You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by jitendra <ji...@persistent.co.in> on 2009/01/19 09:24:24 UTC

Struts 2 validation is not working for comma separated number entered in text field which has property type integer

Hi,


We are using the struts2.0.6 framework as part of our business application.
Recently we found that there is a validation issue with struts2 frame -
work. Let me explain my problem first. 

In a jsp page, I have defined a s:text field and the field property is
Integer type(defined in bean). Now if I enter the String value in text filed
and submit the form, then the struts2 frame work shows the validation error
for the String value, because the property is of type Integer. This is right
behavior. But if I enter the Integer value with comma separated (i.e. 1,2,3)
in text box and submit the form then the struts2 frame - work stripping out
the commas from that value and submit it to bean and does not throwing any
error.

My question is how I can validate the Integer value which has the commas in
it. Basically, we don't want to add any custom validator for this field
because if we do so then we have to apply this validation through out our
application and it is around 150 places. 

Is there any common place where I can configure? Or Is Struts 2 has any
solution for this? If yes then which struts file (i.e. struts2 code base)
needs to change to apply this validation for the text field which will apply
for all text fields.

 

 

Thanks in advance,

Jitendra


DISCLAIMER
==========
This e-mail may contain privileged and confidential information which is the property of Persistent Systems Ltd. It is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, you are not authorized to read, retain, copy, print, distribute or use this message. If you have received this communication in error, please notify the sender and delete all copies of this message. Persistent Systems Ltd. does not accept any liability for virus infected mails.

RE: Struts 2 validation is not working for comma separated number entered in text field which has property type integer

Posted by jitendra <ji...@persistent.co.in>.
Hi Lukasz,

 

Thanks for the solution. I will try this.

 

Regards,

Jitendra

 

  _____  

From: Lukasz Lenart [mailto:lukasz.lenart@googlemail.com] 
Sent: Monday, January 19, 2009 2:39 PM
To: Struts Users Mailing List
Subject: Re: Struts 2 validation is not working for comma separated number
entered in text field which has property type integer

 

2009/1/19 jitendra <ji...@persistent.co.in>:
> My question is how I can validate the Integer value which has the
> commas in it. Basically, we don't want to add any custom validator for
> this field because if we do so then we have to apply this validation
> through out our application and it is around 150 places.

The best solutions is to write your own specific converter for Integer and
apply it to whole application using syntax:

# syntax: <type> = <converterClassName>
java.lang.Integer = com.acme.MyIntegerConverter

take a look for section Applying a Type Converter for an application in [1]

[1] http://struts.apache.org/2.1.6/docs/type-conversion.html


Regards
--
Lukasz
http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


DISCLAIMER
==========
This e-mail may contain privileged and confidential information which is the property of Persistent Systems Ltd. It is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, you are not authorized to read, retain, copy, print, distribute or use this message. If you have received this communication in error, please notify the sender and delete all copies of this message. Persistent Systems Ltd. does not accept any liability for virus infected mails.

Re: Struts 2 validation is not working for comma separated number entered in text field which has property type integer

Posted by Lukasz Lenart <lu...@googlemail.com>.
2009/1/19 jitendra <ji...@persistent.co.in>:
> My question is how I can validate the Integer value which has the commas in
> it. Basically, we don't want to add any custom validator for this field
> because if we do so then we have to apply this validation through out our
> application and it is around 150 places.

The best solutions is to write your own specific converter for Integer
and apply it to whole application using syntax:

# syntax: <type> = <converterClassName>
java.lang.Integer = com.acme.MyIntegerConverter

take a look for section Applying a Type Converter for an application in [1]

[1] http://struts.apache.org/2.1.6/docs/type-conversion.html


Regards
-- 
Lukasz
http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org