Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Struts2+Validation in liferay6

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?

like image 928
user2273574 Avatar asked Jun 03 '26 09:06

user2273574


1 Answers

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.

like image 111
Aleksandr M Avatar answered Jun 07 '26 11:06

Aleksandr M



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!