JavaEE: Question about design
- by Harry Pham
I have a JSF page that will create a new Comment. I have the managed bean of that page to be RequestScoped managed bean.
@ManagedBean(name="PostComment")
@RequestScoped
public class PostComment {
private Comment comment = null;
@ManagedProperty(value="#{A}")
private A a; //A is a ViewScoped Bean
@ManagedProperty(value="#{B}")
private B b; //B is a ViewScoped Bean
@PostConstruct
public void init(){
comment = new Comment();
}
// setters and getters for comment and all the managed property variable
public void postComment(String location){
//persist the new comment
...
if(location.equals("A")){
//update the comment list on page A
}else if(location.equals("B")){
//update the comment list on page B
}
}
}
As you can see from the code above, 2 ViewScoped bean A and B will both use method postComment(), and getter getComment() from bean PostComment. The problem I am having right now is that, if I am on A, constructor of A will load, but it will also load constructor of bean B. This make my page load twice as slow. What would be the best way to solve this problem?