我想使用具有 requestscope 的相同支持 bean 将数据从数据表传递到另一个页面,这可能不使用数据模型吗?我正在使用 Servlet 3.0
这是我的数据表页面
<p:dataTable var="entity" value="#{collegeController.allCollege}">
<p:column headerText="Code">
#{entity.collegeCode}
</p:column>
<p:column headerText="Description">
#{entity.collegeDesc}
</p:column>
<p:column headerText="">
<p:commandLink value="Edit" action="#{collegeController.prepareEdit(entity)}"/>
</p:column>
</p:dataTable>
这是我的支持豆
@ManagedBean
@RequestScoped
public class CollegeController implements Serializable {
private String redirect = ".jsf?faces-redirect=true";
private CollegeCatalog entity;
public CollegeController() {
}
public String prepareEdit(CollegeCatalog selectedEntity) {
Session s = NewHibernateUtil.getSessionFactory().getCurrentSession();
s.beginTransaction();
entity = (CollegeCatalog) s.load(CollegeCatalog.class, selectedEntity.getCollegeKey());
return "update" + redirect;
}
public List getAllCollege() {
Session s = NewHibernateUtil.getSessionFactory().getCurrentSession();
Transaction tx = s.beginTransaction();
String query = ""
+ "FROM CollegeCatalog entity "
+ "WHERE entity.deleted = FALSE";
Query q = s.createQuery(query);
List l = q.list();
tx.commit();
return l;
}
/**
* @return the entity
*/
public CollegeCatalog getEntity() {
if (entity == null) {
entity = new CollegeCatalog();
}
return entity;
}
/**
* @param entity the entity to set
*/
public void setEntity(CollegeCatalog entity) {
this.entity = entity;
}
}
这是我的更新页面(这是我要显示所选数据的地方)
<h:form>
<p:outputLabel value="Code:" for="txtCode"/>
<p:inputText id="txtCode" value="#{collegeController.entity.collegeCode}"/>
<br/>
<p:outputLabel value="Description:" for="txtDesc"/>
<p:inputText id="txtDesc" value="#{collegeController.entity.collegeDesc}"/>
<br/><br/>
<p:commandButton value="Update" action="#{collegeController.update()}"/>
<p:commandButton value="Back" action="index.jsf?faces-redirect=true"/>
</h:form>
它总是返回null
。