You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by StrutsUser <bi...@verizon.net> on 2004/12/11 14:19:46 UTC

html:errors and manual iterate

I have a situation in which I have to add an ActionError without a message (use it to indicate field in error on the page). If I use the generic html:errors tag, it displays lineitems without a message. Is there a way to iterate over html:errors to check that a message should be displayed only if the message is not empty. 
Thanks in advance for any suggestions,
Leonard

Re: html:errors and manual iterate

Posted by Sunny <su...@collab.net>.
You might need to pass  one more argument namely "message" to the 
<html:messages> tag .

If you've saved a message in struts scode with your OWN key, you should 
pass message='true'

if this message has been saved into struts scope using 
ExceptionHandler.saveException() method, you can pass message = 'false'


regards,
Sunny.




Erik Weber wrote:

>> 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!
>


Re: html:errors and manual iterate

Posted by Erik Weber <er...@mindspring.com>.
StrutsUser, weren't you are part of this earlier Thread?

http://www.mail-archive.com/user%40struts.apache.org/msg15734.html

Maybe that was a different Struts user. Also this might help (Sorry, 
mail-archive.com doesn't go back this far. It also has a crappy search, 
but that's another thread).

Hope this helps,

Erik




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:Joe@Germuska.com]
>
> 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



StrutsUser wrote:

> Martin,
> I need to manually iterate through the messages to find out if the 
> message is empty or not in the JSP.
> Thanks,
> Leonard
> ----- Original Message ----- From: "Laconia Data Systems" 
> <we...@laconiadatasystems.com>
> To: "Struts Users Mailing List" <us...@struts.apache.org>
> Sent: Saturday, December 11, 2004 5:37 AM
> Subject: Re: html:errors and manual iterate
>
>
>> Leonard-
>> The Action class getErrors() method returns the contents of 
>> ActionErrors or
>> creates new ActionMessages object
>> http://struts.apache.org/api/org/apache/struts/action/Action.html
>> Is this what you're looking for?
>> Martin-
>> ----- Original Message ----- From: "StrutsUser" <bi...@verizon.net>
>> To: <us...@struts.apache.org>
>> Sent: Saturday, December 11, 2004 8:19 AM
>> Subject: html:errors and manual iterate
>>
>>
>> I have a situation in which I have to add an ActionError without a 
>> message
>> (use it to indicate field in error on the page). If I use the generic
>> html:errors tag, it displays lineitems without a message. Is there a 
>> way to
>> iterate over html:errors to check that a message should be displayed 
>> only if
>> the message is not empty.
>> Thanks in advance for any suggestions,
>> Leonard
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: html:errors and manual iterate

Posted by StrutsUser <bi...@verizon.net>.
Martin,
I need to manually iterate through the messages to find out if the message 
is empty or not in the JSP.
Thanks,
Leonard
----- Original Message ----- 
From: "Laconia Data Systems" <we...@laconiadatasystems.com>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Saturday, December 11, 2004 5:37 AM
Subject: Re: html:errors and manual iterate


> Leonard-
> The Action class getErrors() method returns the contents of ActionErrors 
> or
> creates new ActionMessages object
> http://struts.apache.org/api/org/apache/struts/action/Action.html
> Is this what you're looking for?
> Martin-
> ----- Original Message ----- 
> From: "StrutsUser" <bi...@verizon.net>
> To: <us...@struts.apache.org>
> Sent: Saturday, December 11, 2004 8:19 AM
> Subject: html:errors and manual iterate
>
>
> I have a situation in which I have to add an ActionError without a message
> (use it to indicate field in error on the page). If I use the generic
> html:errors tag, it displays lineitems without a message. Is there a way 
> to
> iterate over html:errors to check that a message should be displayed only 
> if
> the message is not empty.
> Thanks in advance for any suggestions,
> Leonard
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: html:errors and manual iterate

Posted by Laconia Data Systems <we...@laconiadatasystems.com>.
Leonard-
The Action class getErrors() method returns the contents of ActionErrors or
creates new ActionMessages object
http://struts.apache.org/api/org/apache/struts/action/Action.html
Is this what you're looking for?
Martin-
----- Original Message ----- 
From: "StrutsUser" <bi...@verizon.net>
To: <us...@struts.apache.org>
Sent: Saturday, December 11, 2004 8:19 AM
Subject: html:errors and manual iterate


I have a situation in which I have to add an ActionError without a message
(use it to indicate field in error on the page). If I use the generic
html:errors tag, it displays lineitems without a message. Is there a way to
iterate over html:errors to check that a message should be displayed only if
the message is not empty.
Thanks in advance for any suggestions,
Leonard


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org