I began to use MyFaces RegExp validator
(xmlns:t="http://myfaces.apache.org/tomahawk) that is included with
Appfuse-JSF archetype. It is indeed very powerful. Consider that with a
simple line like this:

<h:inputText ...
   <t:validateRegExpr pattern='[0-9A-Z]+'/>
</h:inputText>

you can constraint a field value to accept only digits and uppercase
letters.
In the case of validation failure it is shown the error message for the
field with the tag

<t:message for="fieldXY" styleClass="fieldError"/>

but there is an unpleasant side-effect: the model associated to the form is
cleared (it creates a new instance), although the form still shows the old
values (on the screen).
Just before discovering this, I was testing the id attribute of the model in
order to show some buttons (e.g. "Insert") instead of others (e.g.
"Update"). Now I cannot do this anymore, since, upon validation error, the
model is empty!

Do you know how to solve this?
I noticed that other validators, for example those made by
"<v:commonsValidator...", do not have this side effect and show a pop-up
(client-side validation with alerts). Unfortunately I did not found a RegExp
validator among CommonsValidator. 
Instead, MyFaces validateRegExpr seems to be a server-side validation and
somehow it fails to reload the backing bean and thus the associated model.
Another thing that may be of help to some JSF expert is the following.
If I put a breakpoint in the setter method of the id attribute into the Form
class, I can observe that, when validation succeed the breakpoint is always
hit twice, once with id=null and a second time with id correct.
When validation fails, on the other hand, the breakpoint is hit only once,
with id=null!
Does this has to do with some break in the JSF lifecycle?

TIA

Vincenzo Caselli

-- 
View this message in context: 
http://www.nabble.com/JSF-Regular-Expression-validator-clears-the-model-when-validation-fails-tp16964257s2369p16964257.html
Sent from the AppFuse - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to