aspose file tools*
The moose likes JSF and the fly likes immediate=true for value change events Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "immediate=true for value change events" Watch "immediate=true for value change events" New topic
Author

immediate=true for value change events

An Me
Greenhorn

Joined: Nov 28, 2013
Posts: 10
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
value change of zipcode field using javascript onchange="document.getElementById('autofill').click();"
Here,
-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
immediate=true.
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?
An Me
Greenhorn

Joined: Nov 28, 2013
Posts: 10
JSF zipcode field Autofilling is not working if I'm not setting prependId=false in the <h: form> tag..Any reason??
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16305
    
  21

Totally wrong, I'm afraid.

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).


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: immediate=true for value change events