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 o开发者_StackOverflow社区f 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?
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.
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.
精彩评论