0

I have a JSF application with RichFaces 4.5.8, deltaspike for CDI beans, and EJBs which runs in an EAP 6.3. I have a page with two tables and several popupPanels. The page is backed by a CDI bean controller in WindowScope. By now the page becomes larger and larger, because the popupPanels have a lot of controls and actions.

The xhtml page is separated by composite components and ui:include's which works fine, but the CDI bean becomes larger an larger. I would like to move the action methods of the popupPanels into other CDI beans, but for me it sounds strange to have several windowScoped CDI beans in one page. What would you do to split up the large CDI bean?

Best regards

dako-ak
  • 13
  • 4
  • What are "*windowScoped CDI beans*"? – Tiny Aug 28 '15 at 10:44
  • @WindowScoped beans by deltaspike, see https://deltaspike.apache.org/documentation/jsf.html – dako-ak Aug 28 '15 at 13:46
  • There is no issue with such a split. Window-Scoped just means that instances are restricted to a specific window. Therefore you can have any amount of such instances. You can compare it with a "session per window". So just use/split your logic as you would do it with session-scoped beans. The intention is NOT to have one instance per page or even more pages. Creating a controller per page is just one of many possible approaches. – Dar Whi Aug 28 '15 at 18:37
  • Thank you, I will check it out – dako-ak Aug 31 '15 at 11:03

1 Answers1

1

@DarWhi's comment is correct - you may use as many WindosScoped beans in your page as you want, all of them will live only with one window. There is no restriction that you must use only single bean in the JSF page. You just need to give a name using @Named to all of such beans.

If you prefer to have only one WindowScoped bean per window, you may still separate your logic into multiple beans,. Just inject all child beans into the WindowScoped bean, and then reference actions in child beans using dot notation: #{viewScopedBean.childBean.action. You may use variables to store references to childBeans and make your code in JSF shorter, see this answer.

Community
  • 1
  • 1
OndroMih
  • 7,280
  • 1
  • 26
  • 44