We have implemented a quite comprehensive customer support system using JSF as an in-house prototype of the JSF technology. We have not been able to come up with a satisfactory solution to the following problem however, and have been unable to find any examples code that addresses this very common situation.
we need to allow admin users to edit company details.
we provide a ListCompanies page that gives a list of the company names and the user then clicks on a name to edit that specific company. we use a command link with the company id being passed as a key. when the company has been edited we return the user to the list. this you would think would be a very very common situation and quite trivial. it is not however.
The ListCompanies page is backed by a request scope ManagedBean that provides a sorted list of the companies. the EditCompany page is backed by a request scope CompanyHandler. the company handler checks the request parameter and loads a CompanyBean that then backs the edit company form. the company handler has a managed property which is the actual company bean.
this all seems too complex but if we don't jump through these hoops we get stuck in the following situations:
1) if we just have a request scope bean for the edit company form then any validation errors cause a new request and we lost the contents of the bean and the request parameter containing the id of the company to edit and the form ends up blank.
2) if we use a request scope managed bean for the edit company form then we get the same company every time we try to edit from the list becase the jsf framework only creates one bean per session.
so the solution was to have a managed bean that works out whether it needs to use an existing bean or create a new once for the form. this seems like a cludge and a crazy amount of over-engineering for such a common problem.
also we are getting issues with our users clicking on the browser's back and forth buttons and causing strange things to happen to the forms.
We feel this is such a common problem there must be a generioc solution to it, but so far all searching has been for naught. Does anyone have a pattern they have used for this sort of scenario?
Thanks in advance
JSF / Jini / Javaspaces / JDO - all rock in my opinion.
subject: JSF: Scope of Managed Beans - how best to back a form?