Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSF multiple backing beans on one page

Tags:

java

jsf

facelets

I have done some reading and playing and I still have some questions I was hoping someone might answer:

So, can I use two or more backing beans in a single JSF page?

<h:intputText value="#{myFirstBean.firstProperty}" />
<h:intputText value="#{mySecondBean.secondProperty}" />

If I can, why should I not do it? (I assume I should not, because nobody does)

If I cannot, why?

Also, I read somewhere something like "on page load the framework would instantiate the backing bean, and populate it if it's a postback". They say the backing bean but I cannot understand how the framework know which backing bean to instantiate.

like image 625
Nir Levy Avatar asked Dec 10 '09 19:12

Nir Levy


1 Answers

Let's clarify some terms:

  • managed beans are JavaBeans components that you can configure using the managed bean facility see
  • backing beans, are a JavaServer Faces managed beans that are associated with the UI components used in a particular page see

So, yes you can use two or more managed beans in a single JSF page, but splitting UI components bindings, listeners, logic etc. that are related to one page into two or more backing beans is still posible but very undesirable and might cause you lot of problems and bad code.

like image 198
cetnar Avatar answered Oct 30 '22 20:10

cetnar