Simple piece of code about dataTable. CentralFeed is SessionScoped Bean, and PostComment is RequestScoped Bean
<h:form id="table">
<h:dataTable value="#{CentralFeed.profileComments}" var="item">
<h:column>
<h:outputText value="#{item.comment}"/><br/>
<h:inputTextarea value="#{item.newComment}" rows="2"/><br/>
<h:commandButton value="Post" action="#{PostComment.postReply(item)}" />
</h:column>
</h:dataTable>
</h:form>
inside CentralFeed.java
private List<NewsFeed> profileComments = null;
public List<NewsFeed> getProfileComments() {
PhaseId currentPhaseId = FacesContext.getCurrentInstance().getCurrentPhaseId();
profileComments = scholarBean.findProfileCommentsByUserId(getSelectedUser().getId());
//model = new ListDataModel<NewsFeed>(profileComments);
return profileComments;
}
My problem is that getProfileComments() get called a lot. currentPhaseId will tell us at what phase does the method got called. When the page first load, getProfileComment get call around 5 times, at phase 6 - RENDER_RESPONSE. The page have a inputTextarea, so I type in there something, and click Post (the commandButton). Then getProfileComment get called another 12 times going through phase 1->4. Each phase call this method 3-4 times. Then after that, the setter method of the attribute newComment get call (so setNewComment() get call), the getProfileComment get call again at phase 5. Then postReply() get call, then getProfileComment get call again for another 5 times at phase 6. What is going on? Is it suppose to be like this? If you look at my getProfileComment, via my EJB scholarBean, I actually query the database, so having to query the database like 20 times like this is a very bad idea.