As the complexity of the web projects I'm working on is increasing, the need to include an MVC framework is becoming increasingly relevant. My model classes are well defined, but view and controller code tend to combine. I also used the pretty heavy AJAX on the site (especially in RichFaces jsFunctions), which makes things a little more complicated.
Has anyone found good strategies for implementing MVC using JSF2? I do not want to introduce another structure into the project (for example, Spring MVC).
Some ideas so far that I have not yet begun to do
- For a page with heavy ajax, find the “view” of the bean to remember the selected tabs, selected items, provide filtered data lists, etc.
- Have a bean to handle actions like model changes
- Have the 'beans' command that goes between the JSF page and the controller. The jsFunction function populates the bean command with parameters, and calling
command.execute() calls the bean command to call the correct method on the bean controller to complete the action. The bean "command" may include some javascript that will be called upon completion. It can also indicate regions of a page for re-rendering.
Any thoughts?
Edit
I see quite often managed beans that tend to do everything : track user choices, update the model, get filtered lists, etc.
We are currently using JSF 1.2, so we cannot use actions / actionlisteners with parameters. For example, our managed beans contains variables, such as m_selectedDate , whose sole purpose is to pass the selected date to the background code when updateFilteredItemsBasedOnDate() called. It would be nice if the extra variables could disappear as they are temporary. JSF 2 EL with parameters should help, but I'm curious if there is an alternative solution.
I am curious if there is a way to apply MVC to managed beans or to some method of sharing problems, so that we don’t get big beans that tries to do everything.
source share