javavalidationstruts2struts2-interceptors

How to use same validation method for two action methods


I have an action Method and validation method for this method in Struts2. I want to use this validation method for another action method. I have no Idea how to do it. Please help. The scenario is described below:

public class ApplicantRegistrationDetails extends ActionSupport {
    
     public String personOfCollectiveTrademark() {
      // some code..
         
     }

     public String insertAndValidateIECcode(){
        // I have to use same validation method
        // for this method as above.

     }

     //validation
     public void validatePersonOfCollectiveTrademark() {
       // validations for first method
     }

}

Solution

  • You can do it easily by using prefix based method validation.

     /**
      * Validates insertAndValidateIECcode()
      */
     public void  validateInsertAndValidateIECcode(){
        // The implementation uses same validation method
        // for personOfCollectiveTrademark().
        validatePersonOfCollectiveTrademark();
     }