29.01.2013 Views

WebSphere Application Server - IBM Redbooks

WebSphere Application Server - IBM Redbooks

WebSphere Application Server - IBM Redbooks

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

When a browser submits an HTML form, the Struts ActionServlet does the<br />

following:<br />

1. Looks at the field names from the HTML form<br />

2. Matches them to the properties' names in the form bean<br />

3. Automatically calls the setter methods of these variables to put the values<br />

retrieved from the HTML form<br />

The form bean can be used to collect data from the user, to validate what the<br />

user entered, and by the JSP to repopulate the form fields<br />

In the case of validation errors, Struts has a shared mechanism for raising and<br />

displaying error messages. It automatically invokes the ActionForm.validate<br />

method whenever the JSP page containing the form corresponding to this<br />

ActionForm submits the form. Any type of validation can be performed in this<br />

method. The only requirement is that it return a set of ActionError objects in the<br />

return value. Each ActionError corresponds to a single validation failure, which<br />

maps to a specific error message. These error messages are held in a properties<br />

file to which the Struts application refers.<br />

Custom tags<br />

There are four tag libraries included in Struts:<br />

1. The HTML tag library, which includes tags for describing dynamic pages,<br />

especially forms.<br />

2. The beans tag library, which provides additional tags for improved access to<br />

Java beans and additional support for internationalization.<br />

3. The logic tag library, which provides tags that support conditional execution<br />

and looping.<br />

4. The template tag library for producing and using common JSP templates in<br />

multiple pages.<br />

Using these custom tags, the Struts framework can automatically populate fields<br />

to and from a form bean, providing two advantages:<br />

► The only thing most JSPs need to know about the rest of the framework is the<br />

proper field names and where to submit the form. The associated form bean<br />

automatically receives the corresponding value.<br />

► If a bean is present in the appropriate scope, for instance after an input<br />

validation routine, the form fields will be automatically initialized with the<br />

matching property values.<br />

386 <strong>IBM</strong> <strong>WebSphere</strong> <strong>Application</strong> <strong>Server</strong> - Express V5.0.2 Developer Handbook

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!