blob: 9d17a56c9384386d00abba804e2d7415c4ac2681 [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<!--NewPage-->
<HTML>
<HEAD>
<!-- Generated by javadoc on Fri Aug 22 03:43:54 EDT 2003 -->
<TITLE>
org.apache.struts.taglib.html (Apache Struts API Documentation)
</TITLE>
<META NAME="keywords" CONTENT="org.apache.struts.taglib.html package">
<LINK REL ="stylesheet" TYPE="text/css" HREF="../../../../../stylesheet.css" TITLE="Style">
</HEAD>
<SCRIPT>
function asd()
{
parent.document.title="org.apache.struts.taglib.html (Apache Struts API Documentation)";
}
</SCRIPT>
<BODY BGCOLOR="white" onload="asd();">
<!-- ========== START OF NAVBAR ========== -->
<A NAME="navbar_top"><!-- --></A>
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
<TR>
<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
<A NAME="navbar_top_firstrow"><!-- --></A>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
<TR ALIGN="center" VALIGN="top">
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Package</B></FONT>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <FONT CLASS="NavBarFont1">Class</FONT>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-use.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
</TR>
</TABLE>
</TD>
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
</EM>
</TD>
</TR>
<TR>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
&nbsp;<A HREF="../../../../../org/apache/struts/taglib/bean/package-summary.html"><B>PREV PACKAGE</B></A>&nbsp;
&nbsp;<A HREF="../../../../../org/apache/struts/taglib/logic/package-summary.html"><B>NEXT PACKAGE</B></A></FONT></TD>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../../../../index.html" TARGET="_top"><B>FRAMES</B></A> &nbsp;
&nbsp;<A HREF="package-summary.html" TARGET="_top"><B>NO FRAMES</B></A> &nbsp;
&nbsp;
<SCRIPT>
<!--
if(window==top) {
document.writeln('<A HREF="../../../../../allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
}
//-->
</SCRIPT>
<NOSCRIPT>
<A HREF="../../../../../allclasses-noframe.html" TARGET=""><B>All Classes</B></A>
</NOSCRIPT>
</FONT></TD>
</TR>
</TABLE>
<!-- =========== END OF NAVBAR =========== -->
<HR>
<H2>
Package org.apache.struts.taglib.html
</H2>
<a name="doc.Description">The "struts-html" tag library</a>
contains JSP custom tags useful in creating dynamic HTML user interfaces,
including input forms.
<P>
<B>See:</B>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<A HREF="#package_description"><B>Description</B></A>
<P>
<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TD COLSPAN=2><FONT SIZE="+2">
<B>Class Summary</B></FONT></TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="BaseFieldTag.html">BaseFieldTag</A></B></TD>
<TD>Convenience base class for the various input tags for text fields.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="BaseHandlerTag.html">BaseHandlerTag</A></B></TD>
<TD>Base class for tags that render form elements capable of including JavaScript
event handlers and/or CSS Style attributes.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="BaseInputTag.html">BaseInputTag</A></B></TD>
<TD>Abstract base class for the various input tags.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="BaseTag.html">BaseTag</A></B></TD>
<TD>Renders an HTML <base> element with an href
attribute pointing to the absolute location of the enclosing JSP page.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="ButtonTag.html">ButtonTag</A></B></TD>
<TD>Renders an HTML BUTTON tag within the Struts framework.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="CancelTag.html">CancelTag</A></B></TD>
<TD>Tag for input fields of type "cancel".</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="CheckboxTag.html">CheckboxTag</A></B></TD>
<TD>Tag for input fields of type "checkbox".</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="Constants.html">Constants</A></B></TD>
<TD>Manifest constants for this package.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="ErrorsTag.html">ErrorsTag</A></B></TD>
<TD>Custom tag that renders error messages if an appropriate request attribute
has been created.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="FileTag.html">FileTag</A></B></TD>
<TD>Custom tag for input fields of type "file".</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="FormTag.html">FormTag</A></B></TD>
<TD>Custom tag that represents an input form, associated with a bean whose
properties correspond to the various fields of the form.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="FrameTag.html">FrameTag</A></B></TD>
<TD>Generate an HTML <code>&lt;frame&gt;</code> tag with similar capabilities
as those the <code>&lt;html:link&gt;</code> tag provides for hyperlink
elements.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="HiddenTag.html">HiddenTag</A></B></TD>
<TD>Custom tag for input fields of type "hidden".</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="HtmlTag.html">HtmlTag</A></B></TD>
<TD>Renders an HTML <html> element with appropriate language attributes if
there is a current Locale available in the user's session.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="ImageTag.html">ImageTag</A></B></TD>
<TD>Tag for input fields of type "image".</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="ImgTag.html">ImgTag</A></B></TD>
<TD>Generate an IMG tag to the specified image URI.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="JavascriptValidatorTag.html">JavascriptValidatorTag</A></B></TD>
<TD>Custom tag that generates JavaScript for client side validation based
on the validation rules loaded by the <code>ValidatorPlugIn</code>
defined in the struts-config.xml file.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="LinkTag.html">LinkTag</A></B></TD>
<TD>Generate a URL-encoded hyperlink to the specified URI.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="MessagesTag.html">MessagesTag</A></B></TD>
<TD>Custom tag that iterates the elements of a message collection.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="MessagesTei.html">MessagesTei</A></B></TD>
<TD>Implementation of <code>TagExtraInfo</code> for the <b>messages</b>
tag, identifying the scripting object(s) to be made visible.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="MultiboxTag.html">MultiboxTag</A></B></TD>
<TD>Tag for input fields of type "checkbox".</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="OptionsCollectionTag.html">OptionsCollectionTag</A></B></TD>
<TD>Tag for creating multiple &lt;select&gt; options from a collection.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="OptionsTag.html">OptionsTag</A></B></TD>
<TD>Tag for creating multiple &lt;select&gt; options from a collection.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="OptionTag.html">OptionTag</A></B></TD>
<TD>Tag for select options.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="PasswordTag.html">PasswordTag</A></B></TD>
<TD>Custom tag for input fields of type "password".</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="RadioTag.html">RadioTag</A></B></TD>
<TD>Tag for input fields of type "radio".</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="ResetTag.html">ResetTag</A></B></TD>
<TD>Tag for input fields of type "reset".</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="RewriteTag.html">RewriteTag</A></B></TD>
<TD>Generate a URL-encoded URI as a string.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="SelectTag.html">SelectTag</A></B></TD>
<TD>Custom tag that represents an HTML select element, associated with a
bean property specified by our attributes.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="SubmitTag.html">SubmitTag</A></B></TD>
<TD>Tag for input fields of type "submit".</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="TextareaTag.html">TextareaTag</A></B></TD>
<TD>Custom tag for input fields of type "textarea".</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="TextTag.html">TextTag</A></B></TD>
<TD>Custom tag for input fields of type "text".</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="XhtmlTag.html">XhtmlTag</A></B></TD>
<TD>This tag tells all other html taglib tags to render themselves in xhtml.</TD>
</TR>
</TABLE>
&nbsp;
<P>
<A NAME="package_description"><!-- --></A><H2>
Package org.apache.struts.taglib.html Description
</H2>
<P>
<p><a name="doc.Description">The "struts-html" tag library</a>
contains JSP custom tags useful in creating dynamic HTML user interfaces,
including input forms.</p>
<div align="Center">
<p> <a href="#doc.Intro">[Introduction]</a>
<a href="#doc.Form">[HTML Form Tags]</a>
<a href="#doc.Other">[Other HTML Tags]</a>
</p>
</div>
<hr>
<h3><a name="doc.Intro">Introduction</a>
</h3>
<p>The tags in the Struts HTML library form a bridge between a JSP view and
the other components of a Web application. Since a dynamic Web application
often depends on gathering data from a user, input forms play an important
role in the Struts framework. Consequently, the majority of the HTML tags
involve <a href="#doc.Form">HTML</a>
forms. Other important issues addressed by the Struts-HTML tags are <a href="#doc.Other.messages">
messages</a>
, <a href="#doc.Other.errors">error messages</a>
, <a href="#doc.Other.hyperlinking">hyperlinking</a>
and <a href="#doc.Other.i18n">internationalization</a>
.<br>
</p>
<div align="Center"> <img src="doc-files/htmlUML.gif" alt="Tags that wrap the html tags">
<br>
</div>
<hr>
<h3><a name="doc.Form">HTML "form" tags</a>
</h3>
<ul>
<li><a href="../../../../../../userGuide/struts-html.html#button">button</a>
</li>
<li><a href="../../../../../../userGuide/struts-html.html#cancel">cancel</a>
</li>
<li><a href="../../../../../../userGuide/struts-html.html#checkbox">checkboxes</a>
</li>
<li><a href="../../../../../../userGuide/struts-html.html#file">file</a>
</li>
<li><a href="../../../../../../userGuide/struts-html.html#hidden">hidden</a>
</li>
<li><a href="../../../../../../userGuide/struts-html.html#image">image</a>
</li>
<li><a href="../../../../../../userGuide/struts-html.html#multibox">multibox</a>
</li>
<li><a href="../../../../../../userGuide/struts-html.html#password">password</a>
input fields</li>
<li><a href="../../../../../../userGuide/struts-html.html#radio">radio</a>
buttons</li>
<li><a href="../../../../../../userGuide/struts-html.html#reset">reset</a>
buttons</li>
<li><a href="../../../../../../userGuide/struts-html.html#select">select</a>
lists with embedded</li>
<li><a href="../../../../../../userGuide/struts-html.html#option">option</a>
</li>
<li><a href="../../../../../../userGuide/struts-html.html#options">options</a>
</li>
<li><a href="../../../../../../userGuide/struts-html.html#submit">submit</a>
buttons</li>
<li><a href="../../../../../../userGuide/struts-html.html#text">text</a>
input fields</li>
<li><a href="../../../../../../userGuide/struts-html.html#textarea">textareas</a>
</li>
</ul>
<p>Each of these tags must be nested within a &lt;html:form&gt; tag.</p>
<h4><a name="doc.Form.formTag">About the form tag</a>
</h4>
<p>The Struts <code>form</code> tag outputs a standard HTML form tag, and
also links the input form with a JavaBean subclassed from the Struts
<a href="../../action/ActionForm.html">ActionForm</a>object.
Each field in the form should correspond to a property of the form's
bean. When a field and property correspond, the bean is first used to populate
the form, and then to store the user's input when the form is submitted
to the controller servlet.</p>
<p>The name of the bean and its class can be specified as a property to the
form tag, but may also be omitted. If omitted, the <code>ActionMappings</code>
database (loaded from the <code>struts-config.xml</code> file) is consulted.
If the current page is specified as the <code>input</code> property for an
<code>action</code>, the name of the <code>action</code> is used. The <code>
type</code> property for the bean is also then taken from the configuration,
via a Form Bean definition.</p>
<p>Here's a clip from the Struts Example configuration:</p>
<pre>&lt;action-mappings&gt;<br> &lt;!-- Process a user logon --&gt;<br> &lt;action path="/logon"<br> type="org.apache.struts.webapp.example.LogonAction"<br> name="logonForm"<br> scope="request"<br> input="/logon.jsp"&gt;<br> &lt;/action&gt;<br> &lt; ... /&gt;<br>&lt;/action-mappings&gt;<br>&lt;form-beans&gt;<br> &lt;!-- Logon form bean --&gt;<br> &lt;form-bean name="logonForm"<br> type="org.apache.struts.webapp.example.LogonForm"/&gt;<br> &lt; ... /&gt;<br> &lt;/form-beans&gt;<br>&lt;/pre&gt;<br></pre>
<p>Given this configuration, the HTML form tag for <code>logon.jsp</code>
will default to using "<code>logonForm</code>" as its name property and
"<code> org.apache.struts.webapp.example.LogonForm</code>" as the attribute's type.
This way you can manage the namespace for your framework components from
the configuration file.</p>
<p>If the form tag does not find the form bean in any of the scopes (page,
request, session, application), it creates one using the specified type.</p>
<p>The Struts <code>ActionForm</code> class is equipped with standard <code>
reset()</code> and <code>validate()</code> methods, that can be used by
the controller to enable automatic data validation. See the <a href="../../../../../../userGuide/building_view.html#form_validation">
Users Guide</a>
for more about Form Validation. An important aspect of validation is
reporting errors to the user. This can be handled by the Struts <code>errors</code>
tag, which is discussed <a href="#doc.Other.errors">later in this document</a>
.</p>
<hr>
<h4><a name="doc.Form.attributes">Common Form Tag Attributes</a>
</h4>
<p>The form "field" tags in the Struts-HTML tag library share a common set
of tag attributes that have the same meaning, no matter what field tag they
are used with. These properties also accept Runtime Expressions, meaning
you can set them with a scriptlet. The common attributes fall into four
categories: <a href="#doc.Form.attributes.struts">Struts Common,</a>
<a href="#doc.Form.attributes.navigation">HTML Navigation</a>
, <a href="#doc.Form.attributes.javascript">Javascript</a>
, and <a href="#doc.Form.attributes.css">CSS</a>
.</p>
<h5><a name="doc.Form.attributes.struts">Struts Common</a>
</h5>
<div align="Center">
<center>
<table width="90%" border="1" cellpadding="4">
<tbody>
<tr>
<td> name </td>
<td> The attribute name of the <code>ActionForm</code> bean whose
properties are consulted when rendering the current value of this
input field. If not specified, the bean associated with the form
tag we are nested within is utilized. </td>
</tr>
<tr>
<td> property </td>
<td> Name of the request parameter that will be included with this
submission, set to the specified value. </td>
</tr>
<tr>
<td> value </td>
<td> Value of the label to be used with this element. This value
will also be submitted as the value of the specified request parameter.
[Body of this tag (if any), or "Click"]&nbsp; </td>
</tr>
</tbody>
</table>
</center>
</div>
<p>&nbsp;</p>
<p>Like <a href="../bean/package-summary.html#doc.Properties">Struts-Bean</a>
tags, the property attribute for the Struts-HTML tags accept simple,
nested, and indexed expressions. For example, this tag:</p>
<pre> &lt;html:text property="mailingAddress.street"/&gt;<br></pre>
<p>corresponds to:</p>
<pre> getMailingAddress().getStreet()<br></pre>
<p>For more about using simple, nested, and indexed expressions with Struts,
see the <a href="../bean/package-summary.html#doc.Properties">Struts-Bean
Developers Guide.</a>
</p>
<h5><a name="doc.Form.attributes.javascript">Javascript Event Handlers</a>
</h5>
<div align="Center">
<center>
<table width="90%" border="1" cellpadding="4">
<tbody>
<tr>
<td> onblur </td>
<td> Executed when this element loses input focus. </td>
</tr>
<tr>
<td> onchange </td>
<td> Executed when this element loses input focus and its value
has changed. </td>
</tr>
<tr>
<td> onclick </td>
<td> Executed when this element receives a mouse click. </td>
</tr>
<tr>
<td> ondblclick </td>
<td> Executed when this element receives a mouse - double click.
</td>
</tr>
<tr>
<td> onfocus </td>
<td> Executed when this element receives input focus. </td>
</tr>
<tr>
<td> onkeydown </td>
<td> Executed when this element has focus and a key is depressed.&nbsp;
</td>
</tr>
<tr>
<td> onkeypress </td>
<td> Executed when this element has focus and a key is depressed
and released </td>
</tr>
<tr>
<td> onkeyup </td>
<td> Executed when this element has focus and a key is released
</td>
</tr>
<tr>
<td> onmousedown </td>
<td> Executed when this element is under the mouse pointer and
a mouse button is depressed. </td>
</tr>
<tr>
<td> onmousemove </td>
<td> Executed when this element is under the mouse pointer and
the pointer is moved. </td>
</tr>
<tr>
<td> onmouseout </td>
<td> Executed when this element was under the mouse pointer but
the pointer was moved outside the element. </td>
</tr>
<tr>
<td> onmouseover </td>
<td> Executed when this element was not under the mouse pointer
but the pointer is moved inside the element. </td>
</tr>
<tr>
<td> onmouseup </td>
<td> Executed when this element is under the mouse pointer and
a mouse button is released.&nbsp; </td>
</tr>
<tr>
<td>&nbsp; </td>
<td> <b>"parent" form tag only</b> </td>
</tr>
<tr>
<td> onreset </td>
<td> Executed if the form is reset. </td>
</tr>
<tr>
<td> onsubmit </td>
<td> Executed if the form is submitted.&nbsp; </td>
</tr>
</tbody>
</table>
</center>
</div>
<h5>&nbsp;</h5>
<h5><a name="doc.Form.attributes.navigation">HTML Navigation Attributes</a>
</h5>
<div align="Center">
<center>
<table width="90%" border="1" cellpadding="4">
<tbody>
<tr>
<td> accesskey </td>
<td> The keyboard character used to move focus immediately to this
element. </td>
</tr>
<tr>
<td> tabindex </td>
<td> The tab order (ascending positive integers) for this element.
</td>
</tr>
</tbody>
</table>
</center>
</div>
<h5>&nbsp;</h5>
<h5><a name="doc.Form.attributes.css">CSS Attributes</a>
</h5>
<div align="Center">
<center>
<table width="90%" border="1" cellpadding="4">
<tbody>
<tr>
<td> style </td>
<td> CSS styles to be applied to this HTML element. </td>
</tr>
<tr>
<td> styleClass </td>
<td> CSS stylesheet class to be applied to this HTML element. </td>
</tr>
</tbody>
</table>
</center>
</div>
<p>&nbsp;</p>
<p>See the <a href="../../../../../../userGuide/struts-html.html">HTML Tags Reference</a>
for detailed information about the available tags in this tag library,
and the complete list of valid attributes for each tag.</p>
<hr>
<h3><a name="doc.Other">Other HTML tags</a>
</h3>
<p>Aside from form processing, the Struts-HTML offers several other tags or
tag properties to help with displaying error messages, messages, maintaining
hyperlinks, and with internationalizing your application.</p>
<h4><a name="doc.Other.messages">Displaying Messages</a>
</h4>
<p>Message handling is an important part of any application. These messages
can be informative messages and/or error messages for the user. Struts
provides a generalized method for communicating runtime messages to users,
based on the same technology used to provide internationalization. Messages
and error messages can both be used by the messages tag.</p>
<p>The messages tag [since version 1.1] has basically the same functionality
as the errors tag, but it iterates through the messages so any formatting
of messages can be done in the JSP page. Also the header and footer for
the message tag are optional. </p>
<p>By default, the messages tag will iterate through all pending messages.
You can also specify a property when queuing a message, and then refer to
that property in the messages tag. In that case, only the message(s) for
that property will be displayed. This is helpful when you would like to
place the message for a field next to the actual field.</p>
<p>Messages are often queued in the Action. The variable info is the ActionForm
corresponding to this Action. :</p>
<pre> <br> ActionMessages messages = new ActionMessages();<br> messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("userForm.insert", info.getUserName());<br> messages.add("activationDate", new ActionMessage("userForm.active", info.getSubscriptionLength());<br></pre>
<p>This queues two messages, one is a global message and another for the
"activationDate" field. To print all the messages together, simply place the
messages tag anywhere in your JSP.</p>
<pre> &lt;body bgcolor="white"&gt;<br> &lt;ul&gt;<br> &lt;html:messages id="message"&gt;<br> &lt;li&gt;&lt;bean:write name="message"/&gt;&lt;/li&gt;<br> &lt;/html:messages&gt;<br> &lt;/ul&gt;<br></pre>
<p>Or, you can place specific messages at different locations</p>
<pre> &lt;ul&gt;<br> &lt;html:messages id="message" property="&lt;%= org.apache.struts.action.ActionMessages.GLOBAL_MESSAGE %&gt;"&gt;<br> &lt;li&gt;&lt;bean:write name="message"/&gt;&lt;/li&gt;<br> &lt;/html:messages&gt;<br> &lt;/ul&gt;<br> &lt;table&gt;<br> &lt;tr&gt;<br> &lt;td align="left"&gt;<br> &lt;html:text property="username" size="16" maxlength="16"/&gt;<br> &lt;/td&gt;<br> &lt;/tr&gt;<br> &lt;tr&gt;<br> &lt;td align="left"&gt;<br> &lt;html:text property="activationDate" size="10" maxlength="10"/&gt;<br> &lt;br&gt;<br> &lt;html:messages id="message" property="activationDate"&gt;<br> &lt;bean:write name="message"/&gt;&lt;br&gt;<br> &lt;/html:messages&gt;<br> &lt;/td&gt;<br> &lt;/tr&gt;<br> &lt;/table&gt;<br></pre>
<p>By default, the actual message is retrieved from the application's standard
message resource. This gives you a master list of the messages used by
your application, and provides for internationalization. In the code snippet,
the message corresponding to "userForm.insert" would be retrieved and
displayed to the user at runtime. </p>
<pre> userForm.insert={0} has successfully been inserted.<br> userForm.active=The account will be active for {0} months.<br></pre>
<p>A header and footer are optional. The header will be rendered before iteration
begins and the footer will be rendered after iteration is over. If a
value is not assigned to the attribute, then nothing will be rendered
for that attribute.</p>
<pre> &lt;html:messages id="message" header="errors.header" footer="errors.footer"&gt;<br> &lt;li&gt;&lt;bean:write name="message"/&gt;&lt;/li&gt;<br> &lt;/html:messages&gt;<br><br> errors.header=&lt;h3&gt;&lt;font color="red"&gt;Validation Error&lt;/font&gt;&lt;/h3&gt;<br> You must correct the following error(s) before proceeding:&lt;UL&gt;<br> errors.footer=&lt;/ul&gt;&lt;hr&gt;<br></pre>
<h4><a name="doc.Other.errors">Displaying Error Messages</a>
</h4>
<p>Error handling is an important part of any application, and curing an error
often involves getting the user's help. Struts provides a generalized method
for communicating runtime messages to users, based on the same technology
used to provide internationalization. </p>
<p>In a Web application, it is common to reuse the input page to display error
messages. The Struts error message tag can be placed wherever you would
like the messages to display. If no messages are pending, nothing is printed.</p>
<p>By default, the errors tag will print all pending messages. You can also
specify a property when queuing a message, and then refer to that property
in the errors tag. In that case, only the message for that property will
be displayed. This is helpful when you would like to place the message for
a field next to the actual field.</p>
<p>Error messages are often queued in the ActionForm validate method. Here's
a snippet from the Struts Example application:</p>
<pre> ActionErrors errors = new ActionErrors();<br> if ((username == null) || (username.length() &lt; 1))<br> errors.add("username", new ActionError("error.username.required"));<br> if ((password == null) || (password.length() &lt; 1))<br> errors.add("password",<br> new ActionError("error.password.required"));<br></pre>
<p>This queues two error messages, one for the "username" field and another
for the "password" field. To print all the messages together, simply place
the error tag anywhere in your JSP.</p>
<pre> &lt;body bgcolor="white"&gt;<br> &lt;html:errors/&gt;<br></pre>
<p>Or, you can place specific error messages at different locations</p>
<pre> &lt;td align="left"&gt;<br> &lt;html:text property="username" size="16" maxlength="16"/&gt;<br> &lt;html:errors property="username"/&gt;<br> &lt;/td&gt;<br> &lt;/tr&gt;&lt;tr&gt;<br> &lt;td align="left"&gt;<br> &lt;html:text property="password" size="16" maxlength="16"/&gt;<br> &lt;html:errors property="password"/&gt;<br> &lt;/td&gt;<br></pre>
<p>By default, the actual error message is retrieved from the application's
standard message resource. This gives you a master list of the error messages
used by your application, and provides for internationalization. In the
code snippet, the message corresponding to "error.username.required" would
be retrieved and displayed to the user at runtime. </p>
<pre> error.username.required=&lt;li&gt;Username is required&lt;/li&gt;<br></pre>
<p>Most often, error messages are displayed in a particular way. To make it
easy to format your messages, you can also specific an <code>errors.header</code>
and <code>errors.footer</code> string in your message resource. Typically,
you might want to render the messages in a different color, or set them
up to appear in an unordered list. Using the <code>errors.header</code>
and <code>errors.footer</code> strings keeps the setup codes out of your
JSP until a message actually prints.</p>
<pre> errors.header=&lt;h3&gt;&lt;font color="red"&gt;Validation Error&lt;/font&gt;&lt;/h3&gt;<br> You must correct the following error(s) before proceeding:&lt;UL&gt;<br> errors.footer=&lt;/ul&gt;&lt;hr&gt;<br></pre>
<h4><a name="doc.Other.hyperlinking">Maintaining Hyperlinks</a>
</h4>
<ul>
<li><a href="../../../../../../userGuide/struts-html.html#base">base</a>
</li>
</ul>
<p>When implementing a Web application, it is usually a good idea to use relative
references to other files in the same application. But in a dynamic application,
the controller servlet often returns a completely different file than the
one requested. (Often, the requested "file" doesn't actually exist, but
represents an action for the controller to interpret.) Since relative references
are resolved by the browser, they often won't work in a dynamic application.</p>
<p>To accommodate this, the Struts-HTML taglib provides a <code>&lt;base&gt;</code>
tag that renders an HTML element with an href attribute pointing
to the absolute location of its page. </p>
<p>As a rule, you should place the Struts-HTML base tag in the &lt;head&gt;
section of any JSP that uses relative references to other files.</p>
<pre> &lt;head&gt;<br> &lt;html:base/&gt;<br> &lt;/head&gt;<br></pre>
<h4><a name="doc.Other.sessions">Session Tracking</a>
</h4>
<p>The Java Servlet framework has built-in support for tracking a client through
a session. Sessions are a useful way to compensate for the stateless nature
of HTTP. Tracking a client can be done with either cookies or URL rewriting,
cookies being preferred when available. Struts offers three tags that make
it easy to write "session-aware" hyperlink references:</p>
<ul>
<li><a href="../../../../../../userGuide/struts-html.html#link">link</a>
- Renders an HTML anchor or hyperlink.</li>
<li><a href="../../../../../../userGuide/struts-html.html#rewrite">rewrite</a>
- Renders a request URI, but without creating the &lt;a&gt; hyperlink.
This tag is useful when you want to generate a string constant for use
by a JavaScript procedure.</li>
<li><a href="../../../../../../userGuide/struts-html.html#img">img</a>
- Renders an HTML &lt;img&gt; element with the image at the specified
URL.</li>
</ul>
<p>Each of these tags will automatically apply URL rewriting, to maintain
session state in the absence of cookies. The content displayed for the hyperlink
will be taken from the body of the tag. The base URL for the hyperlink
is calculated based on properties given with the tag.</p>
<p>Normally, the hyperlink or URI you specify is left unchanged. If you would
like to include dynamic parameters to the hyperlink or URI, you can pass
those to the tags via a JavaBean. If there may be naming conflicts, you
can also specify the scope that the tag searches (request, page, session,
application). </p>
<p>To pass a single dynamic parameter, specify the parameter's name using
the <code>paramId</code> attribute. You can then specify the name of the
JavaBean holding the value using the <code>paramName</code> attribute, and
a particular property using <code>paramProperty</code>. </p>
<p>So, a tag like</p>
<pre> &lt;html:link paramId="target"<br> paramName="linkParams" <br> paramProperty="target"<br> paramScope="request"<br> &gt;detail.html&lt;/html:link&gt;</pre>
<p>would correspond to something like</p>
<pre> &lt;A HREF="detail.html?&lt;%= <br> request.getAttribute("linkParams").getTarget()<br> %&gt;"&gt;&lt;/A&gt;<br></pre>
<p>To search all scopes (request, page, session, and application), omit <code>
paramScope</code>. </p>
<p>The <code>paramProperty</code> attribute may also be omitted, so long as
the named bean identifies a value that can be converted to a String. </p>
<p>To pass multiple dynamic parameters, you can store them in a <code><a href="http://java.sun.com/j2se/1.3/docs/api/java/util/Map.html">
java.util.Map</a>
</code>, and use the name of the map for the <code>paramName</code>. The
map must then contain one or more <code>paramIds</code> and their corresponding
values. As the Map is processed, the keys are assumed to be the names of
query parameters to be appended. The value associated with each key must
be either a String or a String array representing the parameter value(s).
If a String array is specified, more than one value for the same query parameter
name will be created. </p>
<p>The HTML session tracking tags use several common attributes, that can
be organized into three groups, as follows. All of these attributes are
not used by all three tags (<code>link</code>, <code>rewrite</code>, and
<code>img</code>), and so the tags using each attribute is given. </p>
<p>&nbsp;
<table width="90%" border="1" cellpadding="4">
<tbody>
<tr>
<th colspan="2">forward, href, and page</th>
</tr>
<tr>
<td> forward </td>
<td> [ link rewrite ] - Logical name of a global ActionForward that
contains the actual content-relative URI of the destination of this
transfer. This hyperlink may be dynamically modified by the inclusion
of query parameters, as described in the tag description. You must specify
exactly one of the forward attribute, the href attribute, the linkName
attribute, or the page attribute </td>
</tr>
<tr>
<td> href </td>
<td> [ link rewrite ] - The URL to which this hyperlink will transfer
control if activated. This hyperlink may be dynamically modified by
the inclusion of query parameters, as described in the tag description.
You must specify exactly one of the forward attribute, the href attribute,
the linkName attribute, or the page attribute. </td>
</tr>
<tr>
<td> page </td>
<td> [ link rewrite ] - The context-relative path, starting with a
slash, of the image to be displayed by this tag. The rendered URL
for this image will automatically prepend the context path of this
web application (in the same manner as the page attribute on the link
tag works), in addition to any necessary URL rewriting. You must specify
either the page attribute or the src attribute. </td>
</tr>
</tbody>
</table>
</p>
<p>&nbsp;
<table width="90%" border="1" cellpadding="4">
<tbody>
<tr>
<th colspan="2">linkName, Target , and src</th>
</tr>
<tr>
<td> linkName </td>
<td>
<p>[ link ] - The anchor name to be defined within this page, so that
you can reference it with intra-page hyperlinks. In other words, the
value specified here will render a "name" element in the generated
anchor tag. </p>
</td>
</tr>
<tr>
<td> target </td>
<td> [ link img ] - The window target in which the resource requested
by this hyperlink will be displayed, for example in a framed presentation.
</td>
</tr>
<tr>
<td> src </td>
<td> [ img ] - The URL to which this image will be transferred from
This image may be dynamically modified by the inclusion of query parameters,
as described in the tag description. This value will be used unmodified
(other than potential URL rewriting) as the value of the "src" attribute
in the rendered tag. You must specify either the page attribute or the
the src attribute. </td>
</tr>
</tbody>
</table>
</p>
<p>&nbsp;
<table width="90%" border="1" cellpadding="4">
<tbody>
<tr>
<th colspan="2">paramId, paramName, paramProperty, paramScope </th>
</tr>
<tr>
<td> paramId </td>
<td> [ link img ] - The name of the request parameter that will be
dynamically added to the generated src URL. The corresponding value
is defined by the paramName and (optional) paramProperty attributes,
optionally scoped by the paramScope attribute</td>
</tr>
<tr>
<td> paramName </td>
<td> [ link img ] - The name of a JSP bean that is a String containing
the value for the request parameter named by paramId (if paramProperty
is not specified), or a JSP bean whose property getter is called to
return a String (if paramProperty is specified). The JSP bean is constrained
to the bean scope specified by the paramScope property, if it is specified.
</td>
</tr>
<tr>
<td> paramProperty </td>
<td> [ link img ] - The name of a property of the bean specified by
the paramName attribute, whose return value must be a String containing
the value of the request parameter (named by the paramId attribute)
that will be dynamically added to this hyperlink or src URL</td>
</tr>
<tr>
<td> paramScope </td>
<td> [ link img ] - The scope within which to search for the bean specified
by the paramName attribute. If not specified, all scopes are searched.
</td>
</tr>
</tbody>
</table>
</p>
<p>&nbsp;
<table width="90%" border="1" cellpadding="4">
<tbody>
<tr>
<th colspan="2">
<p>name, property, scope </p>
</th>
</tr>
<tr>
<td> name </td>
<td> [ link rewrite img ] - The name of a JSP bean that contains a
<code><a href="http://java.sun.com/j2se/1.3/docs/api/java/util/Map.html">
Map</a>
</code> representing the query parameters (if <code>property</code>
is not specified), or a JSP bean whose property getter is called
to return a <code>Map</code> (if <code>property</code> is specified).
</td>
</tr>
<tr>
<td> property </td>
<td>[ link rewrite img ] - The name of a property of the bean specified
by the name attribute, whose return value must be a <code><a href="http://java.sun.com/j2se/1.3/docs/api/java/util/Map.html">
Map</a>
</code> containing the query parameters to be added to the src
URL. You <b>must</b> specify the name attribute if you specify this
attribute </td>
</tr>
<tr>
<td> scope </td>
<td> [ link rewrite img ] - The scope within which to search for the
bean specified by the name attribute. If not specified, all scopes are
searched. </td>
</tr>
</tbody>
</table>
</p>
<p>See the <a href="../../../../../../userGuide/struts-html.html">HTML Tags Reference</a>
for the complete list of valid attributes for each tag.. </p>
<h4><a name="doc.Other.i18n">Internationalization</a>
</h4>
<p>Internationalization is automatically supported by the HTML tags where
appropriate. </p>
<p><a href="../../../../../../userGuide/struts-html.html#errors">Errors</a>
- By default, the text for your messages will be returned by the default
message resource, which will select the appropriate language for the user.
You may also specify another message resource using the <code>bundle</code>
attribute.</p>
<p><a href="../../../../../../userGuide/struts-html.html#html">HTML</a>
- Renders an HTML element with language attributes extracted from the
user's current Locale object, if there is one. </p>
<p><a href="../../../../../../userGuide/struts-html.html#image">image</a>
and <a href="../../../../../../userGuide/struts-html.html#img">img</a>
- Can optionally retrieve the value for its binary source and alt text
from the message resource, so that different images and/or text can be provided
for different locales. See the tag's <code>altKey</code>, <code> srcKey</code>
, and <code>bundle</code> attributes in the <a href="../../../../../../userGuide/struts-html.html">
HTML Tags Reference</a>
.</p>
<p><a href="../../../../../../userGuide/struts-html.html#messages">Messages</a>
- By default, the text for your messages will be returned by the default
message resource, which will select the appropriate language for the user.
You may also specify another message resource using the <code>bundle</code>
attribute.</p>
<p>See the <a href="../../../../../../userGuide/building_view.html#i18n">
Users Guide</a>
for more on how Struts helps you internationalize your applications.</p>
<p>&nbsp;</p>
<P>
<P>
<HR>
<!-- ========== START OF NAVBAR ========== -->
<A NAME="navbar_bottom"><!-- --></A>
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
<TR>
<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
<A NAME="navbar_bottom_firstrow"><!-- --></A>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
<TR ALIGN="center" VALIGN="top">
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Package</B></FONT>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <FONT CLASS="NavBarFont1">Class</FONT>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-use.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
</TR>
</TABLE>
</TD>
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
</EM>
</TD>
</TR>
<TR>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
&nbsp;<A HREF="../../../../../org/apache/struts/taglib/bean/package-summary.html"><B>PREV PACKAGE</B></A>&nbsp;
&nbsp;<A HREF="../../../../../org/apache/struts/taglib/logic/package-summary.html"><B>NEXT PACKAGE</B></A></FONT></TD>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../../../../index.html" TARGET="_top"><B>FRAMES</B></A> &nbsp;
&nbsp;<A HREF="package-summary.html" TARGET="_top"><B>NO FRAMES</B></A> &nbsp;
&nbsp;
<SCRIPT>
<!--
if(window==top) {
document.writeln('<A HREF="../../../../../allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
}
//-->
</SCRIPT>
<NOSCRIPT>
<A HREF="../../../../../allclasses-noframe.html" TARGET=""><B>All Classes</B></A>
</NOSCRIPT>
</FONT></TD>
</TR>
</TABLE>
<!-- =========== END OF NAVBAR =========== -->
<HR>
Copyright © 2000-2003 - Apache Software Foundation
</BODY>
</HTML>