This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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.
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??