struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Al Sutton <al.sut...@alsutton.com>
Subject Re: [S2] Refactoring Action classes
Date Tue, 05 Aug 2008 19:20:43 GMT
You can change the action name to something more explicit so instead of 
just load, save, load, save, you could have firstObjectLoad, 
firstObjectSave,....

You may want to look up RESTful URLs to get some inspiration.

Al.

Milan Milanovic wrote:
> Thanks Al.
>
> But in this way, how I'll now which load is for which class when defining a
> link ?
>
> --
> Regards, Milan
>
>
> Al Sutton wrote:
>   
>> More like;
>>
>> <package name="somePackage" namespace="/myNamespace"
>> extends="struts-default">
>> 	<action name="load" method="load" class="FirstObjectManager">...</action>
>> 	<action name="save" method="save" class="FirstObjectManager">...</action>
>> 	<action name="load" method="load"
>> class="SecondObjectManager">...</action>
>> 	<action name="save" method="save"
>> class="SecondObjectManager">...</action>
>> 	...
>> </package>
>>
>> You can also use singletons, utility classes, and good old-fashioned 
>> inheritance to reduce code duplication (remember, Actions don't have to 
>> extend ActionSupport, ActionSupport is just a utility class).
>>
>> Al.
>>
>> Milan Milanovic wrote:
>>     
>>> Dear Al,
>>>
>>> O.K. You suggest that I have multiple classes in one package/namespace,
>>> like
>>> this:
>>>
>>> <package name="somePackafe" namespace="/myNamespace"
>>> extends="struts-default">
>>>
>>> 	<action name="load" method="execute" class="FirstActionClass">
>>>                   ...
>>>              </action>
>>>  
>>>              ...
>>>  
>>>              <action name="save" method="execute"
>>> class="SecondActionClass">
>>>                   ...
>>>              </action>
>>> </package>
>>>
>>> ?
>>>
>>> I understand what are you talking about, but my class is connected to
>>> little
>>> bit complex jsp-s, where I have, reading/saving master object,
>>> reading/saving its child objects, some links to other objects, and all of
>>> that must be placed during user input, like wizard, so it's hard to
>>> separate
>>> code in two classes, because I will have a lot of duplicate code
>>> (attributes).
>>>
>>> --
>>> Regards, Milan
>>>
>>>
>>> Al Sutton wrote:
>>>   
>>>       
>>>> You don't need to have all your actions for a namespace in a single 
>>>> class, you can use multiple classes.
>>>>
>>>> I usually group methods acting on a common object into a single class 
>>>> which usually leaves me with the 5 public methods in a class which map 
>>>> to actions (typically CRUD plus a View method), and multiple classes for

>>>> different object types.
>>>>
>>>> Imho 20 is too many, 10 is a lot, 5 is OK (don't forget that's public 
>>>> action methods, the number of private methods you have will depend on 
>>>> your app).
>>>>
>>>> Al.
>>>>
>>>>
>>>> Milan Milanovic wrote:
>>>>     
>>>>         
>>>>> Dear Al and Dave,
>>>>>
>>>>> I tried to fix that error with session variable all weekend and I
>>>>> didn't
>>>>> managed to fix it. When action is defined as redirect action to another
>>>>> namespace, and when that action is called, another action called method
>>>>> doesn't see my session variables. I just changed this redirect action
>>>>> to
>>>>> that another namespace, as standard action (not redirect) and I now see
>>>>> my
>>>>> variables! I don't have any idea why it doesn't work with redirect
>>>>> action,
>>>>> but I'm SURE that there is some problem.
>>>>>
>>>>> I have one question regarding refactoring action classes, is it much
to
>>>>> have
>>>>> 20 actions per one namespace/action class ?
>>>>>
>>>>> --
>>>>> Regards, Milan
>>>>>   
>>>>>       
>>>>>           
>>>> -- 
>>>> --
>>>> Al Sutton
>>>>
>>>> W: www.alsutton.com
>>>> T: twitter.com/alsutton
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>
>>>>
>>>>
>>>>     
>>>>         
>>>   
>>>       
>> -- 
>> --
>> Al Sutton
>>
>> W: www.alsutton.com
>> T: twitter.com/alsutton
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>>
>>     
>
>   


-- 
--
Al Sutton

W: www.alsutton.com
T: twitter.com/alsutton


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


Mime
View raw message