You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Eu Hin Chua <em...@iinet.net.au> on 2002/10/15 16:59:25 UTC

How do I use properly?

Hi,

I'm having trouble getting <html:message> to work with attached
ActionMessages. I've tried searching through the mailing list archives
(somewhat unsuccessfully) and perused the review chapters of the
O'Reilly Struts book available at www.theserverside.com. Please accept
my apologies if this question has been answered already.

I am using 1.1 Beta 2. 

In the execute() method of my Action, I am doing something like:

ActionMessages messages = new ActionMessages();

messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("errors.ioException", "blah blah"));

messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("errors.ioException", "blah blah"));

saveMessages(request, messages);

before redirecting to a JSP.


Inside the JSP, I am doing something like:

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

This is copied verbatim from the Struts HTML Taglib Package Description
document
(http://jakarta.apache.org/struts/api/org/apache/struts/taglib/html/package-summary.html#package_description)

However, when I try it, nothing gets displayed. What am I doing wrong?

Interestingly enough, in my Action code, if I also create an
ActionErrors object, populate it with ActionErrors and save it via
saveErrors(), the JSP listed above will actually display the
ActionErrors (but not the ActionMessages).

According to the html:message documentation, the 'id' attribute
refers to "The name of a page scope JSP bean that will contain the
current element of the collection of messages on each iteration, if it
is not null". I am not sure how or why the HTML Taglib Description
example uses an 'id' attribute of "message". 

Does invoking saveMessages() automatically create and attach a JavaBean
called 'message'? If it doesn't, what value of 'id' should I be using to
correctly display ActionMessages?

If someone could provide me with a complete working example of how to
use <html:message> I'd be most grateful.

Thanks in advance,
Hin

-- 
If you pray hard enough you can make water run uphill. How 
hard? Why hard enough to make water run uphill, of course.
    - Robert Heinlein

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>