There is a convince validator for types that uses the backing type errors to 
generate validation errors. I use it to ensure that letters aren't entered in 
my number fields.

The annotation is ConversionErrorFieldValidator

For example:

@ConversionErrorFieldValidator(message="Please enter only numerical values")
public void setHours(float hours) {
        this.hours = hours;
}

Be warned though, it works for me but may be a little buggy. See 
https://issues.apache.org/struts/browse/WW-2331 and 
https://issues.apache.org/struts/browse/WW-2112

-Nick


-----Original Message-----
From: Alberto A. Flores [mailto:[EMAIL PROTECTED]
Sent: December 14, 2007 9:55 AM
To: Struts Users Mailing List
Subject: Re: Required validator dosen't work

You may want to read on
http://struts.apache.org/2.x/docs/type-conversion.html

The last topic "Type Conversion Error Handling".

I had the same problem. It turns out that there's no "validation"
concept of a "type" (similar to Struts1"), however Struts 2 will give
you control over type conversion problems (similar approach, but with
more control).

So, you really don't have to do much (other than formatting the message
if the default doesn't suit your needs)


Arpan Debroy wrote:
> Thank you Laurie ,
>
> Using 'Long' is the correct way to get 'required' validator worked.
> But now I want show error message when user will put string or character
> instead of any long value.
> What validator to use?
>
> On Dec 11, 2007 7:13 PM, Laurie Harper <[EMAIL PROTECTED]> wrote:
>
>> The 'requiredstring' validator will check for both not-null and
>> not-empty, where 'required' only checks for non-null. If you're using a
>> numeric primitive type (i.e. 'long' rather than 'Long'), you can never
>> have a null value, so required can never fail. In that case, you need to
>> specify range constraints in your validation, or switch to using the
>> wrapper type instead of primitives.
>>
>> L.
>>
>> Arpan Debroy wrote:
>>> Yeah..I am using numbers only.The "required" validator not working for
>>> numbers also.
>>> If you want you can test it quickly.
>>>
>>> On Dec 10, 2007 11:01 PM, Jiang, Jane (NIH/NCI) [C] <
>> [EMAIL PROTECTED]>
>>> wrote:
>>>
>>>> Use "required" validator only when a field contains a number.  Use
>>>> requiredstring for String based field.
>>>>
>>>> -----Original Message-----
>>>> From: Arpan Debroy [mailto:[EMAIL PROTECTED]
>>>> Sent: Monday, December 10, 2007 11:00 AM
>>>> To: Struts Users Mailing List
>>>> Subject: Re: Required validator dosen't work
>>>>
>>>> Yeah,
>>>> I am using following -
>>>> <interceptor-ref name="validationWorkflowStack"/>
>>>>
>>>> Other validators are working.
>>>> Anyway have anyone ever used "required" validator or can you use it now
>>>> once
>>>> to test.
>>>>
>>>> Thanks
>>>>
>>>> On Dec 10, 2007 5:26 PM, Simon Berger <[EMAIL PROTECTED]> wrote:
>>>>
>>>>> Do you have the Validation Interceptor on your Stack?
>>>>>
>>>>> Arpan Debroy schrieb:
>>>>>> I want to validate -
>>>>>>
>>>>>> 1) The text box should have some value("required" validator doesn't
>>>> show
>>>>> any
>>>>>> error message even if it's empty)..
>>>>>> 2) The text box must have any numerical(I am using long data type)
>>>>> value. I
>>>>>> have no clue how to do it for long.
>>>>>>
>>>>>> Can anyone please help..
>>>>>>
>>>>>> Thanks
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Dec 6, 2007 1:50 AM, Dave Newton <[EMAIL PROTECTED]> wrote:
>>>>>>
>>>>>>
>>>>>>> --- xniit2003 <[EMAIL PROTECTED]> wrote:
>>>>>>>
>>>>>>>> I am trying to use "required" validator in struts2.
>>>>>>>> But it seems this one dosen't  work at all.
>>>>>>>> Have anybody successfully used "required" validator.
>>>>>>>>
>>>>>>> What data type are you attempting to validate?
>>>>>>>
>>>>>>> d.
>>>>>>>
>>>>>>>
>>>>>>>
>>>> ---------------------------------------------------------------------
>>>>>>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>>>>>> For additional commands, e-mail: [EMAIL PROTECTED]
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>>>> For additional commands, e-mail: [EMAIL PROTECTED]
>>>>>
>>>>>
>>>> --
>>>> Thanks & Regards
>>>>  Arpan Debroy
>>>>
>>>> AOL Online India Private Ltd
>>>> RMZ EcoSpace Campus 1A
>>>> Outer Ring Road, Bellandur,
>>>> Bangalore - 560037
>>>> India
>>>> Mobile No :+9886006306
>>>> on-board :+91 (80) 4035 4528
>>>> E-mail : [EMAIL PROTECTED]
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>>> For additional commands, e-mail: [EMAIL PROTECTED]
>>>>
>>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
>
>

--

Alberto A. Flores
http://www.linkedin.com/in/aflores



********************
NOTICE OF CONFIDENTIALITY
This communication including any information transmitted with it is 
intended only for the use of the addressees and is confidential. 
If you are not an intended recipient or responsible for delivering 
the message to an intended recipient, any review, disclosure, 
conversion to hard copy, dissemination, reproduction or other use 
of any part of this communication is strictly prohibited, as is the 
taking or omitting of any action in reliance upon this communication. 
If you receive this communication in error or without authorization 
please notify us immediately by return e-mail or otherwise and 
permanently delete the entire communication from any computer, 
disk drive, or other storage medium.

If the above disclaimer is not properly readable, it can be found at 
www.td.com/legal
                                                           
AVERTISSEMENT DE CONFIDENTIALITE                   
Ce courriel, ainsi que tout renseignement ci-inclus, destiné uniquement 
aux destinataires susmentionnés,  est confidentiel.  Si vous 
n’êtes pas le destinataire prévu ou un agent responsable de la 
livraison de ce courriel, tout examen, divulgation, copie, impression, 
reproduction, distribution, ou autre utilisation d’une partie de ce 
courriel est strictement interdit de même que toute intervention ou 
abstraction à cet égard.  Si vous avez reçu ce message par erreur ou 
sans autorisation, veuillez en aviser immédiatement l’expéditeur par 
retour de courriel ou par un autre moyen et supprimer immédiatement 
cette communication entière de tout système électronique.

Si l'avis de non-responsabilité ci-dessus n'est pas lisible, vous 
pouvez le consulter à www.td.com/francais/legale

Reply via email to