arg20
arg20

Reputation: 4991

JSF Managed Beans performance

I have a web page that has many forms. One for logging in, another for creating an article and another for submitting a comment. Now, each of these forms is backed by a different backing bean for instance: loggingBean, newCommentBean, etc. When the life cycle executes, does it create instances of each of these beans even though the user submitted only the "new comment" form?

Upvotes: 1

Views: 886

Answers (2)

CoolBeans
CoolBeans

Reputation: 20800

It depends on how you have the scope defined of the managed bean.

EDIT There is also the eager attribute @ManagedBean(eager = true) that you may find good to know.

To force an application-scoped bean to be instantiated and placed in the application scope as soon as the application is started and before any request is made, the eager attribute of the managed bean should be set to true.

Upvotes: 2

Andrew White
Andrew White

Reputation: 53496

It all depends on the scope of the beans. Request beans are created once per request but you probably shouldn't worry about the overhead of a bean creation, it's tiny. You should usually be more concerned with beans staying around too long (session beans that should be request beans) which needlessly drains memory.

Upvotes: 3

Related Questions