aspose file tools*
The moose likes JSF and the fly likes selectOneMenu does not update backing Bean / Application is invoked in phase 2 rather than phase 5 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "selectOneMenu does not update backing Bean / Application is invoked in phase 2 rather than phase 5" Watch "selectOneMenu does not update backing Bean / Application is invoked in phase 2 rather than phase 5" New topic
Author

selectOneMenu does not update backing Bean / Application is invoked in phase 2 rather than phase 5

Axel Wittich
Greenhorn

Joined: Jan 28, 2009
Posts: 12
Hello all,

I'm rather new to JSF and am sure that my problem is that I got some fundamentals wrong, but I've been on this for quite some days now and it gets rather frustrating as it should be an easy issue.

I have inherited a GUI using JSF - now my task is to write an new screen that displays some DB-data after invoking some stored procedure which is fed by some parameters.

The environment is a jboss4, we are using spring and hibernate.

As far as I am now, all is fine, except for the part of feeding the parameters to the sp.

I've now written a little test page linked to a test bean to get to the root cause of this mess. Basically, it consists out of a oneSelect Menu and a command button to start the whole process. The selectOneMenu selectItem is fed by a HashMap - this, and the initial setup of the value does work fine.

The xhtml page:


The backing bean:



Console of first run:



Any following click on the button does result in the same log output.

Basically, the initial parameters are displayed, but when I select a value from the oneSelectMenu, it does not get to the backing bean.

Also, I tried to find out why only phases 1 and 6 are shown in the log. Phase 2 is shown red using FacesTrace, but there is no mention why.

In my 'real' application, I want to set some parameters using oneSelectMenu and selectBooleanCheckbox, then click on some commandButton and invoke a member that fires the sp using the parameters. I would have thought that jsf collects the variables in phase 2 and fires the action of the button in phase 5, but I never reach phase 5 and the sp is fired using the default parameters in phase 2.

Also I really would like to know what the "exiting from lifecycle.execute in RENDER_RESPONSE(6) because getResponseComplete is true from one of the before listeners" means - I searched for it but it seems a bit to deep in JSF for me.

Your help is much appreciated!

Thanks & Cheers, Axel


Tom Fulton
Ranch Hand

Joined: Mar 30, 2006
Posts: 95
I suspect it's because your selectOneMenu selectItem is specified with immediate="true". This moves the processing earlier in the lifecycle than it would normally, and before validation/conversion/update backing bean. Command-type controls automatically go to Render Response when their immediate attribute is set to "true", and I think that's what's happening.

If it's any consolation, this feature isn't really well documented in JSF (and in my opinion, not very well implemented in terms of how Command components differ from non-Command components).
Axel Wittich
Greenhorn

Joined: Jan 28, 2009
Posts: 12
Hello Tom,

thanks for your answer. During my tries I have done it with and without the immediate="true" - so no avail here... Some days ago I had another example working that way that the action method of a button was triggered and afterwards the values were set - so I had to press the button twice to get the right values into the method. But I did not manage to get this behaviour on the above mentioned example.

I tried to monitor what JSF is doing (e.g. using FacesTrace and some other tools) but my main problem is always the same: I do not have a clear view whats going on behind the scenes... For example using FacesTrace on my above mentioned example somtimes gives me phase 2 in red (=error) - but it does not tell me which error.

If you search for example code, it's always the same. They define a bean, link the properties using '#{beanName.beanProperty}', generate a getter and a setter and all is well. In my example, the initial setter works - but if I want the value from the selectOneMenu after clicking the button, the getter does deliver null (the chosen value is displayen in the re-rendered jsf, though). I mean, it's not rocket sience I'm talkin about here, I just want some values from a gui in my java backend to do something with - the rest of the application already works as I want it to... Can't be that hard.

Sorry - I'm currently rather frustrated...

Thanks & Cheers, Axel
Tom Fulton
Ranch Hand

Joined: Mar 30, 2006
Posts: 95
You have immediate="true" specified for both the selectOneMenu, as well as the Command button. When you say you've tried it both ways (immediate="true" and immediate="false", or not specified), did you mean you tried it with both of them turned on, or off, or only one of them?

The effect of immediate="true" is to move the processing to earlier in the lifecycle, and in the case of Command components, to then go immediately to Render Response. I am not sure what the effect is of having immediate="true" associated with the selectOneMenu component.
Axel Wittich
Greenhorn

Joined: Jan 28, 2009
Posts: 12
Hi again,

I tried it with 'true' (to force a change to be processed immediately) and completely without.

Cheers, Axel

Axel Wittich
Greenhorn

Joined: Jan 28, 2009
Posts: 12
...just looking around... This looks similar to me JSF-component-binding-does-not

Do I need a listener to get the change noted? How do I implement one?

Thanks & Cheers, Axel
Axel Wittich
Greenhorn

Joined: Jan 28, 2009
Posts: 12
Hiho all,

looking through the posts here I found a link with a very nice collection on exactly my problem: communication-in-jsf

Now, I have kicked out the immediate="true" and added a listener to the commandButton:


This now works - the doItMember() is now invoked in phase5 (as I was expecting it to be) and has now the correct value of the selectedOneMenu.

...but this leaves some open questions:
The setPropertyActionListener has a target that has nothing to do with the oneSelectMenu. In fact, its just a property of the bean that is updated with a constant string - the value from the oneSelectMenu seem to be read by some kind of side-effect.

How do I set up a setPropertyActionListener for the value of the selectOneMenu? would that be #{idOfSelectOne.nameOfBeanProperty}" ?

(I'm still lacking some fundamentals here... )

Thanks & Cheers, Axel

Tom Fulton
Ranch Hand

Joined: Mar 30, 2006
Posts: 95
In my applications, I've used the selectOneMenu components, and associated it with a ValueChangeListener, rather than an ActionListener. That's because an ActionListener is associated with command components, such as commandButton and commandLink.

That's what you appear to be attempting in your code. You have a selectOneMenu, and you also have a commandButton to submit the form. In my applications, I would associate a ValueChangeListener with the selectOneMenu, which would determine whether the selected item had changed. And you wouldn't have to pass any parameters to the listener in order to get it to work, which (in my opinion) would be cleaner.

One of the nice things about JSF is that there is usually more than one way to accomplish something. However, JSF also has a certain structure which makes some solutions more elegant than others. Whenever I find myself jumping through hoops in JSF to accomplish something that appears rather simple, I back up and re-think the problem, to see if there is a more "JSF-like" way of doing it.
Axel Wittich
Greenhorn

Joined: Jan 28, 2009
Posts: 12
Hallo Tom,

thanks for your reply - I'll have a look at that on monday, but this sounds logical to me!

Cheers, Axel
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: selectOneMenu does not update backing Bean / Application is invoked in phase 2 rather than phase 5