Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes JSF and the fly likes Value change listener updating bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Value change listener updating bean" Watch "Value change listener updating bean" New topic
Author

Value change listener updating bean

Darryl Nortje
Ranch Hand

Joined: Jun 11, 2002
Posts: 140
Howzit guys.

Ok here is an interesting one.

Below is a code sample of a value change listener. The example is a bit contrived, but is simple enough to explain my problem.

I got field on the form mapped to a String on my BB. This field is manadatory. (There's a reason for it). Also I have a drop down box on the page, whose value is mapped to a String on my BB. Lastly there are 2 extra fields on the page that display or hide based on the selection of the drop down box.

Now everything is working just fine. The trick is I don't want validation to happen when the onchange for the drop down is called. For that in the valueChangeListener method I renderResponse as soon as I have updated my beans flags. ie: FacesContext.getCurrentInstance().renderResponse(); without this validation on the mandatory field still happens, which I don't want.

Here comes the problem. Let's say each item in the my drop down value is 1, 2, and 3. I want to display this value is the mandatory field. Look at the valueChanged method to see what I'm trying to do. The problem is that the BB getters aren't called again when the page is rendered. Also, if I take the renderResponse out, in other words, get the rest of the components on the form to update the BB, then the setter is called for the component that I just set myself, and overwrites that value with what was filled in in the jsp.

If this is all not clear hopefully is becomes so when I post the code. Otherwise please shout.

Cheers
Darryl

Bean:



JSP PAGE:


I understand what is happening. JSF is calling the setter of the mandatoryField after I have set the value, with the value filled in on the page, which is nothing, that's why it is being overwritten. My question is how do I get kind oif behavior to work??

Thanks
cheers
Darryl
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

What about binding the input to your BB, and calling setSubmittedValue ?

JSP

BB


[My Blog]
All roads lead to JavaRanch
Darryl Nortje
Ranch Hand

Joined: Jun 11, 2002
Posts: 140
Howzit Christopher,

Thanks for the solution. I'm sure it'll work. Will give it a try a bit later when I have more time.

In the mean time though, and out of interest, would this be possible without binding?

Cheers
Darryl
Sivalingam Sivasuthan
Ranch Hand

Joined: Jan 12, 2001
Posts: 75
Thanks Christophe, I had the same issue solved by your solution.


- Siva<br /> Sun Certified Programmer for the Java™2 Platform
 
 
subject: Value change listener updating bean