Search code examples
jsf-2managed-bean

Separate bean for any action or one bean for all?


I have a jsf page that perform three actions. Is it better, in term of design, to have one separate bean for any action or a single bean with all actions?


Solution

  • It really depends on the functional requirements, but generally you use one request/view scoped bean per <h:form>.

    So, if all actions are in such way related to each other that they really belong in the same form, then just put them in the same bean. If those actions are however completely unrelated to each other (e.g. login form, contact form, language selection form), and thus sit each in its own <h:form>, then they should each refer their own bean.