...
Of course, all the standard validation configuration steps still apply. Client-side validation uses the same validation rules as server-side validation. If server-side validation doesn't work, then client-side validation won't work either.
Panel | bgColor | #ffffce
---|
Note |
Not all validators support client-side validation. Only validators that implement ScriptValidationAware support this feature. Refer to the list of WebWork validators to see which ones do so.Currently only the followings validators supports client-side validation.
|
Note |
---|
Note that the required attribute on many WebWork Tags has nothing to do with client-side validation. |
...
It is just used by certain theme (like xhtml) to put a '*' on the field marked as required. |
Building a Validator that supports client-side validation
Any validator can be extended to support client-side validation by implementing the com.opensymphony.webwork.validators.ScriptValidationAware interface:
Code Block |
---|
public interface ScriptValidationAware extends FieldValidator {
public String validationScript(Map parameters);
}
|
The value returned by validationScript will be executed on the client-side before the form is submitted if client-side validation is enabled. For example, the requiredstring validator has the following code:
Code Block |
---|
public String validationScript(Map parameters) {
String field = (String) parameters.get("name");
StringBuffer js = new StringBuffer();
js.append("value = form.elements['" + field + "'].value;\n");
js.append("if (value == \"\") {\n");
js.append("\talert('" + getMessage(null) + "');\n");
js.append("\treturn '" + field + "';\n");
js.append("}\n");
js.append("\n");
return js.toString();
}
|
Only JavaScript is supported at this timeSee Client Validation for an example.