Here is my dilemma, I know in JSF the accessor method will get call mutilple times, therefore I know not to put expensive business logic (like DB access) in accessor method. What if I absolutely have to put business logic into my accessor. What should I do in this case? Below are a high level layout of my dilemma. (Mojarra 2.1, GF 3.1)
<h:dataTable value="#{myBean.comments}" var="item1">
<h:column>
#{item1.name} says: #{item1.comment}
<h:dataTable value="#{myBean.handleReplies(item1)}" var="item2">
<h:column>
#{item2.name} replies: #{item2.comment}
</h:column>
</h:dataTable>
</h:column>
</h:dataTable>
@ManagedBean
@ViewScoped
public void myBean(){
private List<Comment> comments;
@EJB
private MyEJB myEJB;
@PostConstruct
public void init(){
comments = myEJB.getAllComments();
}
//getters and setters for List<Comment> comments
public List<Comment> handleReplies(Comment comment){
//Return a List of replies of the comment
return myEJB.getRepliesFromComment(comment);
}
}
As you can see, the inner
dataTable take in the item
of the outer
dataTable to generate its List. Is there a way for somehow stop handleReplies()
to be called multiple times, since this accessor method access DB.