开发者

seam clickable data table

I am using seam and, i want to do like that: i want to show list of posts then the user clicks post and clicked post will be shown. My code is:

<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>

my bean is:

@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;
    }

    publ开发者_运维知识库ic 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() {}

}

the problem is when i click the post it will call postView(Post selectedPost) and selectedPost's all atributes are null.

but the objects in list are ok(not null) why is so? help me.

thanks


Have a look at the @DataModelSelection annotation - this allows you to access the clicked object within a datamodel.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜