Hi all,
I'm a S2 newbie.
Trying to validate input in a *-validation.xml, and found a strange
behaviour:
<validators>
<field name="id">
<field-validator type="required">
<message key="required"/>
</field-validator>
<field-validator type="regex">
<!--param name="regex">[0-9]</param-->
<param name="expression">[0-9]</param>
<!--message key="requirednumber"/-->
<message>id is not a numeric value</message>
</field-validator>
</field>
</validators>
When i test validation, the "required" key is shown correctly (taken from
package.properties file), but instead of "requirednumber" key (as shown
above I tried with a plain message too), i'm always receiving a "Invalid
field value for field "id"." message.
Someone can help?
P.
Hi Paolo, I'm a newbie as well, but I'm going to try to answer this one
since I've run into a similar problem. The validation seems to happen in
the
order that is specified in the xml file. My mistake was that I left id
specified in the request parameters, but since it was a post form
submission
I needed to included in the actual form (so that the properties in the
action get set accordingly). So just check that you have an id field in
your
form (usually a hidden field).
Hope that helps.
Will
I did some testing, and here is the result:
Here is the Action-validation.xml file:
VALIDATOR:
<!DOCTYPE validators PUBLIC
"-//OpenSymphony Group//XWork Validator 1.0.2//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
<validators>
<field name="idATsro">
<field-validator type="required">
<message key="requiredstring"/>
</field-validator>
<field-validator type="regex">
<param name="expression">[0-9]</param>
<message key="requirednumber"/>
</field-validator>
</field>
</validators>
Then, if I define idATsro as a String in the Action corresponding to the
form (as defined in struts.xml):
input: NULL
message (use message defined in package.properties): idATsro is required.
input: "a"
message (use message defined in package.properties): idATsro should be a
number.
input: 21
message (use message defined in package.properties): idATsro should be a
number. This is due to [0-9] regex.
input: 2
message: none (FORM Submitted)
If I define id as a Long in the Action (and it IS a Long, in my purpose):
NULL
message (use message defined in package.properties): idATsro is required.
input: "a"
message:
Invalid field value for field "idATsro" (I dont' know where it comes from.
It's not defined by me)
+
idATsro is required (defined in package.properties)
input: 21
message: none (FORM Submitted)
input: 2
message: (FORM Submitted)
So, it seems that if I define the field as a String in the Action, things
are working properly. If I define the field as a Long (and it's what I
need), strange behaviour is occurring.
Where am I wrong? There is a logical explanation?
Many Thanks
P.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]