我想在添加操作后刷新 DataTable 但它不起作用。下面是我的代码。
此代码是使用数据库中的 netbeans jsf 实体类生成的。我确定下面的所有代码都成功执行,没有任何错误。
javascript代码
function update(){
updateComment();
}
视图.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>
问题评论控制器.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"/>
但它不会刷新数据表。
任何帮助,将不胜感激。谢谢。