Struts2/Webwork includes an interceptor in the default stack called
conversionError. This interceptor will throw a validation error if it
fails to convert one of the web request values to your action
setters. When a validation error like this is thrown then Struts2
will return the input result. So in a way your value is being
validated, you just need to display <s:actionErrors/> on the page and
you will get the message. You can customize this message by including
"errors.conversion=whatever message" in your
ApplicationResources.properties bundle, as Appfuse does. You are
getting type validation for free when you set the type of the variable
in your Action.
There is a lot of default behavior for type conversion in Struts2, and
for basic types like numbers (Int, Long) it works great. For dates
you usually have to create your own type converter to handle the
different formats you will allow users to enter (Appfuse has its own
Date Struts type converter). The type converter can even do things
like create compound objects from your model or populate collections
from groups of fields in your web form...but that is getting ahead of
ourselves.
Removing conversionError from the inteceptor stack won't help you
since you simply can't set inNumberCount to 'abc' and an exception
will be thrown. If you really don't want Struts2 to do the conversion
for you and you want to validate the value yourself then you can
declare the value as a String and then use either a action-
validation.xml or validate() to checkt the value. You can check the
value in the method, execute() and try and cast it to an Integer, but
its usually better practice to use the validation machinery in
Struts2....
-Dusty
On Aug 4, 2008, at 5:11 AM, shendel wrote:
hello, im new appfuse user. Im using webworks tags in my jsp. I have
textfield field name intNumberCount
and it must accept only interger values. In my action i have declared
intNumberCount as interger. When the form submits what usually
happens it
that it call the method that is declared in the jsp page and send
success to
xwork.xml and gets the corresponding jsp page to be displayed.. But
the
problem is when the user input a value that is not interger. It is not
calling the method that supposed to call.. and it automatically call
the
input of the xwork.xml. Why is this happening?My big question is how
can i
validate the user input when it won't call the method the is set to
the jsp
page.
--
View this message in context:
http://www.nabble.com/Webwork-validation-interger-tp18810118s2369p18810118.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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]