NPE with tomahawk t:swapImage

Splash Forums PrettyFaces Users NPE with tomahawk t:swapImage

This topic contains 9 replies, has 3 voices, and was last updated by  Christian Kaltepoth 6 years, 9 months ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #17825

    JonH
    Participant

    Hoping this is a simple config issue. I’m migrating a jsf 1.2 app from prettyfaces 1.2.6 to 3.1.0 and get an NPE when using t:swapImage. It doesn’t happen with all tomahawk tags, nor with t:swapImage using prettyfaces 1.2.6.

    INFO: Starting up Tomahawk on the RI-JSF-Implementation.

    Nov 23, 2010 4:53:28 AM org.apache.catalina.core.ApplicationDispatcher invoke

    SEVERE: Servlet.service() for servlet FacesServlet threw exception

    java.lang.NullPointerException

    at com.ocpsoft.pretty.PrettyContext.getCurrentInstance(PrettyContext.java:78)

    at com.ocpsoft.pretty.PrettyContext.getCurrentInstance(PrettyContext.java:67)

    at com.ocpsoft.pretty.faces.servlet.PrettyFacesWrappedResponse.encodeURL(PrettyFacesWrappedResponse.java:75)

    at org.apache.myfaces.renderkit.html.util.NonBufferingAddResource.writeJavaScriptReference(NonBufferingAddResource.java:114)

    at org.apache.myfaces.renderkit.html.util.DefaultAddResource$ScriptPositionedInfo.writePositionedInfo(DefaultAddResource.java:665)

    at org.apache.myfaces.renderkit.html.util.DefaultAddResource.writeWithFullHeader(DefaultAddResource.java:469)

    at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:364)

    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

    at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:113)

    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)

    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)

    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)

    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)

    at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:104)

    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)

    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)

    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)

    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:555)

    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)

    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)

    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)

    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)

    at java.lang.Thread.run(Thread.java:680)

    tomcat 6.0.29

    tomahawk 1.1.9

    prettyfaces-jsf12-3.1.0.jar

    web.xml

    <?xml version=”1.0″ encoding=”ISO-8859-1″?>

    <web-app xmlns=”http://java.sun.com/xml/ns/javaee&#8221;

    xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221;

    xsi:schemaLocation=”http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd

    version=”2.5″>

    <welcome-file-list>

    <welcome-file>index.jsf</welcome-file>

    </welcome-file-list>

    <servlet>

    <display-name>FacesServlet</display-name>

    <servlet-name>FacesServlet</servlet-name>

    <servlet-class>javax.faces.webapp.FacesServlet

    </servlet-class>

    <load-on-startup>1</load-on-startup>

    </servlet>

    <servlet-mapping>

    <servlet-name>FacesServlet</servlet-name>

    <url-pattern>*.jsf</url-pattern>

    </servlet-mapping>

    <filter>

    <filter-name>Pretty Filter</filter-name>

    <filter-class>com.ocpsoft.pretty.PrettyFilter</filter-class>

    </filter>

    <filter-mapping>

    <filter-name>Pretty Filter</filter-name>

    <url-pattern>/*</url-pattern>

    <dispatcher>FORWARD</dispatcher>

    <dispatcher>REQUEST</dispatcher>

    <dispatcher>ERROR</dispatcher>

    </filter-mapping>

    <filter>

    <filter-name>MyFacesExtensionsFilter</filter-name>

    <filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>

    </filter>

    <!– extension mapping for adding <script/>, <link/>, and other resource tags to JSF-pages –>

    <filter-mapping>

    <filter-name>MyFacesExtensionsFilter</filter-name>

    <servlet-name>FacesServlet</servlet-name>

    <dispatcher>REQUEST</dispatcher>

    <dispatcher>FORWARD</dispatcher>

    <dispatcher>ERROR</dispatcher>

    </filter-mapping>

    <filter-mapping>

    <filter-name>MyFacesExtensionsFilter</filter-name>

    <url-pattern>/faces/myFacesExtensionResource/*</url-pattern>

    <dispatcher>REQUEST</dispatcher>

    <dispatcher>FORWARD</dispatcher>

    <dispatcher>ERROR</dispatcher>

    </filter-mapping>

    </web-app>

    pretty-config.xml

    <pretty-config xmlns=”http://ocpsoft.com/prettyfaces/3.1.0&#8243;

    xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221;

    xsi:schemaLocation=”http://ocpsoft.com/prettyfaces/3.1.0

    http://ocpsoft.com/xml/ns/prettyfaces/ocpsoft-pretty-faces-3.1.0.xsd“>

    <url-mapping id=”home”>

    <pattern value=”/” />

    <view-id>/index.jsf</view-id>

    </url-mapping>

    </pretty-config>

    index.jsp

    <%@ taglib uri=”http://java.sun.com/jsf/core&#8221; prefix=”f” %>

    <%@ taglib uri=”http://java.sun.com/jsf/html&#8221; prefix=”h” %>

    <%@ taglib uri=”http://myfaces.apache.org/tomahawk&#8221; prefix=”t” %>

    <html>

    <f:view>

    <body>

    <t:swapImage

    id=”si1″

    url=”/prettyfaces3/images/dismiss.gif”

    swapImageUrl=”/prettyfaces3/images/dismiss_rollover.gif” />

    <h:form id=”loginForm”>

    <t:inputText id=”username” value=”#{userBean.username}” label=”User name”/>

    <t:inputText id=”pass” value=”#{userBean.password}” label=”Password” />

    <h:commandLink id=”loginbutton” action=”#{userBean.doLogin}”>Login</h:commandLink>

    </h:form>

    </body>

    </f:view>

    </html>

    Thanks

    #20440

    Seems like there is no FacesContext for this request. Which URL do you use to access the page?

    #20441

    Have you tried placing your MyFacesExtensionsFilter and Tomohawk filters *before* prettyfaces? It looks like MyFacesExtensionsFilter is asking PrettyFacesWrappedResponse to encode a URL when it is not in the JSF lifecycle. We should probably fix this to prevent NPEs in situations like this.

    #20442

    JonH
    Participant

    Thanks for the replies. I fixed my bad image urls quoted in the index.jsp above and moved the test to another page to simplify things.

    The NPE occurs whether the request is directly to the jsf or via the mapping eg

    TRACE; Nov 23, 2010 18:19:59 PM; tid:http-8080-1; PrettyFilter – Sending mapped request [/tomahawkTest] to resource [/tomahawkTest.jsf]

    Swapping prettyfaces to after the other filters had no effect.

    #20443

    I modified one of my test projects to reproduce this issue. You can download it here:

    https://github.com/chkal/prettyfaces-tests/tarball/swapimage

    The problem seems to be that the MyFaces extension filter calls encodeURL() on the HttpServletResponse that has been wrapped by PrettyFaces. PrettyFacesWrappedResponse tries to obtain the FacesContext which fails because the request hadn’t reached the FacesServlet at this point. Thus the FacesContext is unavailable.

    I think we should find some way to remove all references to the FacesContext from PrettyFacesWrappedResponse.

    Opinions?

    #20444

    I agree – this needs to be resolved by removing calls to FacesContext from PrettyFacesWrappedResponse, let’s discuss this on the dev list. I’ll file an issue.

    #20445
    #20446

    Hey JonH,

    I just committed a fix for this issue. In my tests <t:swapImage> is working fine now. Could you give the latests snapshot a try and test with your application?

    If you are using Maven, just set the version to 3.1.1-SNAPSHOT:

    <dependency>
    <groupId>com.ocpsoft</groupId>
    <artifactId>prettyfaces-jsf2</artifactId>
    <version>3.1.1-SNAPSHOT</version>
    </dependency>

    Please make also sure that you have the OcpSoft Maven Repository in your pom.xml:

    <repository>
    <id>ocpsoft</id>
    <name>OcpSoft</name>
    <url>http://ocpsoft.com/repository/</url>
    <releases>
    <enabled>true</enabled>
    </releases>
    <snapshots>
    <enabled>true</enabled>
    </snapshots>
    </repository>

    You can also directly download the latest snapshot here: prettyfaces-jsf12-3.1.1-20101211.190350-53.jar.

    It would be great to get your feedback so that we can make sure that this issue got correctly fixed!

    #20447

    JonH
    Participant

    Hi,

    I tested with the snapshot (the jsf12 version, as I mentioned in first post, we’re still a 1.2 shop) and t:swapImage is working. I actually eliminated our dependency on that tomahawk tag in the interim but I had since encountered the same exception when using t:tree2 which we want to continue to use and that works now as well so this helps a great deal.

    Thanks!

    #20448

    Perfect! Thank you very much for testing! I hope we will be able to ship PrettyFaces 3.2.0 this or next week! So stay tuned! :-)

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.

Comments are closed.