File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes JSF keeps displaying old values after Validation Phase fails (ignoring actionListeners settings) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF keeps displaying old values after Validation Phase fails (ignoring actionListeners settings)" Watch "JSF keeps displaying old values after Validation Phase fails (ignoring actionListeners settings)" New topic
Author

JSF keeps displaying old values after Validation Phase fails (ignoring actionListeners settings)

Nico Rossi
Greenhorn

Joined: Jun 12, 2011
Posts: 16
Hi all,
I would like to ask some help in understanding a particular behaviour that JSF shows when Validation Phase
fails.
I'm using:

- Tomcat 7.0.2
- JSF 1.2_12
- RichFaces 3.3.3

Problem description.
I wrote a form with 4 input fields: an inputText and 3 selectOneMenu. The inputText is required
while the selectOneMenus don't require any validation. Attached to the first selectOneMenu (row 32),
is an a4j:support tag so that, whenever the change event is fired, the list of items of the second
and the third selectOneMenu (row 44 and 58) are correctly filled. In particular, after loading
the two lists of items, the method forces the value of the second and the third selectOneMenu
to null. This mechanism seems to work fine until I submit the form without filling the input
text: as expected, JSF validation fails but when I change the value of the first selectOneMenu,
the page keeps displaying the values specified before JSF validation failed for the second and the
third selectOneMenu (note that the actionListener is still called and the values of the second and
the third selectOneMenu are still forced to null).

Since I'm using a simple PhaseListener, I noticed the following:
before JSF validation fails, every time I change the value of the first selectOneMenu, JSF life
cycle always calls the get method for the second and the third selectOneMenu during the Render
Response Phase. In this way, JSF is able to "see" that those values have been set to null during
the Invoke Application Phase.
After validation fails, JSF stops calling those getters when I change the value of the first
selectOneMenu.

I hope my explanation was clear enough, thaks a lot for your help.

Regards,
Nico






leo donahue
Ranch Hand

Joined: Apr 17, 2003
Posts: 327
This mechanism seems to work fine until I submit the form without filling the input
text: as expected, JSF validation fails but when I change the value of the first selectOneMenu,
the page keeps displaying the values specified before JSF validation failed for the second and the
third selectOneMenu

Google for the JSF lifecycle and note that if validation fails, the model is not processed, it just skips to the render response phase.


Thanks, leo
Nico Rossi
Greenhorn

Joined: Jun 12, 2011
Posts: 16
Hi Leo, thanks for your advise but I don't think that the problem is the
non-execution of the 'Update Model Values' and 'Invoke Apllication' phases
after an uncorrect submit of the form. Let me explain: if the user submits
the form without filling the inputText, validation fails and JSF jumps to
the Render Response phase displaying the values introduced by the user
(correct or not). That's correct and that's what happens. Now, if the user
changes the value of the first selectOneMenu, RichFaces submits the form
again thanks to the a4j:support tag but, in this case, JSF lifecycle is
completely executed because the attribute 'ajaxSingle = true' tells JSF
to ignore all the other input fields of the form (including the required
input text). As a consequence, the actionListener attached to the first
selectOneMenu is called during the Invoke Application Phase forcing the
values of the second and third selectOneMenu to null. However, JSF keeps
displaying the values introduced before the failure of the validation phase
(even if the properties of the backing bean contain 'null').
What it is strange to me is that JSF stops calling the get methods of the
second and the third selectOneMenu during the Render Response phase after
Validation phase fails.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSF keeps displaying old values after Validation Phase fails (ignoring actionListeners settings)