• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Value change listener updating bean

 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What about binding the input to your BB, and calling setSubmittedValue ?

JSP

BB
 
Darryl Nortje
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Christophe, I had the same issue solved by your solution.
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic