STRUTS: Problem with ActionMessages ! Please help !

Discussions

Web tier: servlets, JSP, Web frameworks: STRUTS: Problem with ActionMessages ! Please help !

  1. Hi all,

    My ActionMessages use to work perfectly, then about a week ago i only picked up that they stopped working, and now i cant find out what the problem is with them.

    Here is the code for creating them in my action class :

    ActionMessages messages = new ActionMessages();
    ActionMessage msg = new ActionMessage
                ("message.user.successfully.added");
    messages.add(ActionMessages.GLOBAL_MESSAGE, msg);
    saveMessages(servletRequest, messages);

    ----------------------------------------------------
    And in my jsp :

    <logic:messagesPresent message="true">
       <html:messages id="message" message="true">
          <bean:write name="message" />
       </html:messages>
    </logic:messagesPresent>

    ----------------------------------------------------

    Now when a user is added to the system to forwards back the the original page, and displays the message at the top.

    The first time the page is loaded everything works(no message yet) then the user gets added and forwarded back to the add page, but then the page crashes with the following message in jboss :

    12:49:17,812 INFO [ManageNewUserAction] created
    12:49:17,812 INFO [ManageNewUserAction] no errors
    12:49:17,812 INFO [ManageNewUserAction] hi3
    12:49:17,843 ERROR [Engine] ApplicationDispatcher[/webmodule] Servlet.service() for servlet jsp thre
    w exception
    javax.servlet.jsp.JspException: Cannot find bean message in any scope
            at org.apache.struts.taglib.TagUtils.lookup(TagUtils.java:992)
            at org.apache.struts.taglib.bean.WriteTag.doStartTag(WriteTag.java:227)
            at org.apache.jsp.mainLayout_jsp._jspx_meth_bean_write_0(mainLayout_jsp.java:425)
            at org.apache.jsp.mainLayout_jsp._jspService(mainLayout_jsp.java:257)
            at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
            at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
            at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
            at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)

    ------------------------------------------------------
    The messages is added to my request scope, so the problem is`nt there. And this message only comes up if the message is actually in the scope.

    I have no idea what to do anymore, any help would be appriciated.

    Rgds
    Derick
  2. Just had the same. First, check that all tags that you are using on the page, are properly declared on top of the page. Then turn on reporting for missing messages in your struts-config.xml: <message-resources null="false" /> If Struts is unable to find message, it will show something like ???KEY???. If you see this, that means that your property names are different from message IDs in your app.
  3. Yes this is spot on. We need to make sure that all keys that we adding to action messages are present in language.properties files. This will fix the problem.

    <message-resources parameter="content.Language" null="false"></message-resources>

    can show info of missing keys as pointed by previous post.