Derek Richardson writes:

>But you still have to duplicate code in the actions, right? Even if
>that code is as simple as:
>
>Service service = Service.getService(SERVICE_KEY);
>Foo[] foos = service.getFoos();
>request.setAttribute(FOO_KEY, foos);
>
>Action chaining allows this code to be written once and used many >times. Thus you get reuse of presentation code, not just business
>logic.

Personally, I would put utility code like this in a super class and make it available to whatever Action wanted to call it. Actions are instantiated once, and there is no performance penalty for have a deep hierarchy.

So there would be something like

setService(request)

that any Action could call.

The BaseAction in Scaffold makes good use of this technique for error handling and such.

What happens with true Action chaining (not to be confused with a simple Action relay) is that instead of using Java calls to create our presentation API, we start to use HTTP to make the API calls instead. IMHO, this is a step backward. The point of Struts is to get us up and out of HTTP and into an object-orientated domain, where we can write proper programs. (Rather than an endless chain of kludges.)

-Ted.



--
Ted Husted,
Struts in Action <http://husted.com/struts/book.html>


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

Reply via email to