Using ActionMessages in struts

Discussions

Web tier: servlets, JSP, Web frameworks: Using ActionMessages in struts

  1. Using ActionMessages in struts (2 messages)

    Hi!
    In my Action class I have the following piece of code:
    -----------------------------------------------------
    ActionMessages messages = new ActionMessages();
    messages.add("message",
           new ActionMessage("actioinMessage.updateSuccess"));
    saveMessages(request,messages);
    return actionMapping.findForward("success");

    ------------------------------------------------------
    In the ApplicationResources.properties I have:
    actioinMessage.updateSuccess= Successfully Updated

    My problem is how display this message in a JSP, i.e, in a JSP page how to access the action-messages stored in the request.
    RamPrasad.
  2. <logic:messagesPresent message="message">
                Messages:
                
                    <html:messages id="message">
                      
    • <bean:write name="message"/>
    •               </html:messages>
                  
    <hr>
     </logic:messagesPresent>

    "message" refers to the name of the attribute of the ActionMessages in the request. Here, we conditionally display some HTML if these messages are there, and then display the messages as an unordered list. The <html:messages/> tag iterates through the messages.
  3. Suppose u have code like below
    ActionMessages messages = new ActionMessages();
    ActionMessage msg = new ActionMessage("data.ok");
    messages.add("message1", msg);

    msg = new ActionMessage("data.continue");
    messages.add("message2", msg);

    saveMessages(request, messages);

    and in the resource file u have message values like

    data.ok=Data saved successfully
    data.continue=Please continue

    U can display messages in JSP as

    <html:messages id="msg" message="true">
    <bean:write name="msg"/><br>
    </html:messages>


    Refer this link for simple Example http://javaboutique.internet.com/tutorials/excep_struts/index-2.html