You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Naresh Bhatia <NB...@sapient.com> on 2006/12/07 19:20:59 UTC

When to initialize bean properties?

I have a bean property that is displayed on a page. The value of the
property needs to be initialized by making a service layer call. When
should this initialization be done? Currently I am doing a lazy
initialization when the property is first accessed:

public class ForumDetailsBean {
    private ForumDetailsVO forum;

    public ForumDetailsVO getForum() {
        if (forum == null) {
            forum = forumService.getForumDetails(forumId);
        }
        return forum;
    }

    public void setForum(ForumDetailsVO forum) {
        this.forum = forum;
    }
}

In other component frameworks I have used (e.g. asp.net), such
initialization is done on page load events. What is the recommended JSF
way? (BTW, my bean is in request scope).

Naresh

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org