This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I have a slightly different approach in one of my apps.
The list values(for dropdown selects) on page is created by external framework. On page display the list is set in HttpRequest by external framework and passed to bean(which has request scope). This works fine during display since I can read the value(if available) in the bean constructor.
On the submit process I call the external framework to save data. I have a callback mechanism that allows external framework to set the list value in my bean. As you know call to save happens only during invoke application phase.
The problem is I get a JSF exception during update model values phase since the list is null.
At this moment I don't want to change the approach of using external framework.
Is there anyway I can manupilate the JSF phases? I don't have much experience with custom componenets; would that help?
This is a strange one, and I'm not really sure what the benefit is, but any attempt to manually attach a selection list to a JSF SelectOneMenu control has major problems. The list isn't just output as a display, its backing model is also used to validate the user's selection. So if you submit a SelectOneMenu item and your selection isn't in the SelectItems collection for that control, you'll have a validation failure.
If you can obtain the list values using a web service or REST request, you can make the "get" method make that request internally to build the SelectItems model on the server side. Although I'm not 100% sure that you can make a selection model object have request scope, since it has to be present both on the outbound response for the page and the inbound request with the selection made. You may need to attach the list to something with a longer scope. In JSF2, View scope might work. In JSF1, you'd need session scope (or application scope), and since it sounds like your list is fairly dynamic, you would need to figure out when it was appropriate to fetch updates to the list.
An IDE is no substitute for an Intelligent Developer.
Joined: Jun 11, 2003
Thanks for your points.
I see... the list values are needed for validation phase.
Isn't this is a constraing in JSF model? I cannot defer initialization upto just before page rendering, in the case of SelectOneMenu.
This would happen if list is dynamic and is determined after invoke application phase.