📄 package-summary.html
字号:
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"] </td>
</tr>
</tbody>
</table>
</center>
</div>
<p> </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> <html:text property="mailingAddress.street"/><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.
</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. </td>
</tr>
<tr>
<td> </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. </td>
</tr>
</tbody>
</table>
</center>
</div>
<h5> </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> </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> </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> <body bgcolor="white"><br> <ul><br> <html:messages id="message"><br> <li><bean:write name="message"/></li><br> </html:messages><br> </ul><br></pre>
<p>Or, you can place specific messages at different locations</p>
<pre> <ul><br> <html:messages id="message" property="<%= org.apache.struts.action.ActionMessages.GLOBAL_MESSAGE %>"><br> <li><bean:write name="message"/></li><br> </html:messages><br> </ul><br> <table><br> <tr><br> <td align="left"><br> <html:text property="username" size="16" maxlength="16"/><br> </td><br> </tr><br> <tr><br> <td align="left"><br> <html:text property="activationDate" size="10" maxlength="10"/><br> <br><br> <html:messages id="message" property="activationDate"><br> <bean:write name="message"/><br><br> </html:messages><br> </td><br> </tr><br> </table><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> <html:messages id="message" header="errors.header" footer="errors.footer"><br> <li><bean:write name="message"/></li><br> </html:messages><br><br> errors.header=<h3><font color="red">Validation Error</font></h3><br> You must correct the following error(s) before proceeding:<UL><br> errors.footer=</ul><hr><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() < 1))<br> errors.add("username", new ActionError("error.username.required"));<br> if ((password == null) || (password.length() < 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> <body bgcolor="white"><br> <html:errors/><br></pre>
<p>Or, you can place specific error messages at different locations</p>
<pre> <td align="left"><br> <html:text property="username" size="16" maxlength="16"/><br> <html:errors property="username"/><br> </td><br> </tr><tr><br> <td align="left"><br> <html:text property="password" size="16" maxlength="16"/><br> <html:errors property="password"/><br> </td><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=<li>Username is required</li><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=<h3><font color="red">Validation Error</font></h3><br> You must correct the following error(s) before proceeding:<UL><br> errors.footer=</ul><hr><br></pre>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -