~ubuntu-branches/ubuntu/trusty/libstruts1.2-java/trusty-proposed

« back to all changes in this revision

Viewing changes to legacy/api-1.1/org/apache/struts/util/package-summary.html

  • Committer: Bazaar Package Importer
  • Author(s): Arnaud Vandyck
  • Date: 2004-11-19 15:35:25 UTC
  • Revision ID: james.westby@ubuntu.com-20041119153525-mdu08a76z4zo67xt
Tags: upstream-1.2.4
Import upstream version 1.2.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
 
2
<!--NewPage-->
 
3
<HTML>
 
4
<HEAD>
 
5
<!-- Generated by javadoc on Fri Aug 22 03:43:57 EDT 2003 -->
 
6
<TITLE>
 
7
org.apache.struts.util (Apache Struts API Documentation)
 
8
</TITLE>
 
9
<META NAME="keywords" CONTENT="org.apache.struts.util package">
 
10
<LINK REL ="stylesheet" TYPE="text/css" HREF="../../../../stylesheet.css" TITLE="Style">
 
11
</HEAD>
 
12
<SCRIPT>
 
13
function asd()
 
14
{
 
15
parent.document.title="org.apache.struts.util (Apache Struts API Documentation)";
 
16
}
 
17
</SCRIPT>
 
18
<BODY BGCOLOR="white" onload="asd();">
 
19
 
 
20
<!-- ========== START OF NAVBAR ========== -->
 
21
<A NAME="navbar_top"><!-- --></A>
 
22
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
 
23
<TR>
 
24
<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
 
25
<A NAME="navbar_top_firstrow"><!-- --></A>
 
26
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
 
27
  <TR ALIGN="center" VALIGN="top">
 
28
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A>&nbsp;</TD>
 
29
  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Package</B></FONT>&nbsp;</TD>
 
30
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Class</FONT>&nbsp;</TD>
 
31
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-use.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A>&nbsp;</TD>
 
32
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
 
33
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
 
34
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
 
35
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
 
36
  </TR>
 
37
</TABLE>
 
38
</TD>
 
39
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
 
40
</EM>
 
41
</TD>
 
42
</TR>
 
43
 
 
44
<TR>
 
45
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
 
46
&nbsp;<A HREF="../../../../org/apache/struts/upload/package-summary.html"><B>PREV PACKAGE</B></A>&nbsp;
 
47
&nbsp;<A HREF="../../../../org/apache/struts/validator/package-summary.html"><B>NEXT PACKAGE</B></A></FONT></TD>
 
48
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
 
49
  <A HREF="../../../../index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;
 
50
&nbsp;<A HREF="package-summary.html" TARGET="_top"><B>NO FRAMES</B></A>  &nbsp;
 
51
&nbsp;
 
52
<SCRIPT>
 
53
  <!--
 
54
  if(window==top) {
 
55
    document.writeln('<A HREF="../../../../allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
 
56
  }
 
57
  //-->
 
58
</SCRIPT>
 
59
<NOSCRIPT>
 
60
<A HREF="../../../../allclasses-noframe.html" TARGET=""><B>All Classes</B></A>
 
61
</NOSCRIPT>
 
62
</FONT></TD>
 
63
</TR>
 
64
</TABLE>
 
65
<!-- =========== END OF NAVBAR =========== -->
 
66
 
 
67
<HR>
 
68
<H2>
 
69
Package org.apache.struts.util
 
70
</H2>
 
71
The Utilities package provides a variety of families of classes,
 
72
to solve problems that are commonly encountered in building web applications.
 
73
<P>
 
74
<B>See:</B>
 
75
<BR>
 
76
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<A HREF="#package_description"><B>Description</B></A>
 
77
<P>
 
78
 
 
79
<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
 
80
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
 
81
<TD COLSPAN=2><FONT SIZE="+2">
 
82
<B>Class Summary</B></FONT></TD>
 
83
</TR>
 
84
<TR BGCOLOR="white" CLASS="TableRowColor">
 
85
<TD WIDTH="15%"><B><A HREF="ErrorMessages.html">ErrorMessages</A></B></TD>
 
86
<TD><B>Deprecated.</B>&nbsp;<I>Use org.apache.struts.action.ActionErrors instead</I></TD>
 
87
</TR>
 
88
<TR BGCOLOR="white" CLASS="TableRowColor">
 
89
<TD WIDTH="15%"><B><A HREF="GenericDataSource.html">GenericDataSource</A></B></TD>
 
90
<TD><B>Deprecated.</B>&nbsp;<I>Use a <code>BasicDataSource</code> directly, or indirectly
 
91
  acquire a data source provided by your container</I></TD>
 
92
</TR>
 
93
<TR BGCOLOR="white" CLASS="TableRowColor">
 
94
<TD WIDTH="15%"><B><A HREF="ImageButtonBean.html">ImageButtonBean</A></B></TD>
 
95
<TD>A simple JavaBean to encapsulate the request parameters sent for an HTML
 
96
 input element of type image.</TD>
 
97
</TR>
 
98
<TR BGCOLOR="white" CLASS="TableRowColor">
 
99
<TD WIDTH="15%"><B><A HREF="IteratorAdapter.html">IteratorAdapter</A></B></TD>
 
100
<TD><B>Deprecated.</B>&nbsp;<I>Use commons-collections' IteratorUtils.asIterator(Enumeration).</I></TD>
 
101
</TR>
 
102
<TR BGCOLOR="white" CLASS="TableRowColor">
 
103
<TD WIDTH="15%"><B><A HREF="LabelValueBean.html">LabelValueBean</A></B></TD>
 
104
<TD>A simple JavaBean to represent label-value pairs.</TD>
 
105
</TR>
 
106
<TR BGCOLOR="white" CLASS="TableRowColor">
 
107
<TD WIDTH="15%"><B><A HREF="MessageResources.html">MessageResources</A></B></TD>
 
108
<TD>General purpose abstract class that describes an API for retrieving
 
109
 Locale-sensitive messages from underlying resource locations of an
 
110
 unspecified design, and optionally utilizing the <code>MessageFormat</code>
 
111
 class to produce internationalized messages with parametric replacement.</TD>
 
112
</TR>
 
113
<TR BGCOLOR="white" CLASS="TableRowColor">
 
114
<TD WIDTH="15%"><B><A HREF="MessageResourcesFactory.html">MessageResourcesFactory</A></B></TD>
 
115
<TD>Factory for <code>MessageResources</code> instances.</TD>
 
116
</TR>
 
117
<TR BGCOLOR="white" CLASS="TableRowColor">
 
118
<TD WIDTH="15%"><B><A HREF="PropertyMessageResources.html">PropertyMessageResources</A></B></TD>
 
119
<TD>Concrete subclass of <code>MessageResources</code> that reads message keys
 
120
 and corresponding strings from named property resources in the same manner
 
121
 that <code>java.util.PropertyResourceBundle</code> does.</TD>
 
122
</TR>
 
123
<TR BGCOLOR="white" CLASS="TableRowColor">
 
124
<TD WIDTH="15%"><B><A HREF="PropertyMessageResourcesFactory.html">PropertyMessageResourcesFactory</A></B></TD>
 
125
<TD>Factory for <code>PropertyMessageResources</code> instances.</TD>
 
126
</TR>
 
127
<TR BGCOLOR="white" CLASS="TableRowColor">
 
128
<TD WIDTH="15%"><B><A HREF="RequestUtils.html">RequestUtils</A></B></TD>
 
129
<TD>General purpose utility methods related to processing a servlet request
 
130
 in the Struts controller framework.</TD>
 
131
</TR>
 
132
<TR BGCOLOR="white" CLASS="TableRowColor">
 
133
<TD WIDTH="15%"><B><A HREF="ResponseUtils.html">ResponseUtils</A></B></TD>
 
134
<TD>General purpose utility methods related to generating a servlet response
 
135
 in the Struts controller framework.</TD>
 
136
</TR>
 
137
<TR BGCOLOR="white" CLASS="TableRowColor">
 
138
<TD WIDTH="15%"><B><A HREF="ServletContextWriter.html">ServletContextWriter</A></B></TD>
 
139
<TD>A PrintWriter implementation that uses the logging facilities of a
 
140
 <code>javax.servlet.ServletContext</code> to output its results.</TD>
 
141
</TR>
 
142
<TR BGCOLOR="white" CLASS="TableRowColor">
 
143
<TD WIDTH="15%"><B><A HREF="StrutsValidator.html">StrutsValidator</A></B></TD>
 
144
<TD><B>Deprecated.</B>&nbsp;<I>As of Struts 1.1, replaced by    <A HREF="../../../../org/apache/struts/validator/FieldChecks.html"><CODE>FieldChecks</CODE></A></I></TD>
 
145
</TR>
 
146
<TR BGCOLOR="white" CLASS="TableRowColor">
 
147
<TD WIDTH="15%"><B><A HREF="StrutsValidatorUtil.html">StrutsValidatorUtil</A></B></TD>
 
148
<TD><B>Deprecated.</B>&nbsp;<I>As of Struts 1.1, replaced by <A HREF="../../../../org/apache/struts/validator/Resources.html"><CODE>Resources</CODE></A></I></TD>
 
149
</TR>
 
150
<TR BGCOLOR="white" CLASS="TableRowColor">
 
151
<TD WIDTH="15%"><B><A HREF="TokenProcessor.html">TokenProcessor</A></B></TD>
 
152
<TD>TokenProcessor is responsible for handling all token related functionality.</TD>
 
153
</TR>
 
154
</TABLE>
 
155
&nbsp;
 
156
 
 
157
<P>
 
158
 
 
159
<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
 
160
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
 
161
<TD COLSPAN=2><FONT SIZE="+2">
 
162
<B>Exception Summary</B></FONT></TD>
 
163
</TR>
 
164
<TR BGCOLOR="white" CLASS="TableRowColor">
 
165
<TD WIDTH="15%"><B><A HREF="AppException.html">AppException</A></B></TD>
 
166
<TD><B>Deprecated.</B>&nbsp;<I>use <A HREF="../../../../org/apache/struts/util/ModuleException.html"><CODE>ModuleException</CODE></A></I></TD>
 
167
</TR>
 
168
<TR BGCOLOR="white" CLASS="TableRowColor">
 
169
<TD WIDTH="15%"><B><A HREF="ModuleException.html">ModuleException</A></B></TD>
 
170
<TD>Used for specialized exception handling.</TD>
 
171
</TR>
 
172
</TABLE>
 
173
&nbsp;
 
174
 
 
175
<P>
 
176
<A NAME="package_description"><!-- --></A><H2>
 
177
Package org.apache.struts.util Description
 
178
</H2>
 
179
 
 
180
<P>
 
181
The Utilities package provides a variety of families of classes,
 
182
to solve problems that are commonly encountered in building web applications.
 
183
<br><br>
 
184
<a name="doc.Description"></a>
 
185
<div align="center">
 
186
<a href="#doc.Intro">[Introduction]</a>
 
187
<a href="#doc.Beans">[Beans]</a>
 
188
<a href="#doc.Utilities">[Servlet Utilities]</a>
 
189
<a href="#doc.Messages">[Message Resources]</a>
 
190
</div>
 
191
 
 
192
<hr>
 
193
 
 
194
<a name="doc.Intro"></a>
 
195
<h3>Introduction</h3>
 
196
 
 
197
<p>The Struts Utilities Package offers several families
 
198
of classes that assist in solving commonly encountered problems when building
 
199
web applications.  Most of the classes in this package do not rely on the
 
200
controller servlet framework, or the custom tag libraries, so they are also
 
201
suitable for general Java application programming.  The following families
 
202
are included:</p>
 
203
<ul>
 
204
<li><a href="#doc.Beans">Beans</a> - A small set of utility beans useful for 
 
205
    encapsulating form elements.</li>
 
206
<li><a href="#doc.Utilities">Servlet Utilities</a> - A set of classes useful
 
207
    for working with servlet-related classes.</li>
 
208
<li><a href="#doc.Messages">Message Resources</a> - A family of classes that
 
209
    features access to internationalized message strings based on a message
 
210
    key coupled with a <code>java.util.Locale</code> object representing a
 
211
    particular user's preferred language.</li>
 
212
</ul>
 
213
 
 
214
<hr>
 
215
 
 
216
<a name="doc.Beans"></a>
 
217
<h3>Beans</h3>
 
218
 
 
219
<p> The <code>ImageButtonBean</code> is a simple JavaBean to encapsulate the 
 
220
    request parameters sent for an HTML input element of type image. The 
 
221
    <code>LabelValueBean</code> is a simple JavaBean to represent label-value 
 
222
    pairs, especially useful for html option elements.
 
223
</p>
 
224
 
 
225
<hr>
 
226
 
 
227
<a name="doc.Utilities"></a>
 
228
<h3>Servlet Utilities</h3>
 
229
 
 
230
<p> The <code>RequestUtils</code> is a general purpose utility methods 
 
231
    related to processing a servlet request. The <code>ResponseUtils</code>
 
232
    is a general purpose utility methods related to generating a servlet 
 
233
    response. The <code>ServletContextWriter</code> is a PrintWriter 
 
234
    implementation that uses the logging facilities of a 
 
235
    <code>javax.servlet.ServletContext</code> to output its results.
 
236
</p>
 
237
 
 
238
<hr>
 
239
 
 
240
<a name="doc.Messages"></a>
 
241
<h3>Message Resources</h3>
 
242
 
 
243
<h5>Background</h5>
 
244
 
 
245
<p>Modern applications often include the requirement to support multiple
 
246
languages, for users who prefer to interact in a language other than the
 
247
default language configured on the server platform.  In addition, sentences
 
248
often need to be constructed, with dynamic content whose placement in the
 
249
message depends on the standard sentence structure in that particular
 
250
language.</p>
 
251
 
 
252
<p>The standard Java platform includes a family of classes
 
253
(<code>java.util.ResourceBundle</code>) designed to support looking up message
 
254
strings based on a standard "key".  The resource bundle classes automatically
 
255
access a Java class (or properties file) that is named with a naming
 
256
convention that includes the Locale to which messages in that class (or file)
 
257
pertain.  However, this selection is based only on the default Locale of the
 
258
server platform, and cannot be adjusted on a per-user basis as required for an
 
259
internationalized web application.</p>
 
260
 
 
261
<p>Struts includes a family of classes
 
262
(<code>org.apache.struts.util.MessageResources</code>) that extends the basic
 
263
approach to looking up message strings by key, allowing you to optionally
 
264
specify a Locale along with the key.  In this way, you can build applications
 
265
that let your users select which Locale they wish to operate within, and then
 
266
look up messages in that language - using the same message keys no matter what
 
267
language is selected.</p>
 
268
 
 
269
<p>In addition to supporting dynamic selection of a Locale for message lookup,
 
270
the <code>MessageResources</code> family of classes optionally allow you to
 
271
specify up to four parameter replacement objects, which are used to replace the
 
272
parameter placeholders "{0}" through "{3}" in the retrieved message.  This
 
273
replacement uses the facilities of the standard Java
 
274
<code>java.text.MessageFormat</code> class, which supports many extended
 
275
formatting capabilities as well.</p>
 
276
 
 
277
<p>For more information about internationalized messages, consult the following
 
278
resources in your Java Development Kit documentation bundle:</p>
 
279
<ul>
 
280
<li><em>Internationalization Info</em> - General information on Java's standard
 
281
    support for internationalized applications can be found at
 
282
    <code>&lt;$JAVA_HOME/docs/guide/internat/index.html&gt;</code>.
 
283
    The "Internationalization Overview" section includes useful information
 
284
    about Locales, localized resources, message formatting, and other
 
285
    relevant topics.</li>
 
286
<li><em>Internationalization Tutorial</em> - The Java Language Tutorial has a
 
287
    comprehensive trail covering internationalization, available at:
 
288
    <a href="http://java.sun.com/docs/books/tutorial/i18n/index.html">
 
289
    http://java.sun.com/docs/books/tutorial/i18n/index.html</a>.</li>
 
290
<li><em>Javadoc APIs</em> - You will want to consult the Javadoc API
 
291
    documentation for the following standard Java classes:
 
292
    <ul>
 
293
    <li><code>java.text.MessageFormat</code>
 
294
    <li><code>java.util.ResourceBundle</code>
 
295
    <li><code>java.util.PropertyResourceBundle</code>
 
296
    <li><code>java.util.Properties</code> - See the documentation for the
 
297
        <code>load()</code> method for the valid syntax of properties files
 
298
        that you prepare.</li>
 
299
    </ul></li>
 
300
</ul>
 
301
 
 
302
<h5>Using the Standard MessageResources Implementation</h5>
 
303
 
 
304
<p>The standard <code>MessageResources</code> implementation provided by the
 
305
Struts library uses Java properties files to initialize message strings, in a
 
306
manner very similar to that supported by the
 
307
<code>java.util.PropertyResourceBundle</code> class.  The following steps are
 
308
required to use these facilities in your Java application.</p>
 
309
 
 
310
<p>First, prepare a Java properties file for each language (or Locale) in which
 
311
you wish to support your messages.  The filenames you use must conform to the
 
312
naming convention for property resource bundles, as described in the
 
313
documentation referenced above.  Be sure you use the same message keys in each
 
314
file to identify the same message.</p>
 
315
 
 
316
<p>For example, you might prepare files in French, Spanish, and English that
 
317
contain language-specific versions of the word "Hello".  The French file would
 
318
be named <code>Messages_fr.properties</code> and contain the following:</p>
 
319
<pre>
 
320
    hi=Bonjour
 
321
</pre>
 
322
<p>while the Spanish and English files would be named
 
323
<code>Messages_es.properties</code> and <code>Messages_en.properties</code>
 
324
respectively.  The corresponding message string definitions would say
 
325
<code>hi=Hola</code> and <code>hi=Hello</code> in these files.</p>
 
326
 
 
327
<p>Second, place these properties files into the class path for your
 
328
application, exactly as you would with class files themselves.  The name
 
329
actually used to load resources will look like a fully qualified Java class
 
330
name (with appropriate package prefixes), so the file should be nested inside
 
331
a directory structure that matches the packaging (either in an unpacked
 
332
directory, or within a JAR file, as appropriate).  For example, assume you
 
333
place directory "foo" on your classpath, and stored the above properties files
 
334
in directory "foo/com/mycompany/mypackage".  (If you were using a JAR file like
 
335
"foo.jar" instead, the files would be in directory "com/mycompany/mypackage"
 
336
within the JAR file).
 
337
 
 
338
<p>Third, initialize a <code>MessageResources</code> object that corresponds
 
339
to the set of properties files for a particular name, within a particular
 
340
package.  The easiest way to do this is to initialize a variable in your main
 
341
application class, like this:</p>
 
342
<pre>
 
343
    public static MessageResources messages =
 
344
     MessageResources.getMessageResources("com.mycompany.mypackage.Messages");
 
345
</pre>
 
346
 
 
347
<p>Note that the "com.mycompany.mypackage" part of the name matches the package
 
348
directory into which you placed your properties files, and "Messages" is the
 
349
filename prefix for the particular family of properties files supported by this
 
350
<code>MessageResources</code> instance.  Depending on your development process,
 
351
you might find it convenient to store all message strings for an entire
 
352
application in a single properties file family, or to have several families -
 
353
in Struts, for example, there is a family of properties files for each Java
 
354
package.</p>
 
355
 
 
356
<p>To access a message string with a particular Locale, execute a statement
 
357
like this:</p>
 
358
<pre>
 
359
    Locale locale = ... select the locale to be used ...
 
360
    String message = messages.getMessage(locale, "hi");
 
361
</pre>
 
362
 
 
363
<p>In this case, the variable <code>message</code> will contain the message
 
364
string corresponding to the key "hi", in the language that corresponds to the
 
365
locale that was selected.</p>
 
366
 
 
367
<p>For an example of message formatting with replaceable parameters, assume
 
368
that the message strings looked like this, instead (only the English version
 
369
is shown - corresponding changes would be made in the other files):</p>
 
370
<pre>
 
371
    hi=Hello {0}
 
372
</pre>
 
373
 
 
374
<p>Now, you can personalize the retrieved message like this:</p>
 
375
<pre>
 
376
    Locale locale = ... select the locale to be used ...
 
377
    String name = "Joe";
 
378
    String message = messages.getMessage(locale, "hi", name);
 
379
</pre>
 
380
 
 
381
<p>and the marker "{0}" will have been replaced by the specified name (Joe),
 
382
no matter which language is in use.  See the JavaDoc API documentation for the
 
383
<code>java.text.MessageFormat</code> class for more advanced uses of the
 
384
parameter replacement mechanism.</p>
 
385
 
 
386
<h5>Developing Your Own MessageResources Implementation</h5>
 
387
 
 
388
<p>In the above example, we were using the default
 
389
<code>MessageResources</code> implementation supplied by Struts, which uses
 
390
property files to store the message strings.  It is also possible to create
 
391
customized mechanisms to retrieve messages (such as loading them on demand
 
392
from a database).  The steps required are as follows:</p>
 
393
<ul>
 
394
<li>Create a customized subclass of
 
395
    <code>org.apache.struts.util.MessageResources</code> that implements
 
396
    message lookup operations as you require.</li>
 
397
<li>Create a customized subclass of
 
398
    <code>org.apache.struts.util.MessageResourcesFactory</code> that will
 
399
    create an instance of your custom <code>MessageResources</code> class
 
400
    when the <code>createResources</code> method is called.  Note that the
 
401
    "config" argument to this method can be used to select families of
 
402
    messages in any manner appropriate to your needs - you are not required
 
403
    to emulate the "fully qualified Java class name" approach that is used
 
404
    by the standard <code>PropertyMessageResourcesFactory</code> class.</li>
 
405
<li>Tell the <code>MessageResourcesFactory</code> class the name of the
 
406
    customized <code>MessageResourcesFactory</code> implementation to use
 
407
    when creating new factory instances.</li>
 
408
<li>Create a new factory instance.</li>
 
409
<li>Ask the new factory instance to create a <code>MessageResources</code>
 
410
    instance for you.</li>
 
411
</ul>
 
412
 
 
413
<p>A code example that illustrates this technique is:</p>
 
414
<pre>
 
415
    MessageResourcesFactory.setFactoryClass("com.mycompany.mypkg.MyFactory");
 
416
    MessageResourcesFactory factory = MessageResourcesFactory.createFactory();
 
417
    MessageResources resources =
 
418
     factory.createResources("configuration information");
 
419
</pre>
 
420
 
 
421
<p>Once you have created your custom MessageResources instance, you utilize it
 
422
to access message strings (with or without parameter replacement objects),
 
423
exactly as we illustrated with the standard implementation in the previous
 
424
section.</p>
 
425
 
 
426
<h5>Using MessageResources With Struts</h5>
 
427
 
 
428
<p>If your application uses the Struts controller servlet, you can optionally
 
429
configure Struts to load an application-specific message resources instance for
 
430
you, and make it available as a servlet context attribute (in JSP terms, an
 
431
application-scope bean).  This mechanism is managed by setting the following
 
432
servlet initialization parameters in the web application deployment descriptor:
 
433
</p>
 
434
<ul>
 
435
<li><strong>application</strong> - The configuration string that will be
 
436
    passed to the <code>createResources()</code> method of the message
 
437
    resources factory, in order to identify the family of resources to be
 
438
    supported.  If you use the standard message resources factory, this must
 
439
    be the base fully qualified name of the property resources files used
 
440
    to contain these messages, as illustrated above.</li>
 
441
<li><strong>factory</strong> - Fully qualified Java class name of the
 
442
    <code>MessageResourcesFactory</code> to be used.  By default, the standard
 
443
    implementation provided by Struts
 
444
    (<code>org.apache.struts.util.PropertyMessageResourcesFactory</code>)
 
445
    will be used.</li>
 
446
</ul>
 
447
 
 
448
<p>Struts provides several JSP custom tags that assume the existence of a
 
449
<code>java.util.Locale</code> attribute in the user's session, under the key
 
450
named by the constant string value of <code>Action.LOCALE_KEY</code>.  Your own
 
451
application logic can set this attribute at any time, or you can ask Struts to
 
452
set it automatically (if not already set) based on the
 
453
<code>Accept-Language</code> HTTP header included with the request.  There are
 
454
two mechanisms by which you request Struts to perform this service:</p>
 
455
<ul>
 
456
<li>To have this service performed on every request submitted to the controller
 
457
    servlet, set the servlet initialization parameter <code>locale</code> to
 
458
    the value <code>true</code> in the application deployment descriptor.</li>
 
459
<li>To have this service performed by a JSP page when it is accessed directly
 
460
    by a user, utilize a <code>&lt;form:html ... locale="true" ... /&gt;</code>
 
461
    tag at the top of each page.</li>
 
462
</ul>
 
463
<P>
 
464
 
 
465
<P>
 
466
<HR>
 
467
 
 
468
<!-- ========== START OF NAVBAR ========== -->
 
469
<A NAME="navbar_bottom"><!-- --></A>
 
470
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
 
471
<TR>
 
472
<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
 
473
<A NAME="navbar_bottom_firstrow"><!-- --></A>
 
474
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
 
475
  <TR ALIGN="center" VALIGN="top">
 
476
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A>&nbsp;</TD>
 
477
  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Package</B></FONT>&nbsp;</TD>
 
478
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Class</FONT>&nbsp;</TD>
 
479
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-use.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A>&nbsp;</TD>
 
480
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
 
481
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
 
482
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
 
483
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
 
484
  </TR>
 
485
</TABLE>
 
486
</TD>
 
487
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
 
488
</EM>
 
489
</TD>
 
490
</TR>
 
491
 
 
492
<TR>
 
493
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
 
494
&nbsp;<A HREF="../../../../org/apache/struts/upload/package-summary.html"><B>PREV PACKAGE</B></A>&nbsp;
 
495
&nbsp;<A HREF="../../../../org/apache/struts/validator/package-summary.html"><B>NEXT PACKAGE</B></A></FONT></TD>
 
496
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
 
497
  <A HREF="../../../../index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;
 
498
&nbsp;<A HREF="package-summary.html" TARGET="_top"><B>NO FRAMES</B></A>  &nbsp;
 
499
&nbsp;
 
500
<SCRIPT>
 
501
  <!--
 
502
  if(window==top) {
 
503
    document.writeln('<A HREF="../../../../allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
 
504
  }
 
505
  //-->
 
506
</SCRIPT>
 
507
<NOSCRIPT>
 
508
<A HREF="../../../../allclasses-noframe.html" TARGET=""><B>All Classes</B></A>
 
509
</NOSCRIPT>
 
510
</FONT></TD>
 
511
</TR>
 
512
</TABLE>
 
513
<!-- =========== END OF NAVBAR =========== -->
 
514
 
 
515
<HR>
 
516
Copyright � 2000-2003 - Apache Software Foundation
 
517
</BODY>
 
518
</HTML>