Home

This Chapter
-Chapter 11: Message Handling and Internationalization
-Working with Locales in Struts
-Registering Properties Files
-The HTML Tag Librarys’s errors Tag
-The HTML Librarys’s messages Tag
-JSTL I18N Library
-Summary

Table of Contents
-Introduction
-Chapter 1: Model 2 and Struts
-Chapter 2: Input Validation with Action Forms
-Chapter 3: The HTML Tag Library
-Chapter 4: Input Validation and Data Conversion
-Chapter 5: The Validator Plugin
-Chapter 6: The Expression Language
-Chapter 7: JSTL
-Chapter 8: The Bean Tag Library
-Chapter 9: The Logic Tag Library
-Chapter 10: Struts-EL, Nested, selectLabel
-Chapter 11: Message Handling and Internationalization
-Chapter 12: The Tiles Framework
-Chapter 13: Securing Struts Applications
-Chapter 14: The Config Object
-Chapter 15: The Persistence Layer
-Chapter 16: Object Caching
-Chapter 17: File Upload and File Download
-Chapter 18: Paging and Sorting
-Chapter 19: Preventing Double Submits
-Chapter 20: Early HttpSession Invalidation
-Chapter 21: Decorating Request Objects
-Chapter 22: How Struts Works

Previous
Next

 

The HTML Librarys’s messages Tag

Like the errors tag, the messages tag looks for the ActionErrors object referenced by the scoped variable whose name is the same as the value of the ERROR_KEY field of the org.apache.struts.Globals class. However, it does not display the messages inside the ActionErrors object. Instead, it iterates the collection and, for each iteration, creates a scoped variable referencing the iterated ActionError object. To actually display the error messages, you can use the Bean Tag Library’s write tag nested inside the messages tag. Compared to the errors tag, the messages tag gives you control over the formatting of the error messages without having to rely on the errors.header, errors.footer, errors.prefix, and errors.suffix keys in your properties file.

As an example, the following messages tag displays the validation error messages of the current action form.

<html:messages id="item">
<li><bean:write name="item"/></li>
</html:messages>

Notice that the id attribute of the messages tag specifies the scoped variable that references the ActionError object for each iteration.

Previous
Next