File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes Question on list values set on bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Question on list values set on bean" Watch "Question on list values set on bean" New topic

Question on list values set on bean

Naveen Sampra
Ranch Hand

Joined: Jun 11, 2003
Posts: 70
Tim and others,

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?

Please let me know.


Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17410

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.
Naveen Sampra
Ranch Hand

Joined: Jun 11, 2003
Posts: 70

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.

I agree. Here's the link:
subject: Question on list values set on bean
It's not a secret anymore!