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()" .
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.
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.
That the second does not work is because the valueChangeListener runs in the 3rd phase (process validations) of the
JSF lifecycle which is right before the 4th phase (update model values). So whenever you change the property behind #{bean.city} in any phase before the 4th phase, then it will simply be overridden during the 4th phase.
After all, your knowledge about the JSF lifecycle is fairly poor. I highly recommend you to go through a decent JSF tutorial or book before continuing with JSF. As a book I can recommend you the "JSF: The Complete Reference". Also the JSF API specification at its own is worth reading.
Regarding to the question as stated in the topic title: "Is backing bean required?". This whole question at its own makes absolutely no sense. Of course it is required. But on the other hand I don't see any relation between that question and your actual problem as described here. Please carefully invent smart questions and topic titles.