This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes JSF and the fly likes consecutive selectOneMenu postback problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "consecutive selectOneMenu postback problem" Watch "consecutive selectOneMenu postback problem" New topic
Author

consecutive selectOneMenu postback problem

Moh Afifi
Greenhorn

Joined: Jun 01, 2009
Posts: 7
I've been working on this problem for two days now and I don't seem to find a solution.
Try this:
notice that this menu does a submit on its onchange event.
Initially, this works ok on the browser, and the value is posted back and the menu maintains its value.
If you keep changing its value a couple of times the menu suddenly stops changing its value, and not just that, but also any control on the form (a submit button for example) won't execute its server side events at all.
By tracing the phases you'll find that before the error, the jsf lifecycle is done completely.
But after this error occurs, the jsf jumps to the RENDER_RESPONSE phase just after the RESTORE_VIEW phase. And consequently no events are executed

Can anybody help me with this?
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2713
    
    5

"moodymeeedo moodymeedo " welcome to Javaranch
please check your private messages for an important administrative matter. You can check them by clicking the My Private Messages link above.


SCJP, SCWCD.
|Asking Good Questions|
Wei Geng
Greenhorn

Joined: Dec 10, 2004
Posts: 28
I guess what you want to do is to trigger the page refresh by changing the value of selectOneMenu, right?

When the attribute onchange="submit()" executes, the JSF will run the whole lifecycle, of course, including the actionListener invoking. So you will see the actions are executed.

You are supposed to change the normal lifecycle flow. How to do it?

Very easy:

You should add a ValueChangeListener method for your selectOneMenu and make sure to invoke the FacesContext.renderResponse() method before return. Just like this:


When you select the new item of selectOneMenu, the valueChangeEvent will be triggered. Before valueChangeListener returns, renderResponse() method will jump over the following phase(ie. actionListener) and render the component directly. Thus, the actions will not be executed.


Wei Geng
Greenhorn

Joined: Dec 10, 2004
Posts: 28
I guess what you want to do is to trigger the page refresh by changing the value of selectOneMenu, right?

When the attribute onchange="submit()" executes, the JSF will run the whole lifecycle, of course, including the actionListener invoking. So you will see the actions are executed.

You are supposed to change the normal lifecycle flow. How to do it?

Very easy:

You should add a ValueChangeListener method for your selectOneMenu and make sure to invoke the FacesContext.renderResponse() method before return. Just like this:


When you select the new item of selectOneMenu, the valueChangeEvent will be triggered. Before valueChangeListener returns, renderResponse() method will jump over the following phase(ie. actionListener) and render the component directly. Thus, the actions will not be executed.


Moh Afifi
Greenhorn

Joined: Jun 01, 2009
Posts: 7
first, thanks for your reply.
Wei GENG wrote:I guess what you want to do is to trigger the page refresh by changing the value of selectOneMenu, right?

yes that's what i want to do and succeeding to.
Wei GENG wrote:You are supposed to change the normal lifecycle flow. How to do it?

that's not what i want to do.

the problem is that i succeed to do it but then what happens is that suddenly the normal lifecycle ceases to happen and the phases that happen are only RESTORE_VIEW,RENDER_RESPONSE,RESTORE_VIEW

i tried more and discovered that the problem occurs only when i put the jsf-comp client validator tags on the page. even just the scriptmanager tag is enough to cause this to happen.

i tried to find out where the problem happens because of the client validators but i failed till now.
i didn't mention that in my previous post cause i didn't link the problem with the client validator.

btw, i'm using websphere application developer 5.1, on websphere application server 5.1 and jsf specification 1.1
any help on that will be appreciated.
thanks again.
Moh Afifi
Greenhorn

Joined: Jun 01, 2009
Posts: 7
Solved at last.

the problem was with the jsf version.

I was about to give up and find an alternative way, but as a last try decided to download the latest jsf 1.1(1.1_02) version, replaced my jars, runned it. then voila. It ran so smoothly without any problem.


thanks for your help.
 
 
subject: consecutive selectOneMenu postback problem
 
Similar Threads
A Problem with events
listbox help needed
Seam/RichFaces - extendedDataTable, datascroller, and changeable page size
JSF keeps displaying old values after Validation Phase fails (ignoring actionListeners settings)
Validation Error on SelectOneMenu