You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by lucas owen <sr...@gmail.com> on 2010/06/24 16:53:17 UTC

different validate's() for different actions in java class

Hi Struts 2 users,

I have in a class different actions, each one with its own method.

I want a validate() method for each of these actions, I'm not sure if I can
have more than one validate() method in a class,
so all the actions would have the same validation.

should i split all my actions in different classes so each one could have
its own validate() method??

thanks

Re: different validate's() for different actions in java class

Posted by Burton Rhodes <bu...@gmail.com>.
Depending on which method you call in your class you can just append
that method name to the validate() method name.  For example:

public void validateEdit() {
   // Validate Stuff here
}
public void validateUpdate() {
   // Validate Stuff here
}
public void validate() {
   // Validate Stuff here
}

// Will run validate()
public String execute() {
   return SUCCESS:
}

// Will run validateEdit()
public String edit() {
   return SUCCESS;
}

// Will run validateUpdate()
public String update() {
   return SUCCESS:
}

On Thu, Jun 24, 2010 at 9:53 AM, lucas owen <sr...@gmail.com> wrote:
> Hi Struts 2 users,
>
> I have in a class different actions, each one with its own method.
>
> I want a validate() method for each of these actions, I'm not sure if I can
> have more than one validate() method in a class,
> so all the actions would have the same validation.
>
> should i split all my actions in different classes so each one could have
> its own validate() method??
>
> thanks
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: different validate's() for different actions in java class

Posted by lucas owen <sr...@gmail.com>.
Burton, that was what i was looking for

YOU #1

THANKS!!!

2010/6/24 David Lu <lu...@lululand.com>

>
> I think having separate classes would be better.
>
> If the validations are almost the same, i.e. one
> for "Add" and one for "Update" of the same object,
> then perhaps you can have just one action extend
> another and they can share some common validation
> code in a method defined in the base action.
>
>
>
> On 06/24/2010 07:53 AM, lucas owen wrote:
>
>> Hi Struts 2 users,
>>
>> I have in a class different actions, each one with its own method.
>>
>> I want a validate() method for each of these actions, I'm not sure if I
>> can
>> have more than one validate() method in a class,
>> so all the actions would have the same validation.
>>
>> should i split all my actions in different classes so each one could have
>> its own validate() method??
>>
>> thanks
>>
>>
>  ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: different validate's() for different actions in java class

Posted by David Lu <lu...@lululand.com>.
I think having separate classes would be better.

If the validations are almost the same, i.e. one
for "Add" and one for "Update" of the same object,
then perhaps you can have just one action extend
another and they can share some common validation
code in a method defined in the base action.


On 06/24/2010 07:53 AM, lucas owen wrote:
> Hi Struts 2 users,
>
> I have in a class different actions, each one with its own method.
>
> I want a validate() method for each of these actions, I'm not sure if I can
> have more than one validate() method in a class,
> so all the actions would have the same validation.
>
> should i split all my actions in different classes so each one could have
> its own validate() method??
>
> thanks
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org