Struts 2 OGNL - Comparison of two string values ​​in validation.xml file

I am new to Struts2 and OGNL and am making a simple web application with a registration page. There are two fields: passwordand repassword(for re-entering the password), and with the help of the verification framework, I would like to confirm that both passwords are the same (I know that I can do this using JavaScript). Here is what I got so far. All field validators work fine. This is my first non-field validator, and I just can't get it to work.

<validator type="expression">
    <param name="expression">${password}!=${repassword}</param>
    <message>Passwords must match.</message>
</validator> 

I tried both with

${password}!=${repassword}

and without

password!=repassword

OGNL tags.

+5
source share
2 answers

expression validator - . fieldexpression validator, OGNL. (==).

<field name="password">
  <field-validator type="fieldexpression">
    <param name="expression"><![CDATA[password == repassword]]></param>
    <message>Passwords must match.</message>
  </field-validator>
</field>

expression . fieldexpression .

+3

%{password == repassword}

OGNL, .

+2

All Articles