我想刪除與當前影片不匹配的評論;如何使用當前上下文刪除項目集合JPA,JSF,Java Collections
信息
jpaController = (CommentFacade) facesContext.getApplication().getELResolver().getValue(facesContext.getELContext(), null, "commentJpa");
movieController = (MovieController) facesContext.getApplication().evaluateExpressionGet(facesContext, "#{movie}", MovieController.class);
private List<Comment> userCommentItems = null;
private Comment userComment = null;
public List<Comment> getUserCommentItems() {
if (userCommentItems == null) {
getUserPagingInfo();
Vector comments = (Vector) jpaController.findAll();
Vector v = new Vector(comments);
for (Iterator iterator = comments.listIterator(); iterator.hasNext();){
userComments = (Comment) iterator.next();
if (userComments.getMovie().getIdMovie() != movieController.getMovie().getIdMovie()){
v.remove(userComments);
}
}
userCommntItems = v;
}
return userCommentItems ;
}
<h:panelGroup>
<h:outputText value="Item #{comment.userPagingInfo.firstItem + 1}..#{comment.userPagingInfo.lastItem} of #{comment.userPagingInfo.itemCount}"/>
<h:commandLink action="#{comment.userPrev}" value="Previous #{comment.userPagingInfo.batchSize}"
rendered="#{comment.userPagingInfo.firstItem >= comment.userPagingInfo.batchSize}"/>
<h:commandLink action="#{comment.userNext}" value="Next #{comment.userPagingInfo.batchSize}" rendered="#{comment.userPagingInfo.lastItem + comment.userPagingInfo.batchSize <= comment.userPagingInfo.itemCount}"/>
<h:commandLink action="#{comment.userNext}" value="Remaining #{comment.userPagingInfo.itemCount - comment.userPagingInfo.lastItem}"
rendered="#{comment.userPagingInfo.lastItem < comment.userPagingInfo.itemCount && comment.userPagingInfo.lastItem + comment.userPagingInfo.batchSize > comment.userPagingInfo.itemCount}"/>
<h:dataTable value="#{comment.userCommentItems}" var="item"
border="0" cellpadding="2" cellspacing="0" rowClasses="jsfcrud_odd_row,jsfcrud_even_row" rules="all" style="border:solid 1px"
rendered="#{not empty comment.movieController.movie.commentCollection}">
<h:column>
<f:facet name="header">
<h:outputText value="IdUser"/>
</f:facet>
<h:outputText value="#{item.idUser.user}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Text"/>
</f:facet>
<h:outputText value="#{item.text}"/>
</h:column>
</h:dataTable>
</h:panelGroup>
你得到的錯誤是什麼? –
沒有錯誤,但爲空我得到一個空的數據表 –
沒有抱歉我現在正在收到所有評論,所有電影的評論。我的意思是,一旦評論結束,他們對於我導航的所有電影都保持不變。 –