I would rather use an ajaxical component library to handle this, such as Ajax4jsf. Or if this is somehow not an option, then I would rather do it using plain vanilla Javascript. Populate a Javascript array with cities and make use of it during the onchange.Sim Kim wrote:I am having a Zipcode field and a City field. I want the city field to be popluated on the basis on value changed in zip code field. For this I have written a value change listener in the ZipCode field and made its immediate = "true" along with onchange = "this.form.submit()" .
Now my issue is if the City field has a value attribute then the updated value of City is not reflected in the page but if the City field is using a binding attribute and is having a backing bean then only the field value is populated ? Is Backing bean required here ?
This works :
This does not :
Also why is immediate = "true" required for City field as well ? If I remove it City field is not updated .
Here you're misusing the valueChangeListener to set the value of another component instead of handling the actual change of the value (you're not interested in the old value). Here you're also misusing the immediate attribute to bypass validation (and model update!) of the other components.
I share that under a "trick", not really a "best practice". When validations comes into picture, it's fairly a mess to get it all right after all (using immediate attribute and component binding).Sim Kim wrote:Read page 156 of the book , under heading "Using a Value Change Event to Auto-Fill Fields"
You will see the same example here.
Then I don't see any other cause in the as far given information and code.As far as explanation for #{city.name} not getting updated is given, I think you are right but I missed one point. The valueChangeListener written for Zipcode calls responseComplete() , so there is not question of going to 4th phase. Can you guide me now how do I use managed bean here ?
A valueChangeListener will only be invoked if the value is actually changed.I think you are wrong ? I can use the old value and new value of the zip code to do some comparison , after all every city can have many zip codes not one. So I can determine whether or not to change the value of the city field based on zip code.
A valueChangeListener will only be invoked if the value is actually changed.
Often the most important part of the news is what they didn't tell.
I think she's lovely. It's this tiny ad that called her crazy:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|