2013-03-04 37 views
0

我想添加操作后刷新数据表执行阿贾克斯后刷新数据表,但它不工作。下面是 是我的代码。无法使用PrimeFaces

该代码使用NetBeans从数据库JSF实体类生成。 确保下面的所有代码都能成功执行而不会出现任何错误。

JavaScript代码

function update(){ 
     updateComment(); 
    } 

view.xhtml

<h:form id="commentArea"> 
       <!--for Comment Area--> 
      rendered="#{issueCommentController.items.rowCount == 0}" style="padding-bottom: 10px;"/><br/> 
       <h:panelGroup> 
       <h:dataTable id="commentTable" value="#{issueCommentController.getCommentModel(issueController.selected.id)}" var="comment" class="table table-striped table-bordered table-condensed table-hover" rules="all"> 
        <h:column> 
        <f:facet name="header"> 
         <h:outputText value="Comment"/> 
        </f:facet> 
        <h:outputText value="#{comment.comment}"/> 
        </h:column> 
        <h:column> 
        <f:facet name="header"> 
         <h:outputText value="Comment Date"/> 
        </f:facet> 
        <h:outputText value="#{comment.commentedDate}"> 
         <f:convertDateTime pattern="MM/dd/yyyy" /> 
        </h:outputText> 
        </h:column> 
       </h:dataTable> 
       </h:panelGroup> 
       <h:inputTextarea id="reply-thread-txt" value="#{issueCommentController.selected.comment}"></h:inputTextarea> 
       <div style="clear:both"></div> 
       <div class="padding-top-10" style="width:284px !Important; margin-top: 10px;"> 
<p:remoteCommand name="updateComment" action="#{issueCommentController.retrieveComment(issueController.selected.id)}" update="commentArea"/> 
       <p:commandButton styleClass="btn btn-primary" oncomplete="update();" value="Reply" action="#{issueCommentController.create}"> 
        <f:param name="issue.id" value="#{issueController.selected.id}"/> 
        <f:param name="commented.by" value="#{sessionScope.LOGIN_USER}"/> 
       </p:commandButton> 
       </div> 
      </h:form> 

IssueCommentController.java

public DataModel getCommentModel(int id){ 
    if(commentModel == null){ 
     commentModel = getCommentPagination(id).createPageDataModel(); 
    } 
    return commentModel; 
    } 

//comment pagination. 
public PaginationHelper getCommentPagination(final int id) { 
    if (commentPagination == null) { 
     commentPagination = new PaginationHelper(10) { 
     @Override 
     public int getItemsCount() { 
      return getFacade().count(); 
     } 

     @Override 
     public DataModel createPageDataModel() { 
      return new ListDataModel(getFacade().getComment(id)); 
     } 
     }; 
    } 
    return commentPagination; 
    } 
//execuate query 
public List<IssueComment> getComment(int id){ 
    TypedQuery<IssueComment> tq = getEntityManager().createQuery("SELECT c FROM IssueComment AS c WHERE c.issueId=:id",IssueComment.class); 
    Issue issue = new Issue(id); 
    tq.setParameter("id", issue); 
    return tq.getResultList(); 
    } 
//execute after the add operation using ajax. 
public void retrieveComment(int id) { 
    items = getCommentPagination(id).createPageDataModel(); 
    } 

该加载操作后,这将被执行。

<p:remoteCommand name="updateComment" action="#{issueCommentController.retrieveComment(issueController.selected.id)}" update="commentArea"/> 

但它不刷新数据表。

anyhelp将不胜感激。 thnks。

+0

'rendered =“#{issueCommentController.items.rowCount == 0}”'属于您的视图中的元素?为什么'update()'和'updateComment'之间的往返?你*知道你可以直接从命令按钮引用'updateComment',而不是不需要的js? – kolossus 2013-03-05 05:55:47

+0

哦对不起,我忘了编辑那一个。应该是它的呈现= “#{issueCommentController.getCommentModel(issueController.selected.id)== 0}”。以及有关的update()和updateComment,我用另一个JS调用updateComment原因,我打算在调用它之前添加一个模式。 – blitzen12 2013-03-07 04:45:32

回答

0

我找到了解决我的问题,但我会后我的情况下,答案可能会有所帮助别人。 我用这个替换了remoteCommand代码。

<p:remoteCommand name="updateComment" action="#{issueCommentController.retrieveComment(issueController.selected.id)}" update="commentArea"/> 

这个。

<p:remoteCommand name="updateComment" action="#{issueCommentController.getCommentModel(issueController.selected.id)}" update="commentArea"/>