You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Satish Talim <sa...@hotmail.com> on 2004/09/25 05:30:53 UTC

ActionMessage and ActionMessages Problem

Hello,

I am using Struts 1.2.4 on JBoss 3.2.5.

In my ActionForm validate method, I have the following code -
    ActionErrors errors = new ActionErrors();
    ActionMessages messages = new ActionMessages();
    ActionMessage msg = null;
    if (getLoginID() == null || getLoginID().length() < 1)
    {
      msg = new ActionMessage("errors.loginID.required");
      messages.add(ActionMessages.GLOBAL_MESSAGE, msg);
      errors.add(ActionMessages.GLOBAL_MESSAGE, msg);
    }
    request.setAttribute("messages", messages);
    return errors;

I did this, since I don't want to use ActionErrors and ActionError (as these are deprecated). Now in my JSP view I want to display the message, but am not clear what I need to do. I tried the following, but it does not work ie. no messages are displayed on the screen.
<%@ taglib uri="http://struts.apache.org/tags-html-el" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-bean-el" prefix="bean" %>
    <html:messages id="messages" message="true">
      <li><bean:message name="messages"/></li>
    </html:messages>

What am I doing wrong and what's the right solution?

All help most appreciated.

Regards,

Satish Talim


Re: ActionMessage and ActionMessages Problem

Posted by Michael McGrady <mi...@michaelmcgrady.com>.
Mark Lowe wrote:

> Satish
>
> ActionErrors isn't deprecated, ActionError is...
>
> http://struts.apache.org/api/org/apache/struts/action/ActionErrors.html
>
> ActionErrors errors = new ActionErrors();
> errors.add("myproperty" , new ActionMessage(...));
> return errors;
>
>
> And then personally i prefer
>
> <html:errors property="myproperty" />
>
> But there are good reasons for preferring html:messages as you can 
> hide whole sections of unwanted html using them..
>
> Mark 


There is a good presentation at page 421 /et seq. /in Ted Husted's 
_Struts in Action_.  Unfortunately, despite the excellent quality of 
Manning books, the index in this one is not top notch.  Ted has a huge 
amount of goodly things you find only by reading the whole book rather 
than using it as a resource through the index.

Michael McGrrady


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


Re: ActionMessage and ActionMessages Problem

Posted by Mark Lowe <ma...@boxstuff.com>.
Satish

ActionErrors isn't deprecated, ActionError is...

http://struts.apache.org/api/org/apache/struts/action/ActionErrors.html

ActionErrors errors = new ActionErrors();
errors.add("myproperty" , new ActionMessage(...));
return errors;


And then personally i prefer

<html:errors property="myproperty" />

But there are good reasons for preferring html:messages as you can hide 
whole sections of unwanted html using them..

Mark

On 25 Sep 2004, at 17:17, Michael McGrady wrote:

> Sorry, left out the "ERRORS" sort of header.
>
> Michael McGrady
>
>                            
> <!--==========================================================
>                            ERRORS
>                            
> ===========================================================-->
>                            <logic:messagesPresent>
>                                <ul>
>                                    <html:messages id='error'>
>                                        <li>
>                                            <font size='+1'>
>                                                <bean:write 
> name='error'/>
>                                            </font>
>                                        </li>
>                                    </html:messages>
>                                </ul>
>                            </logic:messagesPresent>
>                            
> <!--==========================================================
>                            MESSAGES
>                            
> ===========================================================-->
>                            <logic:messagesPresent message='true'>
>                                <ul>
>                                    <html:messages id='message' 
> message='true'>
>                                        <li>
>                                            <font size='+1'>
>                                                <bean:write 
> name='message'/>
>                                            </font>
>                                        </li>
>                                    </html:messages>
>                                </ul>
>                            </logic:messagesPresent>
>
> Satish Talim wrote:
>
>> Hello,
>>
>> I am using Struts 1.2.4 on JBoss 3.2.5.
>>
>> In my ActionForm validate method, I have the following code -
>>    ActionErrors errors = new ActionErrors();
>>    ActionMessages messages = new ActionMessages();
>>    ActionMessage msg = null;
>>    if (getLoginID() == null || getLoginID().length() < 1)
>>    {
>>      msg = new ActionMessage("errors.loginID.required");
>>      messages.add(ActionMessages.GLOBAL_MESSAGE, msg);
>>      errors.add(ActionMessages.GLOBAL_MESSAGE, msg);
>>    }
>>    request.setAttribute("messages", messages);
>>    return errors;
>>
>> I did this, since I don't want to use ActionErrors and ActionError 
>> (as these are deprecated). Now in my JSP view I want to display the 
>> message, but am not clear what I need to do. I tried the following, 
>> but it does not work ie. no messages are displayed on the screen.
>> <%@ taglib uri="http://struts.apache.org/tags-html-el" prefix="html" 
>> %>
>> <%@ taglib uri="http://struts.apache.org/tags-bean-el" prefix="bean" 
>> %>
>>    <html:messages id="messages" message="true">
>>      <li><bean:message name="messages"/></li>
>>    </html:messages>
>>
>> What am I doing wrong and what's the right solution?
>>
>> All help most appreciated.
>>
>> Regards,
>>
>> Satish Talim
>>
>>
>>
>
>
>
> ---------------------------------------------------------------------
> 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: ActionMessage and ActionMessages Problem

Posted by Michael McGrady <mi...@michaelmcgrady.com>.
Sorry, left out the "ERRORS" sort of header.

Michael McGrady

                            
<!--==========================================================
                            ERRORS
                            
===========================================================-->
                            <logic:messagesPresent>
                                <ul>
                                    <html:messages id='error'>
                                        <li>
                                            <font size='+1'>
                                                <bean:write name='error'/>
                                            </font>
                                        </li>
                                    </html:messages>
                                </ul>
                            </logic:messagesPresent>
                            
<!--==========================================================
                            MESSAGES
                            
===========================================================-->
                            <logic:messagesPresent message='true'>
                                <ul>
                                    <html:messages id='message' 
message='true'>
                                        <li>
                                            <font size='+1'>
                                                <bean:write name='message'/>
                                            </font>
                                        </li>
                                    </html:messages>
                                </ul>
                            </logic:messagesPresent>

Satish Talim wrote:

>Hello,
>
>I am using Struts 1.2.4 on JBoss 3.2.5.
>
>In my ActionForm validate method, I have the following code -
>    ActionErrors errors = new ActionErrors();
>    ActionMessages messages = new ActionMessages();
>    ActionMessage msg = null;
>    if (getLoginID() == null || getLoginID().length() < 1)
>    {
>      msg = new ActionMessage("errors.loginID.required");
>      messages.add(ActionMessages.GLOBAL_MESSAGE, msg);
>      errors.add(ActionMessages.GLOBAL_MESSAGE, msg);
>    }
>    request.setAttribute("messages", messages);
>    return errors;
>
>I did this, since I don't want to use ActionErrors and ActionError (as these are deprecated). Now in my JSP view I want to display the message, but am not clear what I need to do. I tried the following, but it does not work ie. no messages are displayed on the screen.
><%@ taglib uri="http://struts.apache.org/tags-html-el" prefix="html" %>
><%@ taglib uri="http://struts.apache.org/tags-bean-el" prefix="bean" %>
>    <html:messages id="messages" message="true">
>      <li><bean:message name="messages"/></li>
>    </html:messages>
>
>What am I doing wrong and what's the right solution?
>
>All help most appreciated.
>
>Regards,
>
>Satish Talim
>
>
>  
>



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


Re: ActionMessage and ActionMessages Problem

Posted by Michael McGrady <mi...@michaelmcgrady.com>.
                            <logic:messagesPresent>
                                <ul>
                                    <html:messages id='error'>
                                        <li>
                                            <font size='+1'>
                                                <bean:write name='error'/>
                                            </font>
                                        </li>
                                    </html:messages>
                                </ul>
                            </logic:messagesPresent>
                            
<!--==========================================================
                            MESSAGES
                            
===========================================================-->
                            <logic:messagesPresent message='true'>
                                <ul>
                                    <html:messages id='message' 
message='true'>
                                        <li>
                                            <font size='+1'>
                                                <bean:write name='message'/>
                                            </font>
                                        </li>
                                    </html:messages>
                                </ul>
                            </logic:messagesPresent>

Satish Talim wrote:

>Hello,
>
>I am using Struts 1.2.4 on JBoss 3.2.5.
>
>In my ActionForm validate method, I have the following code -
>    ActionErrors errors = new ActionErrors();
>    ActionMessages messages = new ActionMessages();
>    ActionMessage msg = null;
>    if (getLoginID() == null || getLoginID().length() < 1)
>    {
>      msg = new ActionMessage("errors.loginID.required");
>      messages.add(ActionMessages.GLOBAL_MESSAGE, msg);
>      errors.add(ActionMessages.GLOBAL_MESSAGE, msg);
>    }
>    request.setAttribute("messages", messages);
>    return errors;
>
>I did this, since I don't want to use ActionErrors and ActionError (as these are deprecated). Now in my JSP view I want to display the message, but am not clear what I need to do. I tried the following, but it does not work ie. no messages are displayed on the screen.
><%@ taglib uri="http://struts.apache.org/tags-html-el" prefix="html" %>
><%@ taglib uri="http://struts.apache.org/tags-bean-el" prefix="bean" %>
>    <html:messages id="messages" message="true">
>      <li><bean:message name="messages"/></li>
>    </html:messages>
>
>What am I doing wrong and what's the right solution?
>
>All help most appreciated.
>
>Regards,
>
>Satish Talim
>
>
>  
>



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