The Action can render the response when convenient. The Struts reload
Action in 1.0.x does this to print "OK" after its complete. It can also
be convenient to have an Action do something like render XML for use by
another system. 

It's just that using Actions to render the presentation is not resusable
in an another environment. In most cases, it's just as easy and much
cleaner to use another servlet to render the response. The coding effort
is equivalent, and you then have the ability to use the servlet outside
of Struts. 

This also corresponds to how Struts works with other presentation
systems. JSPs are glorified servlets, and JSPs are not part of Struts.
The framework just provides some tags that interact with framework.
Likewise, Velocity provided a servlet and toolset that works with the
framework but acts as an independently. If you are using your own
presentation system with Struts, I'd recommend following the same
approach and using your own servlet rather than tweaking-out an Action.

But, again, it's a matter of degree. If you just need to pop out some
text or XML, go for it. But if there is other processing to do be done
on the stream before it is rendered, get it out where it can be reused.

-- Ted Husted, Husted dot Com, Fairport NY US
-- Developing Java Web Applications with Struts
-- Tel: +1 585 737-3463
-- Web: http://husted.com/about/services


Andrew Hill wrote:
> 
> <soapbox>
> Nah. JSPs are definately evil. They arent real (x)html, and they arent real
> Java. (And of course as anything that isnt Java is by definition evil , so
> it follows that jsps... heheh)
> My main objection to JSPs is that they are inelegant (yes - I know thats
> strong language , but its true!). The struts taglibs make them a lot less
> inelegant and make developing apps with them a lot more straightforward, but
> they remain ugly. I have a strong distaste for the idea of mixing the code
> and layout like that. html, scriptlets, tags that you have to rtfm before
> you know what they do..., all very messy and most it definately offends my
> artistic appreciation of the code.
> I feel it is much better to have the dynamic rendering be done using proper
> clean java code, and the layout be done using good pure xhtml (with no non
> xhtml tags! (not that notepad really cares about tags anyhow hehe ;-> ))
> </soapbox>
> 
> We were making use of XMLC to achieve this, however Ive had to ditch it as
> the DOMs it creates have a very dodgy structure and dont even maintain the
> original nesting of elements correctly (not to mention still being glued to
> a hacked version of xerces1.2 !). (I suppose this is what one gets for
> making use of stuff from Barracuda. At this point Im very glad I only
> decided to use the xmlc stuff, and stuck to good ol' struts for my
> controller framework!)
> Ive now written my own (well its not actually mine - the company owns
> everything we write) code which does lots of fun stuff to allow me to obtain
> an org.w3c.Document (without having to type too much code or for the user to
> wait forever for the parser to do its thing) and by manipulating this dom I
> can insert the dynamic content in much the same way as one does it using
> XMLC.
> 
> Its actually quite a good way to learn the inner workings of struts, as
> since Im not using jsps, Im finding myself taking lots of looks at the way
> the taglib source is coded so I can get similar functionality in my code.
> ;-)
> 
> <question>
> While Im on the subject, Ive got a generic servlet that does 'rendering' (or
> more precicely invokes the render() method on a bunch of objects that the
> action selects and forwards to it). However in this case , having a servlet
> to do it seems a bit redundant, as an action already has access to all the
> goodies a servlet gets - the most important of course being the response
> object. Is there any particular reason I shouldnt simply invoke the
> rendering code that is in my rendering class straight from my action and
> write to the response there instead of forwarding to a servlet?
> Or to rephrase it, - do we forward to a jsp or servlet from our action
> because the action(s helper classes) are unable to execute the rendering
> code (such as in the case of a jsp implemented view) or because its good
> design to do it this way or becuase of some other gotcha I havent noticed
> yet?
> </question>

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

Reply via email to