在seam 实现表格选择行非常的容易。只需要使用@dataModel 和 @DataModelSelection
看下面代码:
driverBean.java
package cn.xiangyunsoft.transport3.action;
import java.io.Serializable;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Factory;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.datamodel.DataModel;
import org.jboss.seam.annotations.datamodel.DataModelSelection;
import cn.xiangyunsoft.transport3.entity.Driver;
@Name("driverBean")
@Scope(ScopeType.SESSION)
public class DriverBean implements Serializable {
@DataModel
private List<Driver> drivers;
@DataModelSelection
@Out(required = false)
private Driver driver;
@In
private EntityManager entityManager;
@Factory("drivers")
public void findMessages() {
drivers = entityManager
.createQuery("select driver from Driver driver ")
.getResultList();
}
public void select() {
System.out.println("select driver =" + driver);
driver.setStoped(true);
}
}
driverList.xhtml
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:s="http://jboss.com/products/seam/taglib"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:rich="http://richfaces.org/rich"
template="/layout/template.xhtml">
<ui:define name="body">
<rich:panel>
<f:facet name="header">driverList</f:facet>
<div class="results"><h:outputText value="No driver exists"
rendered="#{empty drivers}" /> <h:dataTable id="driverList"
var="driver" value="#{drivers}" rendered="#{not empty drivers}">
<h:column>
<f:facet name="header">Id</f:facet>
#{driver.id}
<h:selectBooleanCheckbox value="#{driver.stoped}"
disabled="true" />
</h:column>
<h:column>
<f:facet name="header">select</f:facet>
<s:link value="#{driver.name}" action="#{driverBean.select}"/>
</h:column>
</h:dataTable></div>
</rich:panel>
</ui:define>
</ui:composition>
这样配合就可以实现在单行选中了。
posted on 2009-05-02 08:19
Libo 阅读(687)
评论(0) 编辑 收藏 所属分类:
seam