![]() |
VOOZH | about |
Struts 2 allows us to design our validation logic, commonly known as custom validation, by implementing the action class's Validatable Interface. As you might expect, understanding the Validatable interface is critical for understanding Struts2 custom validation.
The workflow interceptor verifies whether or not there are validation errors. It carries out no validation. When an action class implements the Validatable interface, it is used. For this interceptor, the default argument that decides the action or field error result to be executed is the input. We do not need to specify it directly because it is already in the default stack. Here is an example of a Workflow Interceptor:
Using struts UI tags, this jsp website generates a form. The user provides it with their name, password, and email address.
<%@ taglib uri="/struts-tags" prefix="s" %>
<s:form action="register">
<s:textfield name="name" label="Name"></s:textfield>
<s:password name="password" label="Password"></s:password>
<s:submit value="register"></s:submit>
</s:form>
This action class inherits the ActionSupport class and overrides the validate method to define the validation logic.
This xml file defines an extra result by the name input, that will be called if any error message is discovered in the action class.
It's a straightforward JSP file that shows the user's data.
<%@ taglib uri="/struts-tags" prefix="s" %>
Name:<s:property value="name"/><br/>
Password:<s:property value="password"/><br/>