Download The Struts User's Guide - Introduction
Transcript
The Struts User's Guide - Building View Components
8 of 9
http://struts.apache.org/userGuide/building_view.html
type="org.apache.struts.actions.ForwardAction"
parameter="homepage"/>
The TilesPlugin configures a special RequestProcessor that determines if the requested view is
a tile and processes it accordingly. Note that we made the homepage tile extend our root layout
tile and changed the body attribute. Tiles inserts the file named in the body attribute into the
main layout.
See the tiles-documentation webapp for in-depth examples.
3.4.4 Image Rendering Components
Some applications require dynamically generated images, like the price charts on a stock
reporting site. Two different approaches are commonly used to meet these requirements:
Render a hyperlink with a URL that executes a servlet request. The servlet will use a
graphics library to render the graphical image, set the content type appropriately (such as
to image/gif), and send back the bytes of that image to the browser, which will display
them just as if it had received a static file.
Render the HTML code necessary to download a Java applet that creates the required
graph. You can configure the graph by setting appropriate initialization parameters for
the applet in the rendered code, or you can have the applet make its own connection to
the server to receive these parameters.
3.4.5 Rendering Text
Some applications require dynamically generated text or markup, such as XML. If a complete
page is being rendered, and can be output using a PrintWriter, this is very easy to do from an
Action:
response.setContentType("text/plain"); // or text/xml
PrintWriter writer = response.getWriter();
// use writer to render text
return(null);
3.4.6 The Struts-EL Tag Library
The Struts-EL tag library is a contributed library in the Struts distribution. It represents an
integration of the Struts tag library with the JavaServer Pages Standard Tag Library, or at least
the "expression evaluation" engine that is used by the JSTL.
The base Struts tag library contains tags which rely on the evaluation of "rtexprvalue"s
(runtime scriptlet expressions) to evaluate dynamic attribute values. For instance, to print a
message from a properties file based on a resource key, you would use the bean:write tag,
perhaps like this:
<bean:message key='<%= stringvar %>'/>
This assumes that stringvar exists as a JSP scripting variable. If you're using the Struts-EL
library, the reference looks very similar, but slightly different, like this:
2005. 10. 10. 1:08