Workflow Interceptor

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:

XML




<action name="someAction" class="org.w3wiki">
    <interceptor-ref name="params"/>
    <interceptor-ref name="validation"/>
    <interceptor-ref name="workflow"/>
    <result name="success">good_result.ftl</result>
</action>
 
<-- In this case myMethod as well as mySecondMethod of the action class
       will not pass through the workflow process -->
<action name="someAction" class="org.w3wiki">
    <interceptor-ref name="params"/>
    <interceptor-ref name="validation"/>
    <interceptor-ref name="workflow">
        <param name="excludeMethods">myMethod,mySecondMethod</param>
    </interceptor-ref name="workflow">
    <result name="success">good_result.ftl</result>
</action>
 
<action name="someAction" class="com.examples.SomeAction">
    <interceptor-ref name="params"/>
    <interceptor-ref name="validation"/>
    <interceptor-ref name="workflow">
       <param name="inputResultName">error</param>
        <param name="excludeMethods">*</param>
        <param name="includeMethods">myWorkflowMethod</param>
    </interceptor-ref>
    <result name="success">good_result.ftl</result>
</action>


Struts 2 Custom Validation methods

  • void setActionMessages(Collection<String> messages): This action’s collection of messages is set using the set action messages function.
  • void addActionMessage(String message): The add action message function adds a message at the Action level to the particular action.
  • void setFieldErrors(MapString,ListString>> map): Establishes a set of error messages for fields using the set field error function.
  • boolean hasActionErrors(): Looks for error messages at the action level.
  • boolean hasActionMessages(): This function looks for messages at the Action level.
  • void setFieldErrors(MapString,ListString>> map): Establishes a set of error messages for fields using the set field error function.
  • Boolean hasErrors(): Verifies if any actions or fields contain errors.
  • Map<String,List<String>> getFieldErrors(): This map function retrieves all field-level error messages.
  • Collection<String> getActionErrors(): This collection function retrieves all Action-level error messages.

Struts 2 Custom Validation – Workflow Interceptor

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.

Similar Reads

Workflow Interceptor

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:...

Steps to perform Custom Validation

...

Contact Us