|
|||
TAG LIBRARIES: <netui> | <netui-data> | <netui-template> | |||
DETAIL: Syntax | Description | Attributes | Example | Implementing Class: org.apache.beehive.netui.tags.databinding.bundle.DeclareBundle |
Declares a java.util.ResourceBundle as a source for displaying internationalized messages.
Syntax |
<netui-data:declareBundle
bundlePath="bundlePath"
[country="country"]
[language="language"]
name="name"
[variant="variant"] />
Description |
Declares a
java.util.ResourceBundle
as a source for displaying internationalized messages.
The declared resource bundle is accessible
using the {bundle...}
data binding context.
The required name
attribute specifies
the identifier used to refer to the ResourceBundle in an expression. For example:
<netui-data:declareBundle name="someMessages" bundlePath="com/foobar/resources/WebAppMessages"/>
This tag declares a bundle that is referenced in a data binding expression as
{bundle.someMessages}
.
The bundle that is referenced depends on the java.util.Locale
specified. The resource bundle properties files that are accessed are located
in the package com/foobar/resources
with the root properties file
name of WebAppMessages
. The naming conventions for properties can
be found in Sun's Java documentation at ResourceBundle.getBundle(String,
Locale, ClassLoader) . These files must be located in a classpath that is
available to the web application. Often, they are stored in WEB-INF/classes
.
If the properties file contains a key called helloWorld
, then the
expression {bundle.someMessages.helloWorld}
would look-up the message
matching the Locale specified on the tag. Bundle binding expressions can be
used in any data bindable <netui...> tag attribute.
It is possible to have keys that contain multiple words separated by spaces,
commas, or periods. If this is the case, then you must use slightly different
syntax to reference those keys in your data binding statement. The following
list illustrates three ways to access the key My helloWorld
from the someMessages
property file:
<netui:label value="{bundle.someMessages['My helloWorld']}"/>
<netui:label value='{bundle.someMessages["My helloWorld"]}'/>
<netui:label value="{bundle.someMessages[\"My helloWorld\"]}"/>
WebLogic Workshop automatically generates the last example listed above when
you set the label control in the property editor to bundle.someMessages["My
helloWorld"]
. In all three cases, you WebLogic Workshop can successfully
retrieve the multi-word key.
Note: the name default
is a bundle identifier that is reserved for use by the
<netui-data:declareBundle> tag. If this value is used for the name
attribute on a
<netui-data:declareBundle> tag,
an error will be reported in the page. The default
bundle is reserved for use when
accessing internationalized messages from the "current" Struts module's default properties file.
This tag provides a high level of customizability for rendering internationalized messages.
Specifically, the Locale for which to look-up messages can be specified on the
<netui-data:declareBundle>
tag. By default, the Locale for the current request is used, but this Locale can be overridden by
setting the language
, country
, and variant
tag attributes
as necessary. See java.util.Locale for more information on the possible values for these attributes.
The Locale can be overridden by setting these attributes in three combinations:
- country, language, variant
- country, language
- country
Any other combinations will throw an exception.
The <netui-data:declareBundle> tag and the Struts <i18n:getMessage> tags have the following differences. The <netui-data:declareBundle> tag lets you customize the use of a particular resource bundle with attributes to set the country, language, and variant explicitly, but it does not write a message out to the JSP page. Writing out a message from this bundle is done inside of any of the other tags using the {bundle...} data binding context.
<netui:label value="{bundle.messages.messageKey}"/>
The Struts <i18n:getMessage> tag is used to access a bundle and write the message out. It is roughly equivalent to doing the following:
<netui-data:declareBundle bundlePath="com/foobar/resources/messages" name="messages"/> <netui:label value="{bundle.messages.messageKey"/>
An advantage of using the {bundle...} data binding context, is that it lets you write into the <span>...</span> that the <netui:label> creates, or into a <neuti:checkBox> name, etc. just like using a regular String.
Attributes | |||||||
bundlePath |
These are treated as equivalent values. The
ResourceBundle
class
will handle appending the |
||||||
country |
|
||||||
language |
|
||||||
name |
default is an illegal value for this attribute and is reserved for use by this tag. |
||||||
variant |
|
|
|||
TAG LIBRARIES: <netui> | <netui-data> | <netui-template> | |||
DETAIL: Syntax | Description | Attributes | Example | Implementing Class: org.apache.beehive.netui.tags.databinding.bundle.DeclareBundle |