Should we be chaining action servlets?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   steven_crowe
Posted On:   Monday, October 29, 2001 12:12 PM

We're putting together a series of screens where we would say... logon (to main menu), list parties (to list result screen), then add party (to party detail screen), submit add (back to list result screen). The notion of actions makes perfect sense to perform the business logic as a result of the various submits. However, we're currently questioning the use of actions in setting up the resultant page. It appears that the actions themselves are logically dependant on the page (JSP) about to be rendered. As a side; surely this degrades application maintainability somewhat because it reduces the ease at which page flow can be altered, i.e simply by changing struts-config.xml In the case above   More>>

We're putting together a series of screens where we would say... logon (to main menu), list parties (to list result screen), then add party (to party detail screen), submit add (back to list result screen).



The notion of actions makes perfect sense to perform the business logic as a result of the various submits. However, we're currently questioning the use of actions in setting up the resultant page.



It appears that the actions themselves are logically dependant on the page (JSP) about to be rendered. As a side; surely this degrades application maintainability somewhat because it reduces the ease at which page flow can be altered, i.e simply by changing struts-config.xml



In the case above, our 'submit add' needs to perform a list again in preparation for the redisplay of the result screen.



Would we be correct in splitting this functionality between multiple action classes and chaining them. I've seen on the forum somewhere this idea refered to as 'the path to madness'!



Otherwise, in the case above, should we simply not return post-add to the list result screen, or is there (or should there be) in struts a mechanism for pre-processing a particular page, i.e. not leaving it all up to action objects? Have I missed a third/forth option that would decouple actions in some way?



Eagerly awaiting any feedback.



Steve Crowe.

   <<Less

Re: Should we be chaining action servlets?

Posted By:   Ted_Husted  
Posted On:   Tuesday, October 30, 2001 04:38 AM

An Action is intended as an adapter between the HTTP layer
and the rest of your application. Generally, the rest of your
application should be represented by business objects
that have no dependancies on HTTP or Struts.


So, the business logic should not be *in* the Action,
but something that the Action *calls*.


This makes it easier for Actions to handle more than
one task. Since the logic is encapsulated elsewhere,
each task is simpy a method call.


This also makes it easier for logic to be accessed by
more than one Action (or from more than one application).


In this case, there could be a business method for the
listResult page, that an Action could call before forwarding
to that page.


If the correct prerequesites are still in the request,
simply forwarding to another Action can also be a clean
solution, so long as this is documented in the struts-config.


Where it gets iffy is when people start building
dynamic query strings so they can call another Action.
This is a retreat to Model 1, and smells like a kludge, since
it implies that the business logic is not available outside the
Action, where it could be cleanly called with a method (rather
than a query string).


For an example of using business objects with Struts,
see the early release of Artimus at
http://husted.com/struts/resources.htm#new.


HTH -Ted

About | Sitemap | Contact