Win a copy of Python Continuous Integration and Delivery this week in the Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

f:ajax immediate vs h:inputText immediate  RSS feed

 
Ranch Hand
Posts: 1723
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I did this:

The phrase tracker prints out the following. Obviously, the validation happens in Process_validation phase.


2018-06-04T21:59:52.552-0400|Info: BEFORE RESTORE_VIEW 1
2018-06-04T21:59:52.571-0400|Info: AFTER RESTORE_VIEW 1
2018-06-04T21:59:52.572-0400|Info: BEFORE APPLY_REQUEST_VALUES 2
2018-06-04T21:59:52.573-0400|Info: AFTER APPLY_REQUEST_VALUES 2
2018-06-04T21:59:52.574-0400|Info: BEFORE PROCESS_VALIDATIONS 3
2018-06-04T21:59:52.578-0400|Info: AFTER PROCESS_VALIDATIONS 3
2018-06-04T21:59:52.579-0400|Info: BEFORE RENDER_RESPONSE 6
2018-06-04T21:59:52.579-0400|Info: Amount: Validation Error: Value is required.
2018-06-04T21:59:52.610-0400|Info: AFTER RENDER_RESPONSE 6
2018-06-04T21:59:52.611-0400|Info: Amount: Validation Error: Value is required.




But if I did this:

The phrase tracker prints the following. Since immediate= true for the inputText, validation happens in Apply_request.



2018-06-04T22:05:03.415-0400|Info: AFTER RESTORE_VIEW 1
2018-06-04T22:05:03.416-0400|Info: BEFORE APPLY_REQUEST_VALUES 2
2018-06-04T22:05:03.442-0400|Info: AFTER APPLY_REQUEST_VALUES 2
2018-06-04T22:05:03.443-0400|Info: Amount: Validation Error: Value is required.
2018-06-04T22:05:03.443-0400|Info: BEFORE RENDER_RESPONSE 6
2018-06-04T22:05:03.465-0400|Info: AFTER RENDER_RESPONSE 6
2018-06-04T22:05:03.466-0400|Info: Amount: Validation Error: Value is required.



I wonder why <f:ajax immediate='true'/> works differently.
 
Saloon Keeper
Posts: 20505
115
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The f:ajax tag works much like the commandButton and commandLink tags do. That is, making it immediate jumps ahead of the validation and bean updating. In the case of commandButton and commandLink, in fact, the validation and bean updating are short-circuited and do not happen at all, which is useful, for example when doing a dialog view with a Cancel button, where you want to discard all inputs and navigate somewhere else.

In AJAX, you don't navigate, and the official docs say

Autodocs wrote:
If "true" behavior events generated from this behavior are broadcast during Apply Request Values phase. Otherwise, the events will be broadcast during Invoke Aplications phase*



The autodocs for JSF, however, tend to be more obsessed with stuff that only someone implementing their own version of JSF would care about. Or worse, get incorrectly inherited because the developer couldn't be bothered to override with class-specific information. The autodoc documentation for the application programmer is often incomplete and ambiguous.

Of course, the ultimate and authoritative definitions are in the JEE spec itself, but that can require time, patience, and some serious decoding.

In practical terms, I'd hope that the immediate attribute on the ajax tag behaves like the immediate attribute on a command tag does. Although a lot less necessary, since ajax tags can limit what form values actually get processed anyway.

---
* Also, they cannot spell "Aplications" (sic).  
 
Himai Minh
Ranch Hand
Posts: 1723
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried this:



When immediate = false and the input is empty, it does not call the processAjaxBehavior method.
But when immediate = true and the input is empty, it calls the processAjaxBehavior:


BEFORE RESTORE_VIEW 1
2018-06-06T20:45:29.412-0400|Info: AFTER RESTORE_VIEW 1
2018-06-06T20:45:29.413-0400|Info: BEFORE APPLY_REQUEST_VALUES 2
2018-06-06T20:45:29.429-0400|Info: current phase : APPLY_REQUEST_VALUES 2
2018-06-06T20:45:29.430-0400|Info: AFTER APPLY_REQUEST_VALUES 2
2018-06-06T20:45:29.432-0400|Info: BEFORE PROCESS_VALIDATIONS 3
2018-06-06T20:45:29.455-0400|Info: AFTER PROCESS_VALIDATIONS 3
2018-06-06T20:45:29.456-0400|Info: BEFORE RENDER_RESPONSE 6
2018-06-06T20:45:29.456-0400|Info: Amount: Validation Error: Value is required.
2018-06-06T20:45:29.466-0400|Info: AFTER RENDER_RESPONSE 6
2018-06-06T20:45:29.466-0400|Info: Amount: Validation Error: Value is required.


It seems like Ajax's immediate= true, call the processAjaxBehavior. Also the input's immediate=false by default, it still go through the Process_validation
 
Himai Minh
Ranch Hand
Posts: 1723
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another experiment:

When both input and ajax have immediate=true,


2018-06-06T20:59:30.149-0400|Info: BEFORE RESTORE_VIEW 1
2018-06-06T20:59:30.169-0400|Info: AFTER RESTORE_VIEW 1
2018-06-06T20:59:30.169-0400|Info: BEFORE APPLY_REQUEST_VALUES 2
2018-06-06T20:59:30.169-0400|Info: AFTER APPLY_REQUEST_VALUES 2
2018-06-06T20:59:30.169-0400|Info: BEFORE RENDER_RESPONSE 6
2018-06-06T20:59:30.169-0400|Info: current phase : APPLY_REQUEST_VALUES 2
2018-06-06T20:59:30.169-0400|Info: Amount: Validation Error: Value is required.

2018-06-06T20:59:30.176-0400|Info: AFTER RENDER_RESPONSE 6
2018-06-06T20:59:30.179-0400|Info: Amount: Validation Error: Value is required.


The processAjaxBehavior is processed at phase 2 and the validation is also processed at phase 2.
 
Tim Holloway
Saloon Keeper
Posts: 20505
115
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two things to keep in mind:

1. JSF will never apply a value that has not been validated.

2. JSF will never do an incomplete update of values. If one value fails to validate then ALL application of values is suppressed. It is all or nothing.

One of the most fundamental concepts of JSF is that the backing bean (Model) will never receive an incomplete or invalid set of values from the form (View). AJAX can restrict what controls are applied to be a subset of the form controls, but the set itself will be guaranteed value.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!