Robin Mannering wrote:
Thanks for all the help received on this one..
As pointed out by Joe, the <html:messages> tag is conditional, and when supplying the
"parameter" atribute I get exactly what I need.
For reference, it looks like this:
<%-- Display error message keyed under 'usernameError' if it exists
--%>
<html:messages id="error" property="usernameError">
<tr>
<td></td>
<td>${error}</td>
</tr>
</html:messages>
Thanks again all!
-----Original Message-----
From: Joe Germuska [mailto:[EMAIL PROTECTED]
Sent: 05 October 2004 14:00
To: Struts Users Mailing List
Subject: RE: ActionError and JSP display
At 1:45 PM +0100 10/5/04, Robin Mannering wrote:
Hi,
I was intending to use <html:errors property="username"/>,
specifying the property for display, but it still doesn't allow me
to test for it's existence.
What I'd like to do is test if an error exists, then add a new HTML
table row and cell into the output containing the error message,
otherwise I do not want to create the HTML table row and cell at all.
Is there a way to do this ?
Personally, I think <html:errors> is "the old way", although at least
one committer has expressed a preference for it. I prefer
<html:messages> It is essentially a combination conditional block
and iterator. Here is my "standard" error messages JSP block:
<html:messages id="msg"><div class="error"><c:out value="${msg}"
/></div></html:messages>
By default, it looks for an ActionMessages object saved using Struts'
"saveErrors" semantics (that is, stored in the request under
"org.apache.struts.action.ERROR" You can set the "message" attribute
to "true" to get "messages" instead, and you can set the "name"
attribute to fetch any arbitrary ActionMessages. Furthermore, you
can use the "property" attribute to constrain the condition to only
if the ActionMessages contains messages for the given property. If
you're not using the JSTL, you can use <bean:write> instead of
<c:out> to display the message itself. And, of course, you can use
table rows instead of divs to wrap each message provided by the
iterator.
http://struts.apache.org/userGuide/struts-html.html#messages
Hope this helps...
Joe
There's also the <logic:messagesPresent/> tag that takes a property
attribute:
http://struts.apache.org/userGuide/struts-logic.html#messagesPresent
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]