As the complexity of the web projects that I am working on increases, the need to include a MVC structure is becoming more urgent. My model classes are well defined, but view and controller code tends to get munged together. I've been using pretty heavy AJAX on the site also (RichFaces jsFunctions mostly) which makes things slightly more complicated.
Has anyone found good strategies for implementing MVC using JSF2? I do not want to introduce another framework to the project (e.g. Spring MVC).
Some ideas thus far, which I haven't started doing yet
- For a page with heavy ajax, have a 'view' bean for remembering selected tabs, selected items, providing filtered lists of data, etc...
- Have a 'controller' bean to handle actions such as changes to the model
- Have 'command' beans which go between the JSF page and controller. A jsFunction populates the command bean with parameters, and calling
command.execute()
causes the command bean to call the correct method on the controller bean to perform the action. The 'command' bean may include some javascript to be called on completion. It may also specify regions of the page to be re-rendered.
Any thoughts?
Edit
What I see pretty often are managed beans that tend to do everything: keep track of users' selections, update the model, get filtered lists, etc...
We're using JSF 1.2 at the moment and so we can't use actions/actionlisteners with parameters. So for example, our managed beans contain variables such as m_selectedDate
whose only purpose is to feed the selected date to the back-end on the call to updateFilteredItemsBasedOnDate()
. It would be nice if the extra variables could go away since they are just temporary. JSF 2's EL with parameters should help but I'm curious if there is an alternate solution available.
I am curious if there is a way to apply MVC to managed beans, or some method of separating concerns so that we don't end up with large beans that try to do everything.