JavaEE: Question about design

Posted by Harry Pham on Stack Overflow See other posts from Stack Overflow or by Harry Pham
Published on 2011-01-04T07:52:17Z Indexed on 2011/01/04 7:53 UTC
Read the original article Hit count: 244

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about java

Related posts about java-ee