• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 575
  • Last Modified:

struts bean write tag cannot find the bean while iterating messages

Hi, I am having trouble using <bean:write> while iterating <html:messages>, any help is appreciated.

The following prints "foobar", that means there is a message with property "nameTooShort".
                           <logic:messagesPresent message="true">
                              foo
                             <html:messages id="msg" property="nameTooShort" message="true">
                              bar
                             </html:messages>
                           </logic:messagesPresent>
                         </td></tr>

However, the following gives an exception that the bean "msg" cannot be found in any scope:
                           <logic:messagesPresent message="true">
                              foo
                             <html:messages id="msg" property="mrn" message="true">
                                 bar
                                <bean:write name="msg"/>
                             </html:messages>
                           </logic:messagesPresent>

javax.servlet.ServletException: Cannot find bean msg in any scope
        at org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
        at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
        at org.apache.jsp.secure.patient.search_005fc_jsp._jspService(search_005fc_jsp.java:237)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
        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:802)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
        at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:704)
0
kkealoha
Asked:
kkealoha
  • 2
  • 2
1 Solution
 
kkealohaAuthor Commented:
Sorry, had a typo, so reposting.....
Hi, I am having trouble using <bean:write> while iterating <html:messages>, any help is appreciated.

The following prints "foobar", that means there is a message with property "nameTooShort".
                           <logic:messagesPresent message="true">
                              foo
                             <html:messages id="msg" property="nameTooShort" message="true">
                              bar
                             </html:messages>
                           </logic:messagesPresent>
                         </td></tr>

However, the following gives an exception that the bean "nameTooShort" cannot be found in any scope:
                           <logic:messagesPresent message="true">
                              foo
                             <html:messages id="msg" property="nameTooShort" message="true">
                                 bar
                                <bean:write name="msg"/>
                             </html:messages>
                           </logic:messagesPresent>

javax.servlet.ServletException: Cannot find bean msg in any scope
        at org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
        at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
        at org.apache.jsp.secure.patient.search_005fc_jsp._jspService(search_005fc_jsp.java:237)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
        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:802)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
        at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:704)
0
 
suprapto45Commented:
Hi,

How do you send your "nameTooShort" from your ActionForm or Action?

Regards
Dave

0
 
kkealohaAuthor Commented:
I am doing the following:

        ActionMessages msgs = new ActionMessages ();
        msgs.add ("nameTooShort", new ActionMessage ("error.psearch.nametooshort"));
        saveMessages (request, msgs);
        return mapping.findForward (C.Forward.PATIENT_SEARCH);

Your question made me look at my code in more detail, I had a spelling error in the property name "nameTooShort" in the MessageResources.properties file.  All works fine now.  Thanks.
0
 
suprapto45Commented:
Hi,

Glad you can solve it by yourself.

Regards
Dave
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now