Java Mailing List Archive

http://www.junlu.com/

Home » users.myfaces »

Clear Input Components after validation or conversion error with
JSF 2.1

Michael Heinen

2012-03-26

Replies: Find Java Web Hosting

Author LoginPost Reply
Hi all,

I refer to the problem described at:
https://cwiki.apache.org/confluence/display/MYFACES/Clear+Input+Components#

Workflow:
1) Form is submitted
2) Validation or conversion fails
3) Another command is clicked that loads new or "fresh" data into the
same area
Problem:
The data of request (1) is shown instead of (3) because the submitted or
local values of the components are not cleared after
validation/conversion error.

Solution for JSF 1.2
I patched com.sun.facelets.FaceletViewHandler and cleared the UIInput
components via resetValue() before the new state was saved.
As a result new (fresh) data was shown correctly and the submitted value
was also shown directly after the validation/conversion error.

With JSF 2.1 this does not work the same way.
- I patched
org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.renderView
- Before accessing the state manager I iterate over the
clientIdsWithMessages, determine the correspoding form and call
resetValue for all inputComponents.
- As a result new (fresh) data is shown correctly after step (3)
- But the submitted value is NOT shown directly after the
validation/conversion error (step 2). Instead the original value is shown.
 (e.g. User clears required value and submits form, message 'Field
must not be empty' is shown and field contains the original value
instead of being empty)

Questions:
a) How do I get the JSF 1.2 behavior with 2.1? Is resetValue() the wrong
method?
b) Ideally I would reset only the executed components instead of all
input fields of the form. How can I determine them?
  With richfaces 3.3.3 I checked for request keys representing the
submitted region or the ajaxSingle key. is there anything similar for
ajax commands and JSF 2.1?
c) Shouldn't there be out of the box support for this szenario?

Used versions:
MyFaces 2.1.6 with partial state saving activated
Tomahawk2 1.1.11
Richfaces 4.2.0 Final

Regards,
Michael
©2008 junlu.com - Jax Systems, LLC, U.S.A.