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

--
Joe Germuska [EMAIL PROTECTED] http://blog.germuska.com "In fact, when I die, if I don't hear 'A Love Supreme,' I'll turn back; I'll know I'm in the wrong place."
- Carlos Santana

Reply via email to