myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Guy Bashan <>
Subject RE: [Faces][Core]
Date Sat, 07 Jun 2008 10:26:05 GMT
Thanks Simon,

I implemented this specific validation the action method.


-----Original Message-----
From: [] 
Sent: Friday, June 06, 2008 11:05 AM
To: MyFaces Discussion
Subject: Re: [Faces][Core]

Guy Bashan schrieb:
> Hi All,
> I have two fields that gets integer values. When user inputs data only
> numbers are allowed. When user leaves field, I add grouping seperators
> automatically (with JS).
> Now, the fields have one converter that converts the value with
> thousands separator to integer value. If no data entered converter
> returns null, if text data is entered (though I block it with JS, by
> doing copy paste it is still possible), it return Double.NaN.
> In addition, each field has a validator (the same validator) that
> checks that data is valid, by testing if value is: Double.NaN and
> setting proper error message.
> The second field has an additional validator that validates that BOTH
> fields are not empty. If both are empty it returns an error message.
> It seems like when both fields are empty the validators are not
> activated. I assume this is because my converter returns null value
> for the empty fields (in the getAsObject method). Should I return some
> none-null value in order for validators to be activated?

Validators are never run on null values. The only validation that
applies then is checking the "required" flag.

So yes if you want your validator to run, your converter will need to
return some non-null value. But doing multiple-field validation within a
validator attached to one field is probably not the right way to do
this; it was not what JSF validators were designed for. I would suggest
doing this sort of validation in your action method instead.

Check the myfaces wiki; I have a vague memory of a page that talks about
cross-field validation. And also a vague memory that someone wrote a
framework to do this.


View raw message