Thanks for the input - your suggestion revealed an elegant solution. The
framework seems to automatically call validation methods with names of the
form validateActionName. Here's an example from my application. The entry in
struts.xml looks like this:

<action name="dataEntry*" method="dataEntry{1}"
class="com.x.y.action.Request">
  <result name="input">/jsp/Request.jsp</result>
  <result>
    ...
  </result>
</action>

The action methods in the Request class are defined like this:

    public String dataEntrySave() throws Exception {
        // save the data
        // ...
        return SUCCESS;
    }
    public String dataEntrySubmit() throws Exception {
        // submit the data for further processing
        // ...
        return SUCCESS;
    }

and I also have validation methods, which are automatically called by the
framework before the corresponding action method:

    public void validateDataEntrySave() {
        // validation done before dataEntrySave() is called
    }

    public void validateDataEntrySubmit() {
        // validation done before dataEntrySubmit() is called
    }



Skip Hollowell wrote:
> 
> I struggled with the same thing, and finally had to defer to the 
> "Webwork in Action" and it's chapter on the Validation Framework.
> 
> "In the case of multiple action aliases, it's a better idea to pull your 
> common validations into a method and then call that method from each of 
> your execute() equivalent methods."
> 
> So instead of overriding validate(), I have several validation() methods 
> [action1Validation(), action2Validation)(), etc) and calls those first 
> off, as needed.
> 
> ironic wrote:
>> I have a class that services many actions. For each action that needs 
>> validation I have a corresponding Class-action-validation.xml, which 
>> takes care of the simple validation. However, I have a case where two 
>> actions need more complex validation (handled in Struts 1 by validwhen 
>> and indexedproperty validators), and I've overridden the validate() 
>> method in an attempt to handle this. The problem now is that I need to 
>> work out which action caused the validate() method to be called. How 
>> can I determine this? Alternatively, is there a way to direct an 
>> action to a validate method that is intended only for that action? For 
>> example, actionA would cause method validateActionA() to be called. 
>> Any hints, pointers or help would be greatly appreciated. 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/-S2--Action-specific-validate-method--tf4631839.html#a13234743
Sent from the Struts - User mailing list archive at Nabble.com.

Reply via email to