You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Otávio Augusto <ot...@bol.com.br> on 2004/01/07 06:47:05 UTC

messages

I'm able to send error messages to my jsp whenever needed. but how to i send confirmation messages (for instance "Your mail has been sent") ? is there a way similar to the ActionErrors method?

thanks 


Otávio Augusto

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


Re: messages

Posted by "Camron G. Levanger" <ca...@dreamlabmedia.com>.
There is an ActionMessage Package, If i remember correctly.  I think 
Action Errors maybe even Extends it.

Camron G. Levanger
The Dreamlab
www.dreamlabmedia.com
(866) 890-3705
On Jan 6, 2004, at 11:11 PM, Otávio Augusto wrote:

> That means there is an ActionMessages ?
>
> Otávio Augusto
>
> On Wed, 7 Jan 2004 11:41:08 +0530
> "Mohan Radhakrishnan" <mr...@cellexchange.com> wrote:
>
>> I just use ActionErrors for everything but I am guessing that it is
>> html:errors for errors
>> and html:messages for messages.
>>
>> Mohan
>>
>> -----Original Message-----
>> From: Otávio Augusto [mailto:otavio.augusto@bol.com.br]
>> Sent: Wednesday, January 07, 2004 11:17 AM
>> To: struts-user@jakarta.apache.org
>> Subject: messages
>>
>>
>> I'm able to send error messages to my jsp whenever needed. but how to 
>> i send
>> confirmation messages (for instance "Your mail has been sent") ? is 
>> there a
>> way similar to the ActionErrors method?
>>
>> thanks
>>
>>
>> Otávio Augusto
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>

Re: messages

Posted by Otávio Augusto <ot...@bol.com.br>.
That means there is an ActionMessages ?

Otávio Augusto

On Wed, 7 Jan 2004 11:41:08 +0530
"Mohan Radhakrishnan" <mr...@cellexchange.com> wrote:

> I just use ActionErrors for everything but I am guessing that it is
> html:errors for errors
> and html:messages for messages.
> 
> Mohan
> 
> -----Original Message-----
> From: Otávio Augusto [mailto:otavio.augusto@bol.com.br]
> Sent: Wednesday, January 07, 2004 11:17 AM
> To: struts-user@jakarta.apache.org
> Subject: messages
> 
> 
> I'm able to send error messages to my jsp whenever needed. but how to i send
> confirmation messages (for instance "Your mail has been sent") ? is there a
> way similar to the ActionErrors method?
> 
> thanks
> 
> 
> Otávio Augusto
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 

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


RE: messages

Posted by Mohan Radhakrishnan <mr...@cellexchange.com>.
I just use ActionErrors for everything but I am guessing that it is
html:errors for errors
and html:messages for messages.

Mohan

-----Original Message-----
From: Otávio Augusto [mailto:otavio.augusto@bol.com.br]
Sent: Wednesday, January 07, 2004 11:17 AM
To: struts-user@jakarta.apache.org
Subject: messages


I'm able to send error messages to my jsp whenever needed. but how to i send
confirmation messages (for instance "Your mail has been sent") ? is there a
way similar to the ActionErrors method?

thanks


Otávio Augusto

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


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


RE: messages

Posted by Richard Hightower <rh...@arc-mind.com>.
ActionMessages, saveMessages and getResources oh my!

Back in the primordial ooze of Struts pre-1.1, people liked ActionErrors.
They started using them for tasks for which they were never intended. People
started using ActionErrors as a general-purpose way to display i18n-enabled
dynamic messages. Then Struts 1.1 added the concept of ActionMessages. If
you recall from our ActionErrors discussion in Chapter 10, "Managing
Errors," ActionErrors subclass ActionMessages. Now you can use
ActionMessages to display dynamic i18n-enabled messages without feeling like
a hack.

Working with ActionMessages is nearly identical to working with
ActionErrors. Here is an example of adding ActionMessages that you want to
be displayed inside an Actions Execute method:

    public ActionForward execute(
        ActionMapping mapping,
        ActionForm form,
        HttpServletRequest request,
        HttpServletResponse response)
        throws Exception {

        ActionMessages messages = new ActionMessages();



        ActionMessage message = new ActionMessage("inputForm.greet");
        messages.add(ActionMessages.GLOBAL_MESSAGE, message);

        ...
        saveMessages(request,messages);
        ...

Then to display the messages in the JSP, you use the html:messages tag as
follows:

<ul>
<font color='green' >
<html:messages id="message" message="true">
  <li><%= message %></li>
</html:messages>
</font>
</ul>

The html:messages tag will iterate over all of the messages. Notice that the
message attribute of html:messages is set to true. This forces html:messages
to get the messages from Globals.MESSAGE_KEY in request scope. If you do not
set the message attribute, the html:messages tag will display the errors
instead (Globals.ERROR_KEY).
What if you want to display an arbitrary number of messages—and it could
vary by locale? In that case, you use getResources to get the number of
messages for that locale:

    public ActionForward execute(
        ActionMapping mapping,
        ActionForm form,
        HttpServletRequest request,
        HttpServletResponse response)
        throws Exception {

        ActionMessages messages = new ActionMessages();



        ActionMessage message = new ActionMessage("inputForm.greet");
        messages.add(ActionMessages.GLOBAL_MESSAGE, message);

        String num =
            this.getResources(request).getMessage("inputForm.messageNum");

        int messageCount = Integer.parseInt(num);
        for(int index=0; index<messageCount; index++){
            String messageKey="inputForm.message" + index;
            message = new ActionMessage(messageKey);
            messages.add(ActionMessages.GLOBAL_MESSAGE, message);
        }
        saveMessages(request,messages);

        System.out.println(Globals.MESSAGE_KEY);
        if (messages ==
             request.getAttribute(Globals.MESSAGE_KEY)){
           System.out.println("its there can't you see it");
        }
       ...
The previous code corresponds to the following resource bundle entries:
inputForm.greet=Hello Welcome to Trivera Technologies
inputForm.messageNum=2
inputForm.message0=Please be sure to fill out your phone ...
inputForm.message1=Pick a user name and password you can remember


The inputForm.messageNum method specifies the number of messages for the
inputForm. The for loop iterates up to the count of messages, grabbing each
message for inputForm—that is, inputForm.message0, inputForm.message1, and
so on.
These examples cause the messages in the resource bundle to display in an
unordered list at the top of the input JSP page.
The RequestUtils class has a method called getActionMessages() that is used
by logic:messagePresent and html:messages. The getActionMessages method
allows you to retrieve the messages saved by Action.saveMessages and
Action.saveErrors.

Rick Hightower
Developer

Struts/J2EE training -- http://www.arc-mind.com/strutsCourse.htm

Struts/J2EE consulting --
http://www.arc-mind.com/consulting.htm#StrutsMentoring

-----Original Message-----
From: Otávio Augusto [mailto:otavio.augusto@bol.com.br]
Sent: Tuesday, January 06, 2004 10:47 PM
To: struts-user@jakarta.apache.org
Subject: messages


I'm able to send error messages to my jsp whenever needed. but how to i send
confirmation messages (for instance "Your mail has been sent") ? is there a
way similar to the ActionErrors method?

thanks


Otávio Augusto

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



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