I was working on the following: jsf for auto-filling
[A zipcode field is filled by user, the state and city fields are auto-filled(Taking example from JSF 2.0 Complete Reference book)]
In the form, there are four input text fields(name,zipcode,city,state), a submit button and a hidden commandButton(id=autofill).This hidden button is clicked on
-the zipcode,city and state fields have immediate="true" (so that they are validated)
- added f:validateLength to the zipcode field
Following are my doubts:
1.Correct me if I'm wrong.
The sole purpose of immediate=true for value change events is to avoid validation errors and needs to be used with a hidden commandButton with
2. Always if immediate=true for any input field,there will be a hidden commandButton whose immediate=true.Hence it will never go through the Process Validations phase.It will go through Restore View,Apply Request Values and Then Render Response phase.If so who does the validations that are attached to fields with immediate=true.
3.Now the zipcode is validated as I run the application.But, when I attach MyPhaseListener class to this,it is not printing processValidations phase at all.Is it because the hidden commandButton immediate=true.If so, who does the validations if immediate="true" for hidden commandButton?
Joined: Nov 28, 2013
JSF zipcode field Autofilling is not working if I'm not setting prependId=false in the <h: form> tag..Any reason??
As I explained elsewhere, what the "immediate="true"" attribute does is fire the action without submitting any of the form data.
One of the most common uses of "immediate" is on Cancel buttons where the validity of the form data is not required, since you won't be processing any of the form data anyway.
It is a fundamental architectural stricture of JSF that NO invalid data will EVER be presented to a backing bean(s) unless EACH and EVERY control on the submitted form has a valid value. If even one of them fails validation, the submit request will short-circuit, the bean will not be updated and the action method (and/or action listeners ) will not fire.
If you are looking to do something like automatically supply a ZIP code when a certain city/state are entered, that requires AJAX and partial form submission (which can only be done using AJAX).
An IDE is no substitute for an Intelligent Developer.