I have my view.jsp with the form :
<s:form action="action">
<s:textfiled name="user"></textfield>
</s:form>
I created my ActionClass and ActionClass -Validation.xml in the same package.
ActionClass -Validation.xml:
<validators>
<field name="user">
<field-validator type="required">
<message>You must enter a value.</message>
</field-validator>
</field>
</validators>
In my struts
<action name="action" class="com.action.ActionClass" method="execute" >
<result name="success">/html/view/register-success.jsp</result>
<result name="error">/html/view/register-error.jsp</result>
<result name="input">/html/view/view.jsp</result>
</action>
But it doesn't work. What it is wrong?
The required validator is for checking if the specified field is not null. You are probably want to use requiredstring validator which checks that a String field is non-null and has a length > 0.
Also your validation xml file name should be ActionClass-validation.xml, note lower case for -validation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With