blob: 30790352f9a96ec7c49787d05d76475f9b2b8804 [file] [log] [blame]
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>3.4.&nbsp;Message Properties</title><link rel="stylesheet" href="css/stylesheet.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.75.0"><link rel="home" href="index.html" title="Apache Click"><link rel="up" href="ch03.html" title="Chapter&nbsp;3.&nbsp;Controls"><link rel="prev" href="ch03s03.html" title="3.3.&nbsp;Control Classes"><link rel="next" href="ch03s05.html" title="3.5.&nbsp;Control HEAD Elements"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">3.4.&nbsp;Message Properties</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch03s03.html">Prev</a>&nbsp;</td><th width="60%" align="center">Chapter&nbsp;3.&nbsp;Controls</th><td width="20%" align="right">&nbsp;<a accesskey="n" href="ch03s05.html">Next</a></td></tr></table><hr></div><div class="sect1" title="3.4.&nbsp;Message Properties"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="control-message-properties"></a>3.4.&nbsp;Message Properties</h2></div></div></div><p>Control strings for field validation messages and HTML formatting
strings are externalized in the properties file. By using these properties
files you can localize a Click application for your particular language and
dialect.
</p><div class="sect2" title="3.4.1.&nbsp;Message Resolution"><div class="titlepage"><div><div><h3 class="title"><a name="message-resolution"></a>3.4.1.&nbsp;Message Resolution</h3></div></div></div><p>Messages are looked up in a particular order enabling taylor specific
messages, for your controls, individual pages or across your entire
application. The order in which localized messages are resolved is:
</p><div class="variablelist"><dl><dt><span class="term"><span class="bold"><strong>Page scope messages</strong></span></span></dt><dd><p>Message lookups are first resolved to the Page classes message
bundle if it exists. For example a <code class="classname">Login</code> page
may define the message properties:
</p><div class="literallayout"><p>/com/mycorp/page/Login.properties</p></div><p>If you want to tailor messages for a particular page this is
where to place them.
</p></dd><dt><span class="term"><span class="bold"><strong>Global page scope messages</strong></span></span></dt><dd><p>Next message lookups are resolved to the global pages message
bundle if it exists.
</p><div class="literallayout"><p>/click-page.properties</p></div><p>If you want messages to be used across your entire application
this is where to place them.
</p></dd><dt><span class="term"><span class="bold"><strong>Control scope messages</strong></span></span></dt><dd><p>Next message lookups are resolved to the Control classes
message bundle if it exists. For example a
<code class="classname">CustomTextField</code> control may define the
message properties:
</p><div class="literallayout"><p>/com/mycorp/control/CustomTextField.properties</p></div><p>A custom control's messages can be placed here
(or the global control scope covered next) and overridden by one of the
above options.
</p></dd><dt><span class="term"><span class="bold"><strong>Global control scope messages</strong></span></span></dt><dd><p>Finally message lookups are resolved to the global application
control message bundle if the message has not already been found.
The global control properties file is:
</p><div class="literallayout"><p>/click-control.properties</p></div><p>Control messages can be placed here and overridden by one of
the above options.
</p></dd></dl></div></div><div class="sect2" title="3.4.2.&nbsp;Control Properties"><div class="titlepage"><div><div><h3 class="title"><a name="control-properties"></a>3.4.2.&nbsp;Control Properties</h3></div></div></div><p>To customize the <code class="filename">click-control.properties</code> simply
add this file to your classpath and tailor the specific values.
</p><p>Note when customizing the message properties you must include all
the properties, not just the ones you want to override.
</p><div class="literallayout"><p>#&nbsp;Click&nbsp;Control&nbsp;messages<br>
field-maxlength-error={0}&nbsp;must&nbsp;be&nbsp;no&nbsp;longer&nbsp;than&nbsp;{1}&nbsp;characers<br>
field-minlength-error={0}&nbsp;must&nbsp;be&nbsp;at&nbsp;least&nbsp;{1}&nbsp;characters<br>
field-required-error=You&nbsp;must&nbsp;enter&nbsp;a&nbsp;value&nbsp;for&nbsp;{0}<br>
<br>
file-required-error=You&nbsp;must&nbsp;enter&nbsp;a&nbsp;filename&nbsp;for&nbsp;{0}<br>
<br>
label-required-prefix=<br>
label-required-suffix=&lt;span&nbsp;class="required"&gt;*&lt;/span&gt;<br>
label-not-required-prefix=<br>
label-not-required-suffix=&amp;nbsp;<br>
<br>
not-checked-error=You&nbsp;must&nbsp;select&nbsp;{0}<br>
<br>
number-maxvalue-error={0}&nbsp;must&nbsp;not&nbsp;be&nbsp;larger&nbsp;than&nbsp;{1}<br>
number-minvalue-error={0}&nbsp;must&nbsp;not&nbsp;be&nbsp;smaller&nbsp;than&nbsp;{1}<br>
<br>
select-error=You&nbsp;must&nbsp;select&nbsp;a&nbsp;value&nbsp;for&nbsp;{0}<br>
<br>
table-first-label=First<br>
table-first-title=Go&nbsp;to&nbsp;first&nbsp;page<br>
table-previous-label=Prev<br>
table-previous-title=Go&nbsp;to&nbsp;previous&nbsp;page<br>
table-next-label=Next<br>
table-next-title=Go&nbsp;to&nbsp;next&nbsp;page<br>
table-last-label=Last<br>
table-last-title=Go&nbsp;to&nbsp;last&nbsp;page<br>
table-goto-title=Go&nbsp;to&nbsp;page<br>
table-page-banner=&lt;span&nbsp;class="pagebanner"&gt;{0}&nbsp;items&nbsp;found,&nbsp;displaying&nbsp;{1}&nbsp;to&nbsp;{2}.&lt;/span&gt;<br>
table-page-banner-nolinks=<br>
&nbsp;&nbsp;&lt;span&nbsp;class="pagebanner-nolinks"&gt;{0}&nbsp;items&nbsp;found,&nbsp;displaying&nbsp;{1}&nbsp;to&nbsp;{2}.&lt;/span&gt;<br>
table-page-links=&lt;span&nbsp;class="pagelinks"&gt;[{0}/{1}]&nbsp;{2}&nbsp;[{3}/{4}]&lt;/span&gt;<br>
table-page-links-nobanner=&lt;span&nbsp;class="pagelinks-nobanner"&gt;[{0}/{1}]&nbsp;{2}&nbsp;[{3}/{4}]&lt;/span&gt;<br>
table-no-rows-found=No&nbsp;records&nbsp;found.<br>
<br>
table-inline-first-image=/click/paging-first.gif<br>
table-inline-first-disabled-image=/click/paging-first-disabled.gif<br>
table-inline-previous-image=/click/paging-prev.gif<br>
table-inline-previous-disabled-image=/click/paging-prev-disabled.gif<br>
table-inline-next-image=/click/paging-next.gif<br>
table-inline-next-disabled-image=/click/paging-next-disabled.gif<br>
table-inline-last-image=/click/paging-last.gif<br>
table-inline-last-disabled-image=/click/paging-last-disabled.gif<br>
table-inline-page-links=Page&nbsp;&nbsp;&nbsp;{0}&nbsp;{1}&nbsp;{2}&nbsp;{3}&nbsp;{4}<br>
<br>
#&nbsp;Message&nbsp;displayed&nbsp;when&nbsp;a&nbsp;error&nbsp;occurs&nbsp;when&nbsp;the&nbsp;application&nbsp;is&nbsp;in&nbsp;"production"&nbsp;mode<br>
production-error-message=<br>
&nbsp;&nbsp;&lt;div&nbsp;id='errorReport'&nbsp;class='errorReport'&gt;The&nbsp;application&nbsp;encountered&nbsp;an&nbsp;unexpected&nbsp;error.<br>
&nbsp;&nbsp;&lt;/div&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p></div></div><div class="sect2" title="3.4.3.&nbsp;Accessing Messages"><div class="titlepage"><div><div><h3 class="title"><a name="accessing-messages"></a>3.4.3.&nbsp;Accessing Messages</h3></div></div></div><p>Field classes support a hierarchy of resource bundles for displaying
validation error messages and display messages. These localized messages
can be accessed through the Field methods:
</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p>
<a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="../../click-api/org/apache/click/control/AbstractControl.html#getMessage(java.lang.String)" target="_blank">getMessage(String)</a>
</p></li><li class="listitem"><p>
<a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="../../click-api/org/apache/click/control/AbstractControl.html#getMessage(java.lang.String,%20java.lang.Object)" target="_blank">getMessage(String, Object)</a>
</p></li><li class="listitem"><p>
<a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="../../click-api/org/apache/click/control/AbstractControl.html#getMessage(java.lang.String,%20java.lang.Object[])" target="_blank">getMessage(String, Object[])</a>
</p></li><li class="listitem"><p>
<a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="../../click-api/org/apache/click/control/AbstractControl.html#getMessages()" target="_blank">getMessages()</a>
</p></li><li class="listitem"><p>
<a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="../../click-api/org/apache/click/control/Field.html#setErrorMessage(java.lang.String)" target="_blank">setErrorMessage(String)</a>
</p></li><li class="listitem"><p>
<a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="../../click-api/org/apache/click/control/Field.html#setErrorMessage(java.lang.String,%20java.lang.Object)" target="_blank">setErrorMessage(String, Object)</a>
</p></li></ul></div><p>These methods use the <code class="literal">Locale</code> of the request to
lookup the string resource bundle, and use <code class="classname">MessageFormat</code>
for any string formatting.
</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch03s03.html">Prev</a>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="ch03.html">Up</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="ch03s05.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">3.3.&nbsp;Control Classes&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">&nbsp;3.5.&nbsp;Control HEAD Elements</td></tr></table></div></body></html>