Pedro, this is exactly what I need. Thanks!

-----Original Message-----
From: Pedro Salgado [mailto:[EMAIL PROTECTED]
Sent: quarta-feira, 31 de março de 2004 11:14
To: Struts Users Mailing List
Subject: Re: One Action class but more than one functionality


On 31/03/2004 10:12, "Joao Batistella" <[EMAIL PROTECTED]>
wrote:

> I understood what you and mean John Menke said. But the validations I have
> in my abstract action class is not specific for a Person, for example. It
> must be called for every action in the system and I don't want it to be
> called like PersonUtils.commonCodeMethod(params). This must be
automatically
> called, so no chance of forgetting.


  Maybe extending RequestProcessor, overriding processActionPerform

  ... processActionPerform(...) {
    
      //general validation
      (...)

      super.processActionPerform();
    }

  Specify the controller on your struts-config

    <controller
                contentType="text/html;charset=UTF-8"
                debug="3"
                locale="true"
                nocache="true"
                processorClass="pkg1.pkg2.yourProcessorClass"
                maxFileSize="10M"
    />




  This gives you the guarantee that for everything performed with Struts,
the validation is always performed. I did something similar for
processingRoles my way and it is the most cleaner solution, the one that
gives more guarantees and gives more flexbility to use Actions in anyway you
like. I have even made a package out of it so I could reuse the solution.

  More with your method, you can still forget to extend right class and
still get an action performed out of general validation (maybe at most you
get an error executing the action - I don't know your webapp).

  Here goes the javadoc for RequestProcessor ->
http://jakarta.apache.org/struts/api/org/apache/struts/action/RequestProcess
or.html#processActionPerform(javax.servlet.http.HttpServletRequest,%20javax.
servlet.http.HttpServletResponse,%20org.apache.struts.action.Action,%20org.a
pache.struts.action.ActionForm,%20org.apache.struts.action.ActionMapping)


  I ran out of ideas so... you can still solve your problem with multiple
actions. :)


Pedro Salgado



> 
> Thanks you all.
> 
> -----Original Message-----
> From: Pedro Salgado [mailto:[EMAIL PROTECTED]
> Sent: terça-feira, 30 de março de 2004 23:50
> To: Struts Users Mailing List
> Subject: Re: One Action class but more than one functionality
> 
> 
> 
>  Have you tried dispatch action (1 class => several methods that can be
> executed)?
> 
> This way you have:
> 
> - class Person extends Action
>   - add(request, mapping, form, etc)
>   - edit(request, mapping, form, etc)
>   - remove(request, mapping, form, etc)
> 
> You could then create a PersonVUtils (validation utilities for Person or
> something like that) to refactor the code that is common for adding and
> editing a person (in principle, they have the same attributes).
> 
> 
>  If still want to continue with a regular action, like John Menke
> mentioned, it would be best to have an super abstract class.
> 
> This way you have:
> 
> - abstract class BaseAction extends Action
> - class AddPerson extends BaseAction
>   - execute() : 1st executes PersonUtils.commonCodeMethod(params);
> - class EditPerson extends BaseAction
>   - execute() : 1st executes PersonUtils.commonCodeMethod(params);
> - class RemovePerson extends BaseAction
>   - execute() : 1st executes PersonUtils.commonCodeMethod(params);
> 
> Pedro Salgado
> 
> On 30/03/2004 21:12, "Menke, John" <[EMAIL PROTECTED]> wrote:
> 
>> In our base action classes we have elected not to implement the execute
>> method making them abstract actions instead.  this way you can include
>> protected methods in these classes to do validation and call them when
>> needed.  implementing exeucte method in base class seems too limiting.
> you
>> could call super.execute() in your execute method but this is sloppy in
my
>> opinion.  I would rather have a abstract super class.
>> 
>> 
>> -----Original Message-----
>> From: Joao Batistella [mailto:[EMAIL PROTECTED]
>> Sent: Tuesday, March 30, 2004 3:02 PM
>> To: 'Struts Users Mailing List'
>> Subject: RE: One Action class but more than one functionality
>> 
>> 
>> That's right.
>> But I have a problem. I have a superclass that all other actions extend
> and
>> this class only implement execute method with generic validations and so
> on.
>> So, I need the execute method being called, understand?
>> Thanks.
>> -----Original Message-----
>> From: Prabhat Kumar (IT) [mailto:[EMAIL PROTECTED]
>> Sent: terça-feira, 30 de março de 2004 17:33
>> To: Struts Users Mailing List
>> Subject: RE: One Action class but more than one functionality
>> look at the org.apache.struts.actions.DispatchAction class. It is exactly
>> for the use case you described.
>> -----Original Message-----
>> From: Joao Batistella [mailto:[EMAIL PROTECTED]
>> Sent: Tuesday, March 30, 2004 11:28 AM
>> To: 'Struts Users Mailing List'
>> Subject: One Action class but more than one functionality
>> Hello.
>> I have an action class to create, edit and remove a Person, for example.
>> Is this a poor decision? I mean, should I create 3 action classes, one
for
>> create, another for edit and another one for remove?
>> Does struts have a mechanism to help me in that?
>> Thanks all.
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to