我想從數據表中傳遞的數據使用相同的支持bean與requestscope另一個頁面,JSF的傳球這是可能的,而無需使用數據模型?我使用的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>
,這裏是我支持bean
@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
。
它也不起作用。 – borj
看http://stackoverflow.com/questions/4994458/how-can-i-pass-a-parameter-to-a-commandlink-inside-a-datatable我使用#3從鏈接 –
你給我正如你在我的數據表中看到的,不幸的是它不適合我。 – borj