I can not seem to get comments per movie from moviesDetail.jsp. What am I doing wrong?
<h:dataTable value="#{comments.commentsItemsPerMovie}" var="item" border="0" cellpadding="2" cellspacing="0" rowClasses="jsfcrud_odd_row,jsfcrud_even_row" rules="all" style="border:solid 1px">
<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>
Controller Class;
private List<Comments> commentsItemsPerMovie = null;
private Movies movie;
private Comments comment;
public List<Comments> getCommentsItemsPerMovie() {
if (commentsItemsPerMovie == null) {
getPagingInfo();
movies =
(Movies) FacesContext
.getCurrentInstance().getELContext().getContext(Movies.class);
commentsItemsPerMovie = jpaContr开发者_开发百科oller.findByMovie(movie.getIdMovies());
}
return commentsItemsPerMovie;
}
Facade
public List<Comentarios> findByMovie(int movie) {
CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
cq.select(cq.from(Comments.class));
Query q = em.createQuery("SELECT c FROM Comments WHERE c.idMovies = :"+movie+"");
return q.getResultList();
}
Used a collection of comments in the movie bean and stored such commnets id in the movie to set connection
精彩评论