You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by hu...@apache.org on 2006/01/21 01:21:00 UTC
svn commit: r370938 [31/50] - in /struts: action/trunk/
action/trunk/conf/java/ action/trunk/src/java/org/apache/struts/
action/trunk/src/java/org/apache/struts/action/
action/trunk/src/java/org/apache/struts/chain/
action/trunk/src/java/org/apache/str...
Modified: struts/action/trunk/xdocs/userGuide/building_model.xml
URL: http://svn.apache.org/viewcvs/struts/action/trunk/xdocs/userGuide/building_model.xml?rev=370938&r1=370937&r2=370938&view=diff
==============================================================================
--- struts/action/trunk/xdocs/userGuide/building_model.xml (original)
+++ struts/action/trunk/xdocs/userGuide/building_model.xml Fri Jan 20 16:19:02 2006
@@ -18,344 +18,470 @@
-->
<document>
-<properties>
- <title>Building Model Components</title>
-</properties>
-
-<body>
-<section name="2. Building Model Components">
-
-<a name="overview"/>
-<subsection name="2.1 Overview">
-
- <p>
- Many requirements documents used for building web applications focus on
- the <em>View</em>.
- However, you should ensure that the processing required for each submitted
- request is also clearly defined from the <em>Model's</em> perspective.
- In general, the developer of the <em>Model</em> components will be focusing
- on the creation of JavaBeans classes that support all of the functional
- requirements.
- The precise nature of the beans required by a particular application will
- vary widely depending on those requirements, but they can generally be
- classified into several categories discussed below.
- However, a brief review of the concept of "scope" as it relates to beans
- and JSP is useful first.
- </p>
-
-</subsection>
-
-<a name="javabeans"/>
-<subsection name="2.2 JavaBeans and Scope">
-
- <p>
- Within a web-based application, JavaBeans can be stored in (and accessed
- from) a number of different collections of "attributes".
- Each collection has different rules for the lifetime of that collection,
- and the visibility of the beans stored there.
- Together, the rules defining lifetime and visibility are called the
- <em>scope</em> of those beans.
- The JavaServer Pages (JSP) Specification defines scope choices using
- the following terms (with the equivalent servlet API concept defined in
- parentheses):
- </p>
-
- <ul>
-
- <li>
- <strong>page</strong> - Beans that are visible within a single JSP page,
- for the lifetime of the current request.
- (Local variables of the <code>service</code> method)
- </li>
-
- <li>
- <strong>request</strong> - Beans that are visible within a single JSP page,
- as well as to any page or servlet that is included in this page,
- or forwarded to by this page.
- (Request attributes)
- </li>
-
- <li>
- <strong>session</strong> - Beans that are visible to all JSP pages and
- servlets that participate in a particular user session, across one
- or more requests.
- (Session attributes)
- </li>
-
- <li>
- <strong>application</strong> - Beans that are visible to all JSP pages and
- servlets that are part of a web application.
- (Servlet context attributes)
- </li>
-
- </ul>
-
- <p>
- It is important to remember that JSP pages and servlets in the same
- web application share the same sets of bean collections.
- For example, a bean stored as a request attribute in a servlet like this:
- </p>
-
- <p>
- <code>MyCart mycart = new MyCart(...);<br />
- request.setAttribute("cart", mycart);
- </code>
- </p>
-
- <p>
- is immediately visible to a JSP page which this servlet forwards to,
- using a standard action tag like this:
- </p>
-
- <p>
- <code><jsp:useBean id="cart" scope="request"<br />
- class="com.mycompany.MyApp.MyCart"/>
- </code>
- </p>
-
-</subsection>
-
-<a name="actionform"/>
-<subsection name="2.3 ActionForm Beans">
-
-
- <p>
- <strong>Note:</strong> While ActionForm beans often have properties that
- correspond to properties in your Model beans, the form beans themselves
- should be considered a Controller component.
- As such, they are able to transfer data between the Model and View layers.
- </p>
-
- <p>
- The Struts framework generally assumes that you have defined an
- <code>ActionForm</code> bean (that is, a Java class extending the
- <code>ActionForm</code> class) for the input forms in your
- application.
- <code>ActionForm</code> beans are sometimes just called "form beans".
- These may be finely-grained objects, so that there is one
- bean for each form, or coarsely-grained so that one bean serves
- several forms, or even an entire application.
- </p>
-
- <p>
- If you declare such beans in your Struts
- configuration file (see "<a href="building_controller.html#4_8_Writing_Action_Mappings">
- Writing Action Mappings</a>"), the Struts controller servlet
- will automatically perform the following services for you, before
- invoking the appropriate <code>Action</code> method:
- </p>
-
- <ul>
-
- <li>
- Check for an instance of a bean of the appropriate class, under the appropriate key,
- in the appropriate scope (request or session).
- </li>
-
- <li>
- If there is no such bean instance available, a new one is
- automatically created and added to the appropriate scope (request or session).
- </li>
-
- <li>
- For every request parameter whose name corresponds to the name
- of a property in the bean, the corresponding setter method will
- be called. This operates in a manner similar to the standard
- JSP action <code><jsp:setProperty></code> when you use the
- asterisk wildcard to select all properties.
- </li>
-
- <li>
- The updated <code>ActionForm</code> bean will be passed to the
- <code>execute</code> method of an <code>Action</code> class
- [<code>org.apache.struts.Action</code>], so that the values can
- be made available to your system state and business logic beans.
- </li>
-
- </ul>
-
- <p>
- For more about coding <code>Actions</code> and <code>ActionForm</code>
- beans, see the "<a href="building_controller.html">Building
- Controller Components</a>" section.
- </p>
-
- <p>
- You should note that a "form" (in the sense discussed here) does not
- necessarily correspond to a single JSP page in the user interface.
- It is common in many applications to have a "form" (from the user's
- perspective) that extends over multiple pages.
- Think, for example, of the wizard style user interface that is commonly
- used when installing new applications.
- Struts encourages you to define a single <code>ActionForm</code> bean that
- contains properties for all of the fields, no matter which page the field
- is actually displayed on.
- Likewise, the various pages of the same form should all be submitted to
- the same Action Class.
- If you follow these suggestions, the page designers can rearrange the
- fields among the various pages, often without requiring changes to the
- processing logic.
- </p>
-
- <p>
- Smaller applications may only need a single ActionForm to service all of
- its input forms.
- Others applications might use a single ActionForm for each major subsystem
- of the application.
- Some teams might prefer to have a separate ActionForm class for each
- distinct input form or workflow.
- How many or how few ActionForms to use is entirely up to you.
- The framework doesn't care.
- </p>
-
-</subsection>
-
-<a name="system_state"/>
-<subsection name="2.4 System State Beans">
-
- <p>
- The actual state of a system is normally represented as a set of one or
- more JavaBeans classes, whose properties define the current state.
- A shopping cart system, for example, will include a bean that represents
- the cart being maintained for each individual shopper, and will (among
- other things) include the set of items that the shopper has currently
- selected for purchase.
- Separately, the system will also include different beans for the user's
- profile information (including their credit card and ship-to addresses),
- as well as the catalog of available items and their current inventory
- levels.
- </p>
-
- <p>
- For small scale systems, or for state information that need not be kept
- for a long period of time, a set of system state beans may contain all the
- knowledge that the system ever has of these particular details.
- Or, as is often the case, the system state beans will represent
- information that is stored permanently in some external database (such as
- a <code>CustomerBean</code> object that corresponds to a particular row in
- the CUSTOMERS table), and are created or removed from the server's memory
- as needed.
- Entity Enterprise JavaBeans are also used for this purpose in large scale
- applications.
- </p>
-
-</subsection>
-
-<a name="business_logic"/>
-<subsection name="2.5 Business Logic Beans">
-
- <p>
- You should encapsulate the functional logic of your application as
- method calls on JavaBeans designed for this purpose.
- These methods may be part of the same classes used for the system state
- beans, or they may be in separate classes dedicated to performing the
- logic.
- In the latter case, you will usually need to pass the system state beans
- to be manipulated to these methods as arguments.
- </p>
-
- <p>
- For maximum code re-use, business logic beans should be designed and
- implemented so that they do <strong>not</strong> know they are being executed in a
- web application environment.
- If you find yourself having to import a <code>javax.servlet.*</code> class
- in your bean, you are tying this business logic to the web application
- environment.
- Consider rearranging things so that your <code>Action</code> classes (part
- of the Controller role, as described below) translate all required
- information from the HTTP request being processed into property setter
- calls on your business logic beans, after which a call to an
- <code>execute</code> method can be made.
- Such a business logic class can be reused in environments other than the
- web application for which they were initially constructed.
- </p>
-
- <p>
- Depending on the complexity and scope of your application, business logic
- beans might be ordinary JavaBeans that interact with system state beans
- passed as arguments, or ordinary JavaBeans that access a database using
- JDBC calls.
- For larger applications, these beans will often be stateful or stateless
- Enterprise JavaBeans (EJBs) instead.
- </p>
-
-</subsection>
-
-<a name="logic_frameworks"/>
-<subsection name="2.6 Business Logic Frameworks">
-
- <p>
- Most teams still roll their own business logic layer using
- plain old JavaBeans (POJOs).
- Though, business layer frameworks are beginning to emerge,
- and now include:
- </p>
- <ul>
- <li>
- <a href="http://jakarta.apache.org/commons/chain/">
- Commons Chain of Responsiblity</a>
- </li>
- <li>
- <a href="http://springframework.org/">Spring</a>
- </li>
- <li>
- <a href="http://www.opensymphony.com/xwork/">XWork</a>
- </li>
- </ul>
-
- <p>
- As of Struts 1.3, Commons Chain is used to construct the default
- Request Processor for the framework.
- See the "<a href="preface.html#chain">Preface</a>" section for more.
- </p>
-</subsection>
-
-<a name="data_frameworks"/>
-<subsection name="2.6 Data Access Frameworks">
-
- <p>
- Most often, the business layer is seen to be distinct from the
- data access layer.
- Some teams roll their own data access objects (DAOs),
- but more and more teams are turning to one of the many data access
- frameworks.
- Some popular data access frameworks include:
- </p>
-
- <ul>
- <li>
- <a href="http://java.sun.com/products/ejb/index.html">
- Enterprise Java Beans</a>
- </li>
- <li>
- <a href="http://www.hibernate.org/">Hibernate</a>
- </li>
- <li>
- <a href="http://ibatis.apache.org">iBATIS</a>
- </li>
- <li>
- <a href="http://java.sun.com/products/jdbc/index.html">
- JDBC</a>
- </li>
- <li>
- <a href="http://db.apache.org/ojb/">
- Object Relational Bridge</a>
- </li>
- </ul>
-
-
- <p>
- For more about using a database with your application, see the
- <a href="../faqs/db-howto.html">Accessing a Database HowTo</a>.
- </p>
-</subsection>
-</section>
-
-<section>
- <p class="right">
- Next: <a href="building_view.html">Building View Components</a>
- </p>
-</section>
+ <properties>
+ <title>Building Model Components</title>
+ </properties>
+
+ <body>
+ <section name="2. Building Model Components">
+
+ <a name="overview"/>
+ <subsection name="2.1 Overview">
+
+ <p>
+ Many requirements documents used for building web
+ applications focus on
+ the
+ <em>View</em>
+ .
+ However, you should ensure that the processing required
+ for each submitted
+ request is also clearly defined from the
+ <em>Model's</em>
+ perspective.
+ In general, the developer of the
+ <em>Model</em>
+ components will be focusing
+ on the creation of JavaBeans classes that support all of
+ the functional
+ requirements.
+ The precise nature of the beans required by a particular
+ application will
+ vary widely depending on those requirements, but they can
+ generally be
+ classified into several categories discussed below.
+ However, a brief review of the concept of "scope" as it
+ relates to beans
+ and JSP is useful first.
+ </p>
+
+ </subsection>
+
+ <a name="javabeans"/>
+ <subsection name="2.2 JavaBeans and Scope">
+
+ <p>
+ Within a web-based application, JavaBeans can be stored in
+ (and accessed
+ from) a number of different collections of "attributes".
+ Each collection has different rules for the lifetime of
+ that collection,
+ and the visibility of the beans stored there.
+ Together, the rules defining lifetime and visibility are
+ called the
+ <em>scope</em>
+ of those beans.
+ The JavaServer Pages (JSP) Specification defines scope
+ choices using
+ the following terms (with the equivalent servlet API
+ concept defined in
+ parentheses):
+ </p>
+
+ <ul>
+
+ <li>
+ <strong>page</strong>
+ - Beans that are visible within a single JSP page,
+ for the lifetime of the current request.
+ (Local variables of the
+ <code>service</code>
+ method)
+ </li>
+
+ <li>
+ <strong>request</strong>
+ - Beans that are visible within a single JSP page,
+ as well as to any page or servlet that is included in
+ this page,
+ or forwarded to by this page.
+ (Request attributes)
+ </li>
+
+ <li>
+ <strong>session</strong>
+ - Beans that are visible to all JSP pages and
+ servlets that participate in a particular user
+ session, across one
+ or more requests.
+ (Session attributes)
+ </li>
+
+ <li>
+ <strong>application</strong>
+ - Beans that are visible to all JSP pages and
+ servlets that are part of a web application.
+ (Servlet context attributes)
+ </li>
+
+ </ul>
+
+ <p>
+ It is important to remember that JSP pages and servlets in
+ the same
+ web application share the same sets of bean collections.
+ For example, a bean stored as a request attribute in a
+ servlet like this:
+ </p>
+
+ <p>
+ <code>MyCart mycart = new MyCart(...);
+ <br/>
+ request.setAttribute("cart", mycart);
+ </code>
+ </p>
+
+ <p>
+ is immediately visible to a JSP page which this servlet
+ forwards to,
+ using a standard action tag like this:
+ </p>
+
+ <p>
+ <code><jsp:useBean id="cart" scope="request"
+ <br/>
+ class="com.mycompany.MyApp.MyCart"/>
+ </code>
+ </p>
+
+ </subsection>
+
+ <a name="actionform"/>
+ <subsection name="2.3 ActionForm Beans">
+
+
+ <p>
+ <strong>Note:</strong>
+ While ActionForm beans often have properties that
+ correspond to properties in your Model beans, the form
+ beans themselves
+ should be considered a Controller component.
+ As such, they are able to transfer data between the Model
+ and View layers.
+ </p>
+
+ <p>
+ The Struts framework generally assumes that you have
+ defined an
+ <code>ActionForm</code>
+ bean (that is, a Java class extending the
+ <code>ActionForm</code>
+ class) for the input forms in your
+ application.
+ <code>ActionForm</code>
+ beans are sometimes just called "form beans".
+ These may be finely-grained objects, so that there is one
+ bean for each form, or coarsely-grained so that one bean
+ serves
+ several forms, or even an entire application.
+ </p>
+
+ <p>
+ If you declare such beans in your Struts
+ configuration file (see "
+ <a href="building_controller.html#4_8_Writing_Action_Mappings">
+ Writing Action Mappings</a>
+ "), the Struts controller servlet
+ will automatically perform the following services for you,
+ before
+ invoking the appropriate
+ <code>Action</code>
+ method:
+ </p>
+
+ <ul>
+
+ <li>
+ Check for an instance of a bean of the appropriate
+ class, under the appropriate key,
+ in the appropriate scope (request or session).
+ </li>
+
+ <li>
+ If there is no such bean instance available, a new one
+ is
+ automatically created and added to the appropriate
+ scope (request or session).
+ </li>
+
+ <li>
+ For every request parameter whose name corresponds to
+ the name
+ of a property in the bean, the corresponding setter
+ method will
+ be called. This operates in a manner similar to the
+ standard
+ JSP action
+ <code><jsp:setProperty></code>
+ when you use the
+ asterisk wildcard to select all properties.
+ </li>
+
+ <li>
+ The updated
+ <code>ActionForm</code>
+ bean will be passed to the
+ <code>execute</code>
+ method of an
+ <code>Action</code>
+ class
+ [
+ <code>org.apache.struts.Action</code>
+ ], so that the values can
+ be made available to your system state and business
+ logic beans.
+ </li>
+
+ </ul>
+
+ <p>
+ For more about coding
+ <code>Actions</code>
+ and
+ <code>ActionForm</code>
+ beans, see the "
+ <a href="building_controller.html">Building
+ Controller Components</a>
+ " section.
+ </p>
+
+ <p>
+ You should note that a "form" (in the sense discussed
+ here) does not
+ necessarily correspond to a single JSP page in the user
+ interface.
+ It is common in many applications to have a "form" (from
+ the user's
+ perspective) that extends over multiple pages.
+ Think, for example, of the wizard style user interface
+ that is commonly
+ used when installing new applications.
+ Struts encourages you to define a single
+ <code>ActionForm</code>
+ bean that
+ contains properties for all of the fields, no matter which
+ page the field
+ is actually displayed on.
+ Likewise, the various pages of the same form should all be
+ submitted to
+ the same Action Class.
+ If you follow these suggestions, the page designers can
+ rearrange the
+ fields among the various pages, often without requiring
+ changes to the
+ processing logic.
+ </p>
+
+ <p>
+ Smaller applications may only need a single ActionForm to
+ service all of
+ its input forms.
+ Others applications might use a single ActionForm for each
+ major subsystem
+ of the application.
+ Some teams might prefer to have a separate ActionForm
+ class for each
+ distinct input form or workflow.
+ How many or how few ActionForms to use is entirely up to
+ you.
+ The framework doesn't care.
+ </p>
+
+ </subsection>
+
+ <a name="system_state"/>
+ <subsection name="2.4 System State Beans">
+
+ <p>
+ The actual state of a system is normally represented as a
+ set of one or
+ more JavaBeans classes, whose properties define the
+ current state.
+ A shopping cart system, for example, will include a bean
+ that represents
+ the cart being maintained for each individual shopper, and
+ will (among
+ other things) include the set of items that the shopper
+ has currently
+ selected for purchase.
+ Separately, the system will also include different beans
+ for the user's
+ profile information (including their credit card and
+ ship-to addresses),
+ as well as the catalog of available items and their
+ current inventory
+ levels.
+ </p>
+
+ <p>
+ For small scale systems, or for state information that
+ need not be kept
+ for a long period of time, a set of system state beans may
+ contain all the
+ knowledge that the system ever has of these particular
+ details.
+ Or, as is often the case, the system state beans will
+ represent
+ information that is stored permanently in some external
+ database (such as
+ a
+ <code>CustomerBean</code>
+ object that corresponds to a particular row in
+ the CUSTOMERS table), and are created or removed from the
+ server's memory
+ as needed.
+ Entity Enterprise JavaBeans are also used for this purpose
+ in large scale
+ applications.
+ </p>
+
+ </subsection>
+
+ <a name="business_logic"/>
+ <subsection name="2.5 Business Logic Beans">
+
+ <p>
+ You should encapsulate the functional logic of your
+ application as
+ method calls on JavaBeans designed for this purpose.
+ These methods may be part of the same classes used for the
+ system state
+ beans, or they may be in separate classes dedicated to
+ performing the
+ logic.
+ In the latter case, you will usually need to pass the
+ system state beans
+ to be manipulated to these methods as arguments.
+ </p>
+
+ <p>
+ For maximum code re-use, business logic beans should be
+ designed and
+ implemented so that they do
+ <strong>not</strong>
+ know they are being executed in a
+ web application environment.
+ If you find yourself having to import a
+ <code>javax.servlet.*</code>
+ class
+ in your bean, you are tying this business logic to the web
+ application
+ environment.
+ Consider rearranging things so that your
+ <code>Action</code>
+ classes (part
+ of the Controller role, as described below) translate all
+ required
+ information from the HTTP request being processed into
+ property setter
+ calls on your business logic beans, after which a call to
+ an
+ <code>execute</code>
+ method can be made.
+ Such a business logic class can be reused in environments
+ other than the
+ web application for which they were initially constructed.
+ </p>
+
+ <p>
+ Depending on the complexity and scope of your application,
+ business logic
+ beans might be ordinary JavaBeans that interact with
+ system state beans
+ passed as arguments, or ordinary JavaBeans that access a
+ database using
+ JDBC calls.
+ For larger applications, these beans will often be
+ stateful or stateless
+ Enterprise JavaBeans (EJBs) instead.
+ </p>
+
+ </subsection>
+
+ <a name="logic_frameworks"/>
+ <subsection name="2.6 Business Logic Frameworks">
+
+ <p>
+ Most teams still roll their own business logic layer using
+ plain old JavaBeans (POJOs).
+ Though, business layer frameworks are beginning to emerge,
+ and now include:
+ </p>
+ <ul>
+ <li>
+ <a href="http://jakarta.apache.org/commons/chain/">
+ Commons Chain of Responsiblity</a>
+ </li>
+ <li>
+ <a href="http://springframework.org/">Spring</a>
+ </li>
+ <li>
+ <a href="http://www.opensymphony.com/xwork/">XWork</a>
+ </li>
+ </ul>
+
+ <p>
+ As of Struts 1.3, Commons Chain is used to construct the
+ default
+ Request Processor for the framework.
+ See the "
+ <a href="preface.html#chain">Preface</a>
+ " section for more.
+ </p>
+ </subsection>
+
+ <a name="data_frameworks"/>
+ <subsection name="2.6 Data Access Frameworks">
+
+ <p>
+ Most often, the business layer is seen to be distinct from
+ the
+ data access layer.
+ Some teams roll their own data access objects (DAOs),
+ but more and more teams are turning to one of the many
+ data access
+ frameworks.
+ Some popular data access frameworks include:
+ </p>
+
+ <ul>
+ <li>
+ <a href="http://java.sun.com/products/ejb/index.html">
+ Enterprise Java Beans</a>
+ </li>
+ <li>
+ <a href="http://www.hibernate.org/">Hibernate</a>
+ </li>
+ <li>
+ <a href="http://ibatis.apache.org">iBATIS</a>
+ </li>
+ <li>
+ <a href="http://java.sun.com/products/jdbc/index.html">
+ JDBC</a>
+ </li>
+ <li>
+ <a href="http://db.apache.org/ojb/">
+ Object Relational Bridge</a>
+ </li>
+ </ul>
+
+
+ <p>
+ For more about using a database with your application, see
+ the
+ <a href="../faqs/db-howto.html">Accessing a Database
+ HowTo</a>
+ .
+ </p>
+ </subsection>
+ </section>
+
+ <section>
+ <p class="right">
+ Next:
+ <a href="building_view.html">Building View Components</a>
+ </p>
+ </section>
-</body>
+ </body>
</document>
Modified: struts/action/trunk/xdocs/userGuide/building_view.xml
URL: http://svn.apache.org/viewcvs/struts/action/trunk/xdocs/userGuide/building_view.xml?rev=370938&r1=370937&r2=370938&view=diff
==============================================================================
--- struts/action/trunk/xdocs/userGuide/building_view.xml (original)
+++ struts/action/trunk/xdocs/userGuide/building_view.xml Fri Jan 20 16:19:02 2006
@@ -18,599 +18,797 @@
-->
<document>
-<properties>
- <title>Building View Components</title>
-</properties>
+ <properties>
+ <title>Building View Components</title>
+ </properties>
+
+ <body>
+ <section name="3. Building View Components">
+
+ <a name="overview"/>
+ <subsection name="3.1 Overview">
+
+ <p>
+ The framework provides infrastructural support for view
+ components,
+ but does not provide any actual view components of its
+ own.
+ Several options are available, such as
+ <a href="http://struts.apache.org/struts-taglib/">Struts
+ Taglib</a>
+ ,
+ <a href="http://struts.sourceforge.net/struts-cocoon/">
+ Struts Cocoon</a>
+ ,
+ <a href="http://jakarta.apache.org/velocity/tools/struts/">
+ Struts Velocity</a>
+ ,
+ and
+ <a href="http://stxx.sourceforge.net/">Stxx</a>
+ ,
+ among others.
+ </p>
+
+ <p>
+ Features provided by the framework for direct use by view
+ components
+ include
+ <a href="#resources">Message Resources</a>
+ for localizing text and images,
+ and
+ <a href="#formbeans">FormBeans</a>
+ to provide for automatic
+ population and validation.
+ </p>
+
+ </subsection>
+
+ <a name="i18n"/>
+ <subsection name="3.2 Internationalized Messages">
+
+ <p>
+ A few years ago, application developers could count on
+ having to support
+ only residents of their own country, who are used to only
+ one (or
+ sometimes two) languages, and one way to represent numeric
+ quantities like
+ dates, numbers, and monetary values.
+ However, the explosion of application development based on
+ web
+ technologies, as well as the deployment of such
+ applications on the
+ Internet and other broadly accessible networks, have
+ rendered national
+ boundaries invisible in many cases.
+ This has translated (if you will pardon the pun) into a
+ need for
+ applications to support
+ <em>internationalization</em>
+ (often called "i18n"
+ because 18 is the number of letters in between the "i" and
+ the "n") and
+ <em>localization</em>
+ .
+ </p>
+
+ <p>
+ Struts builds upon the standard classes available on the
+ Java platform to
+ build internationalized and localized applications.
+ The key concepts to become familiar with are:
+ </p>
+
+ <ul>
+
+ <li>
+ <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/Locale.html">
+ <strong>Locale</strong>
+ </a>
+ - The fundamental Java class that supports
+ internationalization is
+ <code>Locale</code>
+ .
+ Each
+ <code>Locale</code>
+ represents a particular choice of country and
+ language (plus an optional language variant), and also
+ a set of
+ formatting assumptions for things like numbers and
+ dates.
+ </li>
+
+ <li>
+ <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/ResourceBundle.html">
+ <strong>ResourceBundle</strong>
+ </a>
+ - The
+ <code>java.util.ResourceBundle</code>
+ class provides the fundamental tools for supporting
+ messages in
+ multiple languages.
+ See the Javadocs for the
+ <code>ResourceBundle</code>
+ class, and the
+ information on Internationalization in the
+ documentation bundle for your
+ JDK release, for more information.
+ </li>
+
+ <li>
+ <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/PropertyResourceBundle.html">
+ <strong>PropertyResourceBundle</strong>
+ </a>
+ - One of the standard
+ implementations of
+ <code>ResourceBundle</code>
+ allows you to define
+ resources using the same "name=value" syntax used to
+ initialize
+ properties files.
+ This is very convenient for preparing resource bundles
+ with messages
+ that are used in a web application, because these
+ messages are
+ generally text oriented.
+ </li>
+
+ <li>
+ <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/text/MessageFormat.html">
+ <strong>MessageFormat</strong>
+ </a>
+ - The
+ <code>java.text.MessageFormat</code>
+ class allows you to replace portions of a message
+ string (in this
+ case, one retrieved from a resource bundle) with
+ arguments specified
+ at run time.
+ This is useful in cases where you are creating a
+ sentence, but the
+ words would appear in a different order in different
+ languages.
+ The placeholder string
+ <code>{0}</code>
+ in the message is replaced by
+ the first runtime argument,
+ <code>{1}</code>
+ is replaced by the
+ second argument, and so on.
+ </li>
+
+ <li>
+ <a href="../apidocs/org/apache/struts/util/MessageResources.html">
+ <strong>MessageResources</strong>
+ </a>
+ - The framework class
+ <code>org.apache.struts.util.MessageResources</code>
+ lets you treat
+ a set of resource bundles like a database, and allows
+ you to request
+ a particular message string for a particular Locale
+ (normally one
+ associated with the current user) instead of for the
+ default Locale
+ the server itself is running in.
+ </li>
+
+ </ul>
+
+ <p>
+ Please note that the i18n support in a server-side
+ framework is limited to
+ the
+ <strong>presentation</strong>
+ of internationalized text and images to the user.
+ Support for Locale specific
+ <strong>input methods</strong>
+ (used with languages
+ such as Japanese, Chinese, and Korean) is left up to the
+ client device,
+ which is usually a web browser.
+ </p>
+
+ <p>
+ For an internationalized application, follow the steps
+ described in
+ the Internationalization document in the JDK documentation
+ bundle for your
+ platform to create a properties file containing the
+ messages for each
+ language.
+ An example will illustrate this further:
+ </p>
+
+ <p>
+ Assume that your source code is created in package
+ <code>com.mycompany.mypackage</code>
+ , so it is stored in a directory
+ (relative to your source directory) named
+ <code>com/mycompany/mypackage</code>
+ .
+ To create a resource bundle called
+ <code>com.mycompany.mypackage.MyApplication</code>
+ , you would create the
+ following files in the
+ <code>com/mycompany/mypackage</code>
+ directory:
+ </p>
+
+ <ul>
+
+ <li>
+ <strong>MyApplication.properties</strong>
+ - Contains the messages in the default
+ language for your server.
+ If your default language is English, you might have an
+ entry like
+ this:
+ <code>prompt.hello=Hello</code>
+ </li>
+
+ <li>
+ <strong>MyApplication_xx.properties</strong>
+ - Contains the same messages in the
+ language whose ISO language code is "xx" (See the
+ <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/ResourceBundle.html">
+ ResourceBundle Javadoc</a>
+ page for a link to the current list).
+ For a French version of the message shown above, you
+ would have this
+ entry:
+ <code>prompt.hello=Bonjour</code>
+ You can have resource bundle files for as many
+ languages as you need.
+ </li>
+
+ </ul>
+
+ <p>
+ When you configure the controller servlet via the
+ struts-config.xml
+ configuration file, one of the things you will need to
+ define is
+ the base name of the resource bundle for the application.
+ In the case described above, it would be
+ <code>com.mycompany.mypackage.MyApplication</code>
+ .
+ </p>
-<body>
-<section name="3. Building View Components">
-
-<a name="overview"/>
-<subsection name="3.1 Overview">
-
- <p>
- The framework provides infrastructural support for view components,
- but does not provide any actual view components of its own.
- Several options are available, such as
- <a href="http://struts.apache.org/struts-taglib/">Struts Taglib</a>,
- <a href="http://struts.sourceforge.net/struts-cocoon/">Struts Cocoon</a>,
- <a href="http://jakarta.apache.org/velocity/tools/struts/">Struts Velocity</a>,
- and <a href="http://stxx.sourceforge.net/">Stxx</a>,
- among others.
- </p>
-
- <p>
- Features provided by the framework for direct use by view components
- include <a href="#resources">Message Resources</a>
- for localizing text and images,
- and <a href="#formbeans">FormBeans</a> to provide for automatic
- population and validation.
- </p>
-
-</subsection>
-
-<a name="i18n"/>
-<subsection name="3.2 Internationalized Messages">
-
- <p>
- A few years ago, application developers could count on having to support
- only residents of their own country, who are used to only one (or
- sometimes two) languages, and one way to represent numeric quantities like
- dates, numbers, and monetary values.
- However, the explosion of application development based on web
- technologies, as well as the deployment of such applications on the
- Internet and other broadly accessible networks, have rendered national
- boundaries invisible in many cases.
- This has translated (if you will pardon the pun) into a need for
- applications to support <em>internationalization</em> (often called "i18n"
- because 18 is the number of letters in between the "i" and the "n") and
- <em>localization</em>.
- </p>
-
- <p>
- Struts builds upon the standard classes available on the Java platform to
- build internationalized and localized applications.
- The key concepts to become familiar with are:
- </p>
-
- <ul>
-
- <li>
- <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/Locale.html">
- <strong>Locale</strong></a> - The fundamental Java class that supports
- internationalization is <code>Locale</code>.
- Each <code>Locale</code> represents a particular choice of country and
- language (plus an optional language variant), and also a set of
- formatting assumptions for things like numbers and dates.
- </li>
-
- <li>
- <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/ResourceBundle.html">
- <strong>ResourceBundle</strong></a> - The <code>java.util.ResourceBundle</code>
- class provides the fundamental tools for supporting messages in
- multiple languages.
- See the Javadocs for the <code>ResourceBundle</code> class, and the
- information on Internationalization in the documentation bundle for your
- JDK release, for more information.
- </li>
-
- <li>
- <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/PropertyResourceBundle.html">
- <strong>PropertyResourceBundle</strong></a> - One of the standard
- implementations of <code>ResourceBundle</code> allows you to define
- resources using the same "name=value" syntax used to initialize
- properties files.
- This is very convenient for preparing resource bundles with messages
- that are used in a web application, because these messages are
- generally text oriented.
- </li>
-
- <li>
- <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/text/MessageFormat.html">
- <strong>MessageFormat</strong></a> - The <code>java.text.MessageFormat</code>
- class allows you to replace portions of a message string (in this
- case, one retrieved from a resource bundle) with arguments specified
- at run time.
- This is useful in cases where you are creating a sentence, but the
- words would appear in a different order in different languages.
- The placeholder string <code>{0}</code> in the message is replaced by
- the first runtime argument, <code>{1}</code> is replaced by the
- second argument, and so on.
- </li>
-
- <li>
- <a href="../apidocs/org/apache/struts/util/MessageResources.html">
- <strong>MessageResources</strong></a> - The framework class
- <code>org.apache.struts.util.MessageResources</code> lets you treat
- a set of resource bundles like a database, and allows you to request
- a particular message string for a particular Locale (normally one
- associated with the current user) instead of for the default Locale
- the server itself is running in.
- </li>
-
- </ul>
-
- <p>
- Please note that the i18n support in a server-side framework is limited to
- the <strong>presentation</strong> of internationalized text and images to the user.
- Support for Locale specific <strong>input methods</strong> (used with languages
- such as Japanese, Chinese, and Korean) is left up to the client device,
- which is usually a web browser.
- </p>
-
- <p>
- For an internationalized application, follow the steps described in
- the Internationalization document in the JDK documentation bundle for your
- platform to create a properties file containing the messages for each
- language.
- An example will illustrate this further:
- </p>
-
- <p>
- Assume that your source code is created in package
- <code>com.mycompany.mypackage</code>, so it is stored in a directory
- (relative to your source directory) named
- <code>com/mycompany/mypackage</code>.
- To create a resource bundle called
- <code>com.mycompany.mypackage.MyApplication</code>, you would create the
- following files in the <code>com/mycompany/mypackage</code> directory:
- </p>
-
- <ul>
-
- <li>
- <strong>MyApplication.properties</strong> - Contains the messages in the default
- language for your server.
- If your default language is English, you might have an entry like
- this: <code>prompt.hello=Hello</code>
- </li>
-
- <li>
- <strong>MyApplication_xx.properties</strong> - Contains the same messages in the
- language whose ISO language code is "xx" (See the
- <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/ResourceBundle.html">
- ResourceBundle Javadoc</a> page for a link to the current list).
- For a French version of the message shown above, you would have this
- entry: <code>prompt.hello=Bonjour</code>
- You can have resource bundle files for as many languages as you need.
- </li>
-
- </ul>
-
- <p>
- When you configure the controller servlet via the struts-config.xml
- configuration file, one of the things you will need to define is
- the base name of the resource bundle for the application.
- In the case described above, it would be
- <code>com.mycompany.mypackage.MyApplication</code>.
- </p>
-
-<source><![CDATA[
+ <source><![CDATA[
<message-resources parameter="com.mycompany.mypackage.MyApplication"/>
]]></source>
- <p>
- The important thing is for the resource bundle to be found on the
- class path for your application.
- Another approach is to store the <code>MyResources.properties</code>
- file in your application's <code>classes</code> folder.
- You can then simply specify "myResources" as the application value.
- Just be careful it is not deleted if your build script deletes
- classes as part of a "clean" target.
- </p>
-
- <p>
- If it does, here is an Ant task to run when compiling your application
- that copies the contents of a <code>src/conf</code>
- directory to the <code>classes</code> directory:
- </p>
+ <p>
+ The important thing is for the resource bundle to be found
+ on the
+ class path for your application.
+ Another approach is to store the
+ <code>MyResources.properties</code>
+ file in your application's
+ <code>classes</code>
+ folder.
+ You can then simply specify "myResources" as the
+ application value.
+ Just be careful it is not deleted if your build script
+ deletes
+ classes as part of a "clean" target.
+ </p>
+
+ <p>
+ If it does, here is an Ant task to run when compiling your
+ application
+ that copies the contents of a
+ <code>src/conf</code>
+ directory to the
+ <code>classes</code>
+ directory:
+ </p>
-<source><![CDATA[
+ <source><![CDATA[
<!-- Copy any configuration files -->
<copy todir="classes">
<fileset dir="src/conf"/>
</copy>
]]></source>
-</subsection>
+ </subsection>
-<a name="form_beans"/>
-<subsection name="3.3 Forms and FormBean Interactions">
+ <a name="form_beans"/>
+ <subsection name="3.3 Forms and FormBean Interactions">
-<p>
- <strong>Note:</strong> While the examples given here use JSP and custom tags,
- the ActionForm beans and the other controller components are
- View neutral.
- The framework be used with Cocoon, Velocity Templates, XSLT, and
- any other presentation technology that can be rendered via a Java servlet.
-</p>
-
-</subsection>
-
- <a name="form_population"/>
- <subsection name="3.3.1 Automatic Form Population">
-
- <p>
- At one time or another, most web developers have built forms using
- the standard capabilities of HTML, such as the <code><input></code>
- tag.
- Users have come to expect interactive applications to have certain
- behaviors, and one of these expectations relates to error handling -- if
- the user makes an error, the application should allow them to fix just
- what needs to be changed -- without having to re-enter any of the rest
- of the information on the current page or form.
- </p>
-
- <p>
- Fulfilling this expectation is tedious and cumbersome when coding with
- standard HTML and JSP pages.
- For example, an input element for a <code>username</code> field might
- look like this (in JSP):
- </p>
-
-<source><![CDATA[
+ <p>
+ <strong>Note:</strong>
+ While the examples given here use JSP and custom tags,
+ the ActionForm beans and the other controller components
+ are
+ View neutral.
+ The framework be used with Cocoon, Velocity Templates,
+ XSLT, and
+ any other presentation technology that can be rendered via
+ a Java servlet.
+ </p>
+
+ </subsection>
+
+ <a name="form_population"/>
+ <subsection name="3.3.1 Automatic Form Population">
+
+ <p>
+ At one time or another, most web developers have built
+ forms using
+ the standard capabilities of HTML, such as the
+ <code><input></code>
+ tag.
+ Users have come to expect interactive applications to have
+ certain
+ behaviors, and one of these expectations relates to error
+ handling -- if
+ the user makes an error, the application should allow them
+ to fix just
+ what needs to be changed -- without having to re-enter any
+ of the rest
+ of the information on the current page or form.
+ </p>
+
+ <p>
+ Fulfilling this expectation is tedious and cumbersome when
+ coding with
+ standard HTML and JSP pages.
+ For example, an input element for a
+ <code>username</code>
+ field might
+ look like this (in JSP):
+ </p>
+
+ <source><![CDATA[
<input type="text" name="username"
value="<%= loginBean.getUsername() >"/>
]]></source>
- <p>
- which is difficult to type correctly, confuses HTML developers who are
- not knowledgeable about programming concepts, and can cause problems with
- HTML editors.
- Instead, Struts Taglibs provides a comprehensive facility for
- building forms,
- based on the Custom Tag Library facility of JSP 1.1.
- The case above would be rendered like this using Struts Taglibs:
- </p>
+ <p>
+ which is difficult to type correctly, confuses HTML
+ developers who are
+ not knowledgeable about programming concepts, and can
+ cause problems with
+ HTML editors.
+ Instead, Struts Taglibs provides a comprehensive facility
+ for
+ building forms,
+ based on the Custom Tag Library facility of JSP 1.1.
+ The case above would be rendered like this using Struts
+ Taglibs:
+ </p>
-<source><![CDATA[
+ <source><![CDATA[
<html:text property="username"/>;
]]></source>
- <p>
- with no need to explicitly refer to the JavaBean from which the initial
- value is retrieved. That is handled automatically by the JSP tag, using
- facilities provided by the framework.
- </p>
-
- <p>
- HTML forms are sometimes used to upload other files.
- Most browsers support this through a <input type="file"> element,
- that generates a file browse button, but it's up to the developer to
- handle the incoming files.
- The framework handles these "multipart" forms in a way identical to building
- normal forms.
- </p>
-
- <p>
- For an example of using the framework to create a simple login form,
- see the "<a href="../faqs/actionForm.html">
- Buiding an ActionForm Howto</a>".
- </p>
-</subsection>
-
-<a name="form_validation"/>
-<subsection name="3.3.2 Automatic Form Validation">
-
- <p>
- In addition to the form and bean interactions described above,
- The framework offers an additional facility to validate the input
- fields it has received.
- To utilize this feature, override the following method in your ActionForm
- class:
- </p>
+ <p>
+ with no need to explicitly refer to the JavaBean from
+ which the initial
+ value is retrieved. That is handled automatically by the
+ JSP tag, using
+ facilities provided by the framework.
+ </p>
+
+ <p>
+ HTML forms are sometimes used to upload other files.
+ Most browsers support this through a <input type="file">
+ element,
+ that generates a file browse button, but it's up to the
+ developer to
+ handle the incoming files.
+ The framework handles these "multipart" forms in a way
+ identical to building
+ normal forms.
+ </p>
+
+ <p>
+ For an example of using the framework to create a simple
+ login form,
+ see the "
+ <a href="../faqs/actionForm.html">
+ Buiding an ActionForm Howto</a>
+ ".
+ </p>
+ </subsection>
+
+ <a name="form_validation"/>
+ <subsection name="3.3.2 Automatic Form Validation">
+
+ <p>
+ In addition to the form and bean interactions described
+ above,
+ The framework offers an additional facility to validate
+ the input
+ fields it has received.
+ To utilize this feature, override the following method in
+ your ActionForm
+ class:
+ </p>
-<source><![CDATA[
+ <source><![CDATA[
validate(ActionMapping mapping,
HttpServletRequest request);
]]></source>
- <p>
- The <code>validate</code> method is called by the controller servlet after
- the bean properties have been populated, but before the corresponding
- action class's <code>execute</code> method is invoked.
- The <code>validate</code> method has the following options:
- </p>
-
- <ul>
-
- <li>
- Perform the appropriate validations and find no problems -- Return
- either <code>null</code> or a zero-length ActionErrors instance,
- and the controller servlet will proceed to call the
- <code>execute</code> method of the appropriate
- <code>Action</code> class.
- </li>
-
- <li>
- Perform the appropriate validations and find problems -- Return an
- ActionErrors instance containing <code>ActionMessage</code>'s, which
- are classes that contain the error message keys (into the
- application's <code>MessageResources</code> bundle) that should be
- displayed.
- The controller servlet will store this array as a request attribute
- suitable for use by the <code><html:errors></code> tag, and
- will forward control back to the input form (identified by the
- <code>input</code> property for this <code>ActionMapping</code>).
- </li>
-
- </ul>
-
- <p>
- As mentioned earlier, this feature is entirely optional.
- The default implementation of the <code>validate</code> method returns
- <code>null</code>, and the controller servlet will assume that any
- required validation is done by the action class.
- </p>
-
- <p>
- One common approach is to perform simple, prima facia validations using
- the ActionForm <code>validate</code> method, and then handle the
- "business logic" validation from the Action.
- </p>
-
- <p>
- The Struts Validator, covered in the next section, may be used to easily
- validate ActionForms.
- </p>
-
-</subsection>
-
-<a name="validator"/>
-<subsection name="3.3.3 The Struts Validator">
-
-
- <p>
- Configuring the Validator to perform form validation is easy.
- </p>
- <ol>
-
- <li>
- The ActionForm bean must extend ValidatorForm.
- </li>
- <li>
- The form's JSP must include the
- <a href="struts-html.html"><html:javascript></a> tag for client
- side validation.
- </li>
- <li>
- You must define the validation rules in an xml file like this:
-
-<source><![CDATA[
+ <p>
+ The
+ <code>validate</code>
+ method is called by the controller servlet after
+ the bean properties have been populated, but before the
+ corresponding
+ action class's
+ <code>execute</code>
+ method is invoked.
+ The
+ <code>validate</code>
+ method has the following options:
+ </p>
+
+ <ul>
+
+ <li>
+ Perform the appropriate validations and find no
+ problems -- Return
+ either
+ <code>null</code>
+ or a zero-length ActionErrors instance,
+ and the controller servlet will proceed to call the
+ <code>execute</code>
+ method of the appropriate
+ <code>Action</code>
+ class.
+ </li>
+
+ <li>
+ Perform the appropriate validations and find problems
+ -- Return an
+ ActionErrors instance containing
+ <code>ActionMessage</code>
+ 's, which
+ are classes that contain the error message keys (into
+ the
+ application's
+ <code>MessageResources</code>
+ bundle) that should be
+ displayed.
+ The controller servlet will store this array as a
+ request attribute
+ suitable for use by the
+ <code><html:errors></code>
+ tag, and
+ will forward control back to the input form
+ (identified by the
+ <code>input</code>
+ property for this
+ <code>ActionMapping</code>
+ ).
+ </li>
+
+ </ul>
+
+ <p>
+ As mentioned earlier, this feature is entirely optional.
+ The default implementation of the
+ <code>validate</code>
+ method returns
+ <code>null</code>
+ , and the controller servlet will assume that any
+ required validation is done by the action class.
+ </p>
+
+ <p>
+ One common approach is to perform simple, prima facia
+ validations using
+ the ActionForm
+ <code>validate</code>
+ method, and then handle the
+ "business logic" validation from the Action.
+ </p>
+
+ <p>
+ The Struts Validator, covered in the next section, may be
+ used to easily
+ validate ActionForms.
+ </p>
+
+ </subsection>
+
+ <a name="validator"/>
+ <subsection name="3.3.3 The Struts Validator">
+
+
+ <p>
+ Configuring the Validator to perform form validation is
+ easy.
+ </p>
+ <ol>
+
+ <li>
+ The ActionForm bean must extend ValidatorForm.
+ </li>
+ <li>
+ The form's JSP must include the
+ <a href="struts-html.html"><html:javascript></a>
+ tag for client
+ side validation.
+ </li>
+ <li>
+ You must define the validation rules in an xml file
+ like this:
+
+ <source><![CDATA[
<form-validation>
-<formset>
+<formset>
<form name="logonForm">
<field property="username" depends="required">
<msg name="required" key="error.username"/>
- </field>
-</form>
-</formset>
+ </field>
+</form>
+</formset>
</form-validation>
]]></source>
-The msg element points to the message resource key to use when generating the error message.
-</li>
-<li>Lastly, you must enable the ValidatorPlugin in the struts-config.xml file like this:
-<source><![CDATA[
+ The msg element points to the message resource key to
+ use when generating the error message.
+ </li>
+ <li>Lastly, you must enable the ValidatorPlugin in the
+ struts-config.xml file like this:
+ <source><![CDATA[
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
-<set-property
-property="pathnames"
+<set-property
+property="pathnames"
value="/org/apache/struts/validator/validator-rules.xml,
/WEB-INF/validation.xml"/>
</plug-in>
]]></source>
- </li>
- </ol>
-
- <p>
- <strong>Note:</strong> If your required form property is one of the Java object representations of
- primitive types (ie. java.lang.Integer), you must set the ActionServlet's convertNull init.
- parameter to true. Failing to do this will result in the required validation not being performed
- on that field because it will default to 0.
- </p>
-
- <p>
- For more about the Struts Validator, see the
- <a href="http://struts.apache.org/struts-taglib/dev_validator.html">Developers Guide</a>.
- </p>
-
-</subsection>
-
-
-<a name="Tiles"/>
-<subsection name="3.3.4 Page Composition With Tiles">
-
- <p>
- Tiles is a powerful templating library that allows you to construct views
- by combining various "tiles".
- Here's a quick setup guide:
- </p>
-
- <ol>
- <li>
- Create a /layout/layout.jsp file that contains your app's common look and
- feel:
-
-<source><![CDATA[
+ </li>
+ </ol>
+
+ <p>
+ <strong>Note:</strong>
+ If your required form property is one of the Java object
+ representations of
+ primitive types (ie. java.lang.Integer), you must set the
+ ActionServlet's convertNull init.
+ parameter to true. Failing to do this will result in the
+ required validation not being performed
+ on that field because it will default to 0.
+ </p>
+
+ <p>
+ For more about the Struts Validator, see the
+ <a href="http://struts.apache.org/struts-taglib/dev_validator.html">
+ Developers Guide</a>
+ .
+ </p>
+
+ </subsection>
+
+
+ <a name="Tiles"/>
+ <subsection name="3.3.4 Page Composition With Tiles">
+
+ <p>
+ Tiles is a powerful templating library that allows you to
+ construct views
+ by combining various "tiles".
+ Here's a quick setup guide:
+ </p>
+
+ <ol>
+ <li>
+ Create a /layout/layout.jsp file that contains your
+ app's common look and
+ feel:
+
+ <source><![CDATA[
<html>
<body>
<tiles:insert attribute="body"/>
</body>
</html>
]]></source>
- </li>
-
- <li>
- Create your /index.jsp homepage file:
-
-<source><![CDATA[
+ </li>
+
+ <li>
+ Create your /index.jsp homepage file:
+
+ <source><![CDATA[
<h1>This is my homepage</h1>
]]></source>
- </li>
+ </li>
- <li>
- Create a /WEB-INF/tiles-defs.xml file that looks like this:
+ <li>
+ Create a /WEB-INF/tiles-defs.xml file that looks like
+ this:
-<source><![CDATA[
+ <source><![CDATA[
<tiles-definitions>
-<definition
- name="layout"
+<definition
+ name="layout"
path="/layout/layout.jsp">
<put name="body" value=""/>
</definition>
<definition name="homepage" extends="layout">
- <put
- name="body"
+ <put
+ name="body"
value="/index.jsp"/>
</definition>
<tiles-definitions>
]]></source>
- </li>
+ </li>
- <li>
- Setup the TilesPlugin in the struts-config.xml file:
-
-<source><![CDATA[
-<plug-in
+ <li>
+ Setup the TilesPlugin in the struts-config.xml file:
+
+ <source><![CDATA[
+<plug-in
className="org.apache.struts.tiles.TilesPlugin">
- <set-property
- property="definitions-config"
+ <set-property
+ property="definitions-config"
value="/WEB-INF/tiles-defs.xml"/>
</plug-in>
]]></source>
- </li>
-
- <li>
- Setup an action mapping in struts-config.xml to point to your
- homepage tile:
+ </li>
+
+ <li>
+ Setup an action mapping in struts-config.xml to point
+ to your
+ homepage tile:
-<source><![CDATA[
-<action
+ <source><![CDATA[
+<action
path="/index"
type="org.apache.struts.actions.ForwardAction"
parameter="homepage"/>
]]></source>
- </li>
- </ol>
+ </li>
+ </ol>
- <p>
- 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.
- </p>
-
- <p>
- See the <a href="http://struts.apache.org/struts-tiles/">Struts Tiles website</a>
- for in-depth examples.
- </p>
-
- </subsection>
-
-<a name="presentation_frameworks"/>
-<subsection name="3.4 Presentation Frameworks">
- <p>
- The framework is supported by many presentation technologies,
- and there are a great number of extensions that
- make creating view components even easier.
- </p>
-
- Some popular presentation layer technologies include:
- <ul>
- <li>
- <a href="http://struts.apache.org/struts-taglib/">
- Struts Taglibs</a>
- </li>
- <li>
- <a href="http://struts.sourceforge.net/struts-cocoon/">
- Struts Cocoon</a>
- </li>
- <li>
- <a href="http://jakarta.apache.org/velocity/tools/struts/">
- Velocity Struts</a>
- </li>
- <li>
- <a href="http://stxx.sourceforge.net/">Stxx for XLST</a>
- </li>
- </ul>
-</subsection>
-
-<a name="other_presentations"/>
-<subsection name="3.5 Other Presentation Techniques">
-
- <p>
- Although the look and feel of your application can be completely
- constructed based on the standard capabilities of presentation libraries,
- you may need to employ other techniques to render some responses directly.
- </p>
-
-</subsection>
-
- <a name="image_rendering"/>
- <subsection name="3.5.1 Image Rendering Components">
-
- <p>
- 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:
- </p>
-
- <ul>
-
- <li>
- 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
- <code>image/gif</code>), and send back the bytes of that image to the
- browser, which will display them just as if it had received a static
- file.
- </li>
-
- <li>
- 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.
- </li>
-
- </ul>
-
- </subsection>
-
- <a name="text_rendering"/>
- <subsection name="3.5.2 Rendering Text">
-
- <p>
- 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:
- </p>
+ <p>
+ 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.
+ </p>
+
+ <p>
+ See the
+ <a href="http://struts.apache.org/struts-tiles/">Struts
+ Tiles website</a>
+ for in-depth examples.
+ </p>
+
+ </subsection>
+
+ <a name="presentation_frameworks"/>
+ <subsection name="3.4 Presentation Frameworks">
+ <p>
+ The framework is supported by many presentation
+ technologies,
+ and there are a great number of extensions that
+ make creating view components even easier.
+ </p>
+
+ Some popular presentation layer technologies include:
+ <ul>
+ <li>
+ <a href="http://struts.apache.org/struts-taglib/">
+ Struts Taglibs</a>
+ </li>
+ <li>
+ <a href="http://struts.sourceforge.net/struts-cocoon/">
+ Struts Cocoon</a>
+ </li>
+ <li>
+ <a href="http://jakarta.apache.org/velocity/tools/struts/">
+ Velocity Struts</a>
+ </li>
+ <li>
+ <a href="http://stxx.sourceforge.net/">Stxx for
+ XLST</a>
+ </li>
+ </ul>
+ </subsection>
+
+ <a name="other_presentations"/>
+ <subsection name="3.5 Other Presentation Techniques">
+
+ <p>
+ Although the look and feel of your application can be
+ completely
+ constructed based on the standard capabilities of
+ presentation libraries,
+ you may need to employ other techniques to render some
+ responses directly.
+ </p>
+
+ </subsection>
+
+ <a name="image_rendering"/>
+ <subsection name="3.5.1 Image Rendering Components">
+
+ <p>
+ 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:
+ </p>
+
+ <ul>
+
+ <li>
+ 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
+ <code>image/gif</code>
+ ), and send back the bytes of that image to the
+ browser, which will display them just as if it had
+ received a static
+ file.
+ </li>
+
+ <li>
+ 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.
+ </li>
+
+ </ul>
+
+ </subsection>
+
+ <a name="text_rendering"/>
+ <subsection name="3.5.2 Rendering Text">
+
+ <p>
+ 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:
+ </p>
-<source><![CDATA[
+ <source><![CDATA[
response.setContentType("text/plain"); // or text/xml
PrintWriter writer = response.getWriter();
// use writer to render text
return(null);
]]></source>
-</subsection>
+ </subsection>
-</section>
+ </section>
-<section>
- <p class="right">
- Next: <a href="building_controller.html">Building Controller
- Components</a>
- </p>
-</section>
+ <section>
+ <p class="right">
+ Next:
+ <a href="building_controller.html">Building Controller
+ Components</a>
+ </p>
+ </section>
-</body>
+ </body>
</document>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org