File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes selectOneMenu value not being set on postback Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "selectOneMenu value not being set on postback" Watch "selectOneMenu value not being set on postback" New topic

selectOneMenu value not being set on postback

John Footh

Joined: Mar 10, 2011
Posts: 4
I have this simple code:

So, when the user changes the amount in the select box, the search executes and displays the chosen rows per page. The problem is, the "itemsPerPage" value always ends up being null. I've tried what seems like a million different things but can't seem to get it to work. I'm guessing it has something to do with the JSF phases which I am not too familiar with. I am about to switch to old school HTML forms. Can anyone offer an explanation as to why this isn't working (and perhaps a solution) ?



Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17256

Welcome to the JavaRanch, John!

You haven't supplied an Action processor for this View. So, yes, you're missing one of the lifecycle components. The <h:form> element doesn't support an "action" attribute, so the attribute you coded is being ignored.

And I'm afraid that JavaScript cannot properly submit the context needed, anyway. There's a lot of stuff going on "under the hood" in JSF, so you really need to be using JSF to manage it.

Although it's always good to keep a real "submit" button on a form, just in case the user has disabled JavaScript, if you want to bind an action processor to a selection onchange event, you'll need some extra help, either with an extended tagset such as RichFaces, or using the AJAX support features added in JSF version 2.

An IDE is no substitute for an Intelligent Developer.
John Footh

Joined: Mar 10, 2011
Posts: 4
Thanks for the advice Tim.

I actually did a lot more research on the JSF lifecycle. Also, I'm using Seam which provides some conveniences for dealing with this.

Ultimately, using Seam, I changed the scope of my search component to PAGE which preserves the parameter through a post back. Then I used a page action (another Seam convenience) which executes code on any page load. These two together allowed me to accomplish my goal.
I agree. Here's the link:
subject: selectOneMenu value not being set on postback
jQuery in Action, 3rd edition