Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Aren't incoming values converted and applied to JSF Components before validations phase  RSS feed

 
Teme Hm
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see conflicting information about when converted values are applied to JSF Components. It is my understanding, according to the spec that incoming values are converted and applied to components in Apply Request Value phase. So by the time validations are getting processed all incoming values have been converted and applied to JSF components (assuming no Conversion errors). I keep finding writings like the one below that say component values are set to submitted values only if they are valid... Am I missing something or are there a lot of incorrect interpretations out there....

Eg.

http://wiki.apache.org/myfaces/How_The_Immediate_Attribute_Works

•Restore View - Creates or restores the previous page.
•Apply Request Values - Set component submitted values to request values.
•Process Validations - Convert and validate component values. Set component values to submitted values if valid.
•Update Model Values - Set backing bean values to component values.
•Invoke Application - Execute actionListeners and actions.
•Render Response - Return response.

Thanks

 
Tim Holloway
Bartender
Posts: 18720
72
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think your confusion is that you didn't notice the difference between "component request values" and "backing bean values".

The component is the analogue of the actual display. The actual display can have bad data in it. However, JSF's validation services ensure that the backing bean will never be updated with that bad data and that in addition, updates are "all or nothing". Meaning that no backing bean data is updated unless all of the data is valid.

If an updated component request value is invalid, the bean update and action processing phases are bypassed, and the update component is used as part of the render response where the display is updated with the invalid value and appropriate messages (assuming you made good use of the message tags).

Since you mentioned "immediate" actions, they're another matter entirely. Putting 'immediate="true"' on an action indicates that the component request values will be updated (otherwise the render would "lose" your data entry), but that neither validation nor bean updating will occur. Validation is fairly meaningless without bean updating, although there are some cases where validate-only is supported. It's just not important here. In fact, a validation failure would bypass the action processor and that would mean the action was only conditionally immediate, which isn't how it works.
 
Teme Hm
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply Tim! I think what you described is exactly what my understanding was. I am just surprised there are multiple places on the web that describe the validation phase as what I listed in my first post. "Process Validations - Convert and validate component values. Set component values to submitted values if valid. " Component values are already converted and set by the time it gets to validations phase and the statement set component values to submitted values if valid is just not true. Note this is all about values stored in the components not backing beans... Is that you understanding too...

Thanks
 
Tim Holloway
Bartender
Posts: 18720
72
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Almost. I saw some stuff recently that leaves a certain amount of doubt, but I believe the component value is still a string and that conversion is done later.

In practical terms, however, the 2 main rules are:

1. immediate action don't update the backing bean properties.

2. non-immediate actions ONLY update the backing bean properties if ALL properties are valid.
 
Teme Hm
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you think only the request value as a string is set on the componet after apply request phase. And the converted values are only set on the component as they are validated? I belive the conveted values on the compoent are called local values. I saw in the spec that local values are all set by the end of apply request value phase but it seems that is not true...

Thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!