bean:message

 < Day Day Up > 



<bean:message />

The <bean:message /> tag is a very useful tag that we can employ to retrieve keyed values from a previously defined resource bundle. It also supports the ability to include parameters that can be substituted for defined placeholders in the retrieved string. The <bean:message /> tag has no body and supports 11 attributes, described in Table 20.5.

Table 20.5: <bean:message /> Tag Attributes

Attribute

Description

arg0

Contains the first parametric replacement value. (Optional)

arg1

Contains the second parametric replacement value. (Optional)

arg2

Contains the third parametric replacement value. (Optional)

arg3

Contains the fourth parametric replacement value. (Optional)

arg4

Contains the fifth parametric replacement value. (Optional)

bundle

Specifies the name of the bean under which messages are stored. This bean is stored in the ServletContext. If the bundle is not included, the default value of the Action.MESSAGES_KEY is used. This attribute is an optional request-time attribute. If you use the ActionServlet to manage your resource bundles, you can ignore this attribute. (Optional)

key

Identifies the unique key that is used to retrieve a message from a previously defined resource bundle. (Optional)

locale

Specifies the session bean that references the requesting client's locale. If the bundle is not included, the default value of Action.LOCALE_KEY is used. (Optional)

name

Specifies the name of the object whose data member is being retrieved. If the property attribute is not specified, then the value of this bean itself will be used as the message resource key. (Optional)

property

Specifies the name of the property to be accessed on the bean identified by the name attribute. If this attribute is not specified, then the value of the bean identified by the name attribute will be used as the message resource key. (Optional)

scope

Identifies the scope of the bean specified by name attribute. If the scope attribute is not specified, then the tag will search for the bean in the scopes, in the order of page, request, session, and application. (Optional)

start sidebar

We used this tag throughout Chapter 9, "Internationalizing Your Struts Applications."

end sidebar

The following code snippet contains a simple example of using the <bean:message /> tag:

 <html>   <head>     <title><bean:message key="app.title"/></title>   </head>   <body>   </body> </html> 

In this example, we are retrieving the value stored in the resource bundle that is referenced by the key app.title. This retrieved value will be substituted for the occurrence of this <bean:message /> tag. The result is a JSP that will have an HTML <title> that matches the locale of the requesting client.



 < Day Day Up > 



Professional Jakarta Struts
Professional Jakarta Struts (Programmer to Programmer)
ISBN: 0764544373
EAN: 2147483647
Year: 2003
Pages: 183

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net