Trying to understand immediate=”true” skipping inputs when it shouldn’t

With immediate="true" on the button, the action is indeed invoked during apply request values phase and all the remaining phases are skipped. That’s also the sole point of this attribute: process (decode, validate, update and invoke) the component immediately during apply request values phase.

All inputs which do not have immediate="true" are ignored anyway. Only inputs which do have immediate="true" are also processed, but this happens also during apply request values phase. Why should the remaining phases be invoked if everything has already taken place in the apply request values phase?

In the Debug JSF lifecycle article you can find the following summary which should enlighten when to (not) use the immediate"true":

Okay, when should I use the immediate attribute?

If it isn’t entirely clear yet, here’s a summary, complete with real world use examples when they may be beneficial:

  • If set in UIInput(s) only, the process validations phase will be taken place in apply request values phase instead. Use this to prioritize validation for the UIInput component(s) in question. When validation/conversion fails for any of them, the non-immediate components won’t be validated/converted.

  • If set in UICommand only, the apply request values phase until with update model values phases will be skipped for any of the UIInput component(s). Use this to skip the entire processing of the form. E.g. “Cancel” or “Back” button.

  • If set in both UIInput and UICommand components, the apply request values phase until with update model values phases will be skipped for any of the UIInput component(s) which does not have this attribute set. Use this to skip the processing of the entire form expect for certain fields (with immediate). E.g. “Password forgotten” button in a login form with a required but non-immediate password field.

See also:

Leave a Comment