Paolo Beccari <[EMAIL PROTECTED]> wrote:
So how to validate a Long value?
"Dave Newton" <[EMAIL PROTECTED]> wrote:
You might just be able to use the conversion
validator.
http://struts.apache.org/2.x/docs/conversion-validator.html
I have not tried this, so I'd be interested in the
results if you do!
Thanks,
Dave
Just tested. Result is (uh, almost) Ok.
The new Action-validation.xml is:
<!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="conversion">
<message key="requirednumber"/>
<!--message>${idATsro} is not a numeric value</message-->
</field-validator>
</field>
</validators>
package.properties file is:
requiredstring = ${getText(fieldName)} is required.
requirednumber = ${getText(fieldName)} should be a number.
idATsro is a Long variable in Action.java.
Test case:
input: NULL
message: idATsro is required. [taken from package.properties: OK]
input: a number
message: None (FORM Submitted)
input: a character, or a string
message:
Invalid field value for field "idATsro". [SO, WHERE DO YOU COME FROM?]
+
idATsro is required. [taken from package.properties: OK]
+
idATsro should be a number. [taken from package.properties: OK]
The only thing that I want to remove (because i did not configured it in
package.properties file) is the message:
Invalid field value for field "idATsro"
I suppose this message is always returned when a conversion error occurs.
Next step is finding a way to hide it. I'll post the solution, if ever find
one.
HTH
P.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]