This problem affected me on my current project, but only when I viewed
pages that weren't processed by Struts and were processed by SiteMesh.
In other works, messages.jsp pukes when it doesn't find Struts 2's
ValueStack in the request.  To fix it, I used:

<% if (request.getAttribute("struts.valueStack") != null) { %>
<s:if test="hasActionErrors()">
   <div class="error" id="errorMessages">
     <s:iterator value="actionErrors">
       <img src="<c:url value="${contentdir}/images/iconWarning.gif"/>"
           alt="<fmt:message key="icon.warning"/>" class="icon" />
       <s:property escape="false"/><br />
     </s:iterator>
  </div>
</s:if>

<s:if test="hasFieldErrors()">
   <div class="error" id="errorMessages">
     <s:iterator value="fieldErrors">
         <s:iterator value="value">
           <img src="<c:url value="${contentdir}/images/iconWarning.gif"/>"
               alt="<fmt:message key="icon.warning"/>" class="icon" />
            <s:property escape="false"/><br />
         </s:iterator>
     </s:iterator>
  </div>
</s:if>
<% } %>

I think this is a bug and we should probably enter something in Struts' JIRA.

Matt


On 3/13/07, Tim Azzopardi <[EMAIL PROTECTED]> wrote:

This post shows a fix/workaround for a problem I had with my appfuse 1.9.4
application modified to use struts2.0.1 (and ultimately 2.0.6) instead of
webwork. (But I do not understand why appfuse2 does not have this problem.)
Fast forward to option [4] at the end for the fix.

Other configuration: Using iBatis and postgres. Using a heavily modified
xhtml theme. JDK5 and JDK6 give same results.

My app seemed to be working ok.

Then I noticed that, when using sitemesh with struts 2, you are supposed to
use the struts-cleanup (ActionContextCleanUp) filter as described here:
http://struts.apache.org/2.x/docs/sitemesh-plugin.html

And I noticed appfuse2 was doing this in web.xml. So I dutifully changed
web.xml to include struts-cleanup.

My app started up ok, but every page I visited gave this set of stack traces

        [myapp] ERROR [http-80-Processor25] [jsp].invoke(704) | 
Servlet.service()
for servlet jsp threw exception
        java.lang.NullPointerException
                at 
org.apache.struts2.views.jsp.TagUtils.getStack(TagUtils.java:56)
                at
org.apache.struts2.views.jsp.StrutsBodyTagSupport.getStack(StrutsBodyTagSupport.java:51)
                at
org.apache.struts2.views.jsp.ComponentTagSupport.doStartTag(ComponentTagSupport.java:42)
                at 
org.apache.jsp.error_jsp._jspx_meth_s_if_0(error_jsp.java:224)
                at org.apache.jsp.error_jsp._jspService(error_jsp.java:120)
                at 
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
                at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
                ...
                at
org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:499)
                at
org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:966)
                at
org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:602)
                at
com.opensymphony.module.sitemesh.taglib.page.ApplyDecoratorTag.doEndTag(ApplyDecoratorTag.java:256)
                at
org.apache.jsp._404_jsp._jspx_meth_page_applyDecorator_0(_404_jsp.java:152)
                at org.apache.jsp._404_jsp._jspService(_404_jsp.java:84)
                at 
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
                at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
                ...
                at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
                at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
                ...
                at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
                at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
                at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
                at
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
                ...
                at java.lang.Thread.run(Thread.java:619)
        [myapp] ERROR [http-80-Processor25] [jsp].invoke(704) | 
Servlet.service()
for servlet jsp threw exception
        java.lang.NullPointerException
                at 
org.apache.struts2.views.jsp.TagUtils.getStack(TagUtils.java:56)
                [same stack trace as above]

        org.apache.jasper.JasperException: Exception in JSP: 
/common/messages.jsp:2

        1: <%@ page language="java" isErrorPage="true" %>
        2: <%@ taglib uri="http://java.sun.com/jsp/jstl/core"; prefix="c" %>
        3: <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt"; prefix="fmt" %>
        4: <%@ taglib uri="/struts-tags" prefix="s" %>
        5:


        Stacktrace:
                at
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:512)
                ...
                at
org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:602)
                at
com.opensymphony.module.sitemesh.taglib.page.ApplyDecoratorTag.doEndTag(ApplyDecoratorTag.java:256)
                at
org.apache.jsp._404_jsp._jspx_meth_page_applyDecorator_0(_404_jsp.java:152)
                at org.apache.jsp._404_jsp._jspService(_404_jsp.java:84)
                ...
        [myapp] ERROR [http-80-Processor25] [jsp].invoke(704) | 
Servlet.service()
for servlet jsp threw exception
        java.lang.NullPointerException
                at 
org.apache.struts2.views.jsp.TagUtils.getStack(TagUtils.java:56)
                ...
        [myapp] ERROR [http-80-Processor25] [jsp].invoke(704) | 
Servlet.service()
for servlet jsp threw exception
        java.lang.NullPointerException
                at 
org.apache.struts2.views.jsp.TagUtils.getStack(TagUtils.java:56)
                ...
        14-Mar-2007 01:08:02 org.apache.catalina.core.StandardHostValve custom
        SEVERE: Exception Processing ErrorPage[errorCode=404, location=/404.jsp]
        org.apache.jasper.JasperException: Exception in JSP: 
/common/messages.jsp:2

        1: <%@ page language="java" isErrorPage="true" %>
        2: <%@ taglib uri="http://java.sun.com/jsp/jstl/core"; prefix="c" %>
        3: <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt"; prefix="fmt" %>
        4: <%@ taglib uri="/struts-tags" prefix="s" %>
        5:

        Stacktrace:
                at
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:512)
                at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
                at
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
                at 
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
                at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
                ...


(Notice the mention of 400_jsp and error_jsp in the stack traces above. Note
that with Strusts 2.0.6, the NPE occurs two lines later at
org.apache.struts2.views.jsp.TagUtils.getStack(TagUtils.java:58))

By trial and error, I worked out how different ways to get rid of this
problem culminating in an acceptable fix/workaround.

[1] In web.xml deleting the 404 mapping section removed the stacktraces.
    <error-page>
        <error-code>404</error-code>
        <location>/404.jsp</location>
    </error-page>

    But a real 404 then gives the standard tomcat 404 page. Not pretty.

[2] Instead of [1] replace contents of 404.jsp with
        404 Page not found
    Not pretty but it works

[3] Instead of [1] and [2] remove the following line from default.jsp (used
to decorate 404.jsp)
        <%@ include file="/common/messages.jsp" %>
    This works, but default.jsp is used to decorate pages other than 404.jsp
and those messages are needed somtimes.
    (Defining a seperate default-404.jsp decorator for specifically
decorating the 404 page is a possibilty)

[4] Instead of [1][2] or [3] replace the line in error.jsp
                <%@ include file="/common/messages.jsp" %>
    with
                <%
                   try {
                %>
                       <%@ include file="/common/messages.jsp" %>
                <%
                   } catch (Exception e) {
                       out.println("...");
                   }
                %>

I hope this may help anybody who comes across the same problem.





--
View this message in context: 
http://www.nabble.com/%28Fix-for%29-struts-tags-in-messages.jsp-causing-NPE-stack-trace-using-struts-cleanup-ActionContextCleanUp-tf3399814s2369.html#a9467306
Sent from the AppFuse - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




--
http://raibledesigns.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to