Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ValueChangeListener question

 
Tom Fulton
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, I'm officially confused.

I'm really just testing out various events. Action Events I've had no problems understanding and getting to work. But Value Change Events are driving me nuts.

I want to trap a change to a radio button and effect a change in the view. For example, if the user selects the radio button corresponding to "Blue" a message would appear in a text box. I want this to happen without submitting the form, because there are validation rules that I don't want to execute. If I define the control like this:



and I define the listener method in my bean like this:



I never reach this method...none of the printlns execute. I can get it to execute by adding a JavaScript command to submit the form, but of course that causes the form to be submitted and I get validation error message, which I want to avoid. I tried immediate="true", but that didn't work either. What am I doing wrong?

Thanks in advance for any help.

P.S. Yes, I know "Blue" is not the label, it's the value. The point is, I can't even get the method to execute at all without adding JavaScript to submit the form.
 
Daniel Rhoades
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you try an onchange="submit()" with an immediate="true" on the selectOneRadio, the form does actually need to submit back to the server to process the valueChangeListener
 
Tom Fulton
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I can do it with either an onclick or an onchange...but the point is, I want to update the view without processing the page for validation. I don't mind a server roundtrip, I just want to avoid all the validation errors I'm going to get. A workaround is fine...and I suspect there's a way of doing this without a round trip, because that's the basic concept behind Ajax. But is it possible to do it within JSF without Ajax? For example, if I could be sure the ValueChangeListener method was going to be called before the validation method, I could set a flag in the backing bean. Any ideas?
 
Daniel Rhoades
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
immediate="true" should bypass the validation phase, adding AJAX support to your JSF application sounds cool - but that might add more complexity than you actually need.
 
Tom Fulton
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adding immediate="true" does not work, although I would have thought it would. When I configure the control like this on the .jsp page:



the method is never called. According to thisJSF Lifecycle article, "conversion and validation would occur earlier in the lifecycle", not bypassed. Which, by the way, is not the way it works with UICommand components...I can cause a command button to change its appearance without having validation errors pop up.

It appears that the rule is: with anything other than a UICommand component, you must always submit the form for the event to be fired. But it seems to me that there ought to be a way to bypass all phases and go directly to Render Response. I just can't think of how to do it with pure JSF.
 
Andres Quinones
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Tom Fulton:
Adding immediate="true" does not work, although I would have thought it would. When I configure the control like this on the .jsp page:



the method is never called. According to thisJSF Lifecycle article, "conversion and validation would occur earlier in the lifecycle", not bypassed. Which, by the way, is not the way it works with UICommand components...I can cause a command button to change its appearance without having validation errors pop up.

It appears that the rule is: with anything other than a UICommand component, you must always submit the form for the event to be fired. But it seems to me that there ought to be a way to bypass all phases and go directly to Render Response. I just can't think of how to do it with pure JSF.



Hi Tom,

I think is impossible to avoid validation during the JSF Lifecycle. I think the best solution for you is to us Ajx4JSF (https://ajax4jsf.dev.java.net/nonav/ajax/ajax-jsf/ ), is easy to configure and to use. This framework can help you with a partial render of your form and I think avoiding the validation process.

I hope this help.
 
Julien Martin
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I use ajax4jsf and I have several value change listener methods in my page as follows:


Can anyone please tell me if I can have several value change listener methods in a managed bean?

Please help?

Thanks in advance,

Julien.
 
André Lima
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tom,where do you define the "colorWinLabel"??is this in your view??
the reason of the ask is cause i am doing the same that you,but im using ajax support with richfaces.
 
Mathew Lee
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>>>Can anyone please tell me if I can have several value change listener methods in a managed bean?

I believe you can use
 
Tim Holloway
Saloon Keeper
Posts: 18366
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
gudim gudi wrote:>>>Can anyone please tell me if I can have several value change listener methods in a managed bean?

I believe you can use


Yes. As a general rule, almost any type of listener permits multiplicity. Which is why the method is normally named "addListener" and not "setListener".

JSF supports 2 primary submit modes. Immediate mode bypasses the validation phase. Standard mode does not. However, some sort of action request must be made in order to start the JSF lifecycle.

The most common type of action request is, of course, a submit button. In JSF, there's also the commandLink, which allows a URL object to behave as a command button. If you want a valueChangeListener to be invoked and you don't want the user to have to click on a command object, you must fire off the request yourself using JavaScript. One way to do this is to use the RichFaces a4j tags.

Keep in mind, however, that HTML/HTTP is what's underpinning all this, and unlike tradition client/server, HTTP is designed with the idea of collecting up data in a batch and submitting it all at once. Partial submissions and other things to make the view more interactive don't come naturally, so there's a little extra work involved.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic