Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could use a non-field custom validator to validate any number of fields. For this purpose you should create a custom validator that extend <code>ValidatorSupport</code> and implement <code>validate</code> method which is inherited from <code>Validator</code> interface but doesn't have default implementation. You should write this implementation to do custom validation. For example you want to create a <code>RetypeValidator</code> which validates two fields have the same value. It could look like</p> <pre><code>public class RetypeValidator extends ValidatorSupport { private String value = null; public String getValue() { return value; } public void setValue(String value) { this.value = value; } private String retypeValue = null; public String getRetypeValue() { return retypeValue; } public void setRetypeValue(String value) { retypeValue = value; } @Override public void validate(Object object) throws ValidationException { String value = (String) parse(this.value, String.class); String retypeValue = (String) parse(this.retypeValue, String.class); if (value != null &amp;&amp; retypeValue != null &amp;&amp; !value.equals(retypeValue)) addActionError(getDefaultMessage()); } } </code></pre> <p>then you have to add this validator to the configuration in the <code>validators.xml</code>:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE validators PUBLIC "-//Apache Struts//XWork Validator Config 1.0//EN" "http://struts.apache.org/dtds/xwork-validator-config-1.0.dtd"&gt; &lt;validators&gt; &lt;validator name="retypeValidator" class="org.custom.struts.vaidators.RetypeValidator"/&gt; &lt;/validators&gt; </code></pre> <p>Now, you have a custom validator name that you could use with <code>@CustomValidator</code> annotation.</p> <pre><code>@Validations( customValidators = @CustomValidator(type="retypeValidator", message="the value and retype value should be the same", parameters = { @ValidationParameter( name = "value", value = "${password}" ), @ValidationParameter( name = "retypeValue", value = "${conformPassword}" )}) ) </code></pre> <p>Note, <code>password</code> and <code>conformPassword</code> are OGNL expressions used to parse when being validated. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload