1
我正在使用縫,我想這樣做: 我想顯示帖子列表,然後用戶點擊帖子和點擊帖子將顯示。 我的代碼是:縫可點擊數據表
<h:dataTable id="hotels" value="#{postList}" var="post" rendered="#{postList.rowCount>0}"> <h:column> <f:facet name="header">title</f:facet> <s:link value="#{post.title}" action="#{postBean.postView(post)}"></s:link> </h:column> </h:dataTable>
我bean是:
@Stateful
@Name("postBean")
public class PostBeanImpl extends BaseBean implements PostBean {
@PersistenceContext
private EntityManager entityManager;
@In(required = false)
@Out(required = false)
Post post;
@DataModel
public List<Post> postList;
public EntityManager getEntityManager() {
return entityManager;
}
public void setEntityManager(EntityManager entityManager) {
this.entityManager = entityManager;
}
public Post getPost() {
return post;
}
public void setPost(Post post) {
this.post = post;
}
public List<Post> getPostList() {
return postList;
}
public void setPostList(List<Post> postList) {
this.postList = postList;
}
public String view() {
if (post != null)
return "";
String sid = getParamValue("id");
if (sid == null) return "home";
Integer id = Integer.valueOf(sid);
post = entityManager.find(Post.class, id);
return "";
}
@Begin
public void postView(Post selectedPost) {
this.post = entityManager.merge(selectedPost);
}
public void list() {
setPostList(entityManager.createQuery("from Post").getResultList());
}
public String save() {
entityManager.persist(post);
return "/blog/view.xhtml?id=" + post.getId();
}
@Remove @End
public void destroy() {}
}
的問題是,當我點擊後它會調用覽(郵政selectedPost)和selectedPost的所有的屬性都爲空。
但列表中的對象正常(非空) 爲什麼是這樣? 幫助我。
感謝