0

I have some simple navigation using primefaces menu. However I have jsf websockets on both pages. This causes a NullPointerException when navigating between pages. When navigating to Portfolio if there are websockets present in the Portfolio page the NullPointerException is returned when attempting to navigate to it and back to the Stocks page. If I remove all of the websockets from the Portfolio page, then the navigation kind of works - the first click causes the below exception but the second works. If I remove all websockets from both pages the navigation works without issue, but obviously I need the websockets for the page functionality.

EDIT: I've now made a minimal reproducible example and have changed the code below. Note that h:commandLink are included and they also cause the same issue when selecting page2.

java.lang.NullPointerException
at com.sun.faces.push.WebsocketFacesListener.processEvent(WebsocketFacesListener.java:118)
at javax.faces.event.SystemEvent.processListener(SystemEvent.java:147)
at javax.faces.event.ComponentSystemEvent.processListener(ComponentSystemEvent.java:134)
at com.sun.faces.application.ApplicationImpl.processListenersAccountingForAdds(ApplicationImpl.java:2340)
at com.sun.faces.application.ApplicationImpl.invokeViewListenersFor(ApplicationImpl.java:2158)
at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:337)
at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:292)
at javax.faces.application.ApplicationWrapper.publishEvent(ApplicationWrapper.java:748)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:113)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:223)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:671)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1580)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:338)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.glassfish.tyrus.servlet.TyrusServletFilter.doFilter(TyrusServletFilter.java:305)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:250)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:652)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:591)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:371)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:238)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:463)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:168)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:242)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:539)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:593)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:573)
at java.lang.Thread.run(Thread.java:748)

This is my menu page:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://xmlns.jcp.org/jsf/html"
  xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
  xmlns:p="http://primefaces.org/ui"
  xmlns:f="http://xmlns.jcp.org/jsf/core">
<f:view>
<h:head>
</h:head>

<h:body>

    <div class="column side">
        <h2>Side</h2>
        <h:form>
            <h:commandLink value="Page1" actionListener="#{menuViewTest.selectPageOne}" />
            <h:commandLink value="Page2" actionListener="#{menuViewTest.selectPageTwo}" />
        </h:form>
    </div>

    <div class="column middle">
        <h2>Middle</h2>
            <ui:include src="#{menuViewTest.view}">
            </ui:include>
    </div>
</h:body>
</f:view>
</html>

Backing bean for MenuTest:

@Named("menuViewTest")
@SessionScoped
public class MenuViewTest implements Serializable {

private static final long serialVersionUID = -1015364935820045523L;
private String view;

public void selectPageOne() {
    setView("page1.xhtml");
}

public void selectPageTwo() {
    setView("page2.xhtml");
}

public String getView() {
    return view;
}

public void setView(String view) {
    this.view = view;
}

  public String getSelectPageOne(){
    return "page1.xhtml";
}

public String getSelectPageTwo(){
    return "page2.xhtml";
}

}

Page1:

<ui:composition  xmlns="http://www.w3.org/1999/xhtml"
          xmlns:h="http://xmlns.jcp.org/jsf/html"
          xmlns:f="http://xmlns.jcp.org/jsf/core"
          xmlns:p="http://primefaces.org/ui"
          xmlns:ui="http://xmlns.jcp.org/jsf/facelets">

<script type="text/javascript">

    function notifyListener(message, channel, event) {
        console.log("notifyListener message: " + message);
        console.log("notifyListener channel: " + channel);
        console.log("notifyListener event: " + event);
    }
</script>

<h2>Page 1</h2>

<f:websocket channel="notify" onmessage="notifyListener" />

</ui:composition>

Page 2:

<ui:composition  xmlns="http://www.w3.org/1999/xhtml"
             xmlns:h="http://xmlns.jcp.org/jsf/html"
             xmlns:f="http://xmlns.jcp.org/jsf/core"
             xmlns:p="http://primefaces.org/ui"
             xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<script type="text/javascript">

        function notifyListener(message, channel, event) {
        console.log("notifyListener message: " + message);
        console.log("notifyListener channel: " + channel);
        console.log("notifyListener event: " + event);
    }
</script>

<h2>Page 2</h2>

<f:websocket channel="notify2" onmessage="notifyListener" />
</ui:composition>
zobbo
  • 117
  • 2
  • 13
  • 1
    [mcve] please. And does it work if you navigate by plain jsf components? – Kukeltje May 14 '20 at 20:39
  • thanks Kukeltje. I have changed the code to make a minimal example that replicates the issue. As you will see using h:commandLink also replicates the issue – zobbo May 18 '20 at 16:49
  • 1
    Then please remove primefaces etc from the title, code and tags. Oh and html and h:head in an include is bad (wrong) design as it results in invalid html. https://stackoverflow.com/questions/4792862. might even be your real issue... – Kukeltje May 18 '20 at 17:44
  • Thanks. I can move my javascript to the body tags, but how do I include f:websocket if I don't have the body to set the tags, e.g. xmlns:f="http://xmlns.jcp.org/jsf/core is in the html tag attributes – zobbo May 19 '20 at 16:41
  • See the link in my previous comment. You can set the namespace declarations on other tags too – Kukeltje May 19 '20 at 16:45
  • ok I've used ui composition for both pages (see edited post) but I still get the exception, so it doesn't seem to be the issue – zobbo May 19 '20 at 17:31
  • It seems to be related to the jsf websockets, I had no issue with same code using primefaces sockets/push – zobbo May 19 '20 at 18:32
  • Ok, now we are getting somewhere.. And what if you remove the `p:outputPanel` and the weird `h:outputLabel` before the `h:head` and what if you use an action instead of an actionLlistener? Or explicit navigation instead of via bean? And what is your explicit Mojarra version? – Kukeltje May 19 '20 at 19:35
  • If I remove the outputPanel I also have to remove the menuitems otherwise I get an error "Cannot find component for expression "optionPanel" . If I then remove the menuItems to fix that I get another error "MenuViewTest' does not have the property 'selectPageOne'". My Mojarra version is 2.3.2 – zobbo May 20 '20 at 13:56
  • You don't have any menu items in your code above and the error you get after removing them (whatever that is) cannot be caused by what is in the code above. Please run the code you post and post the code you run. And edit the question so the code in there matches 100% with what you run. – Kukeltje May 20 '20 at 14:14
  • ok I've updated the code to what I am running. I added getters to MenuViewTest and removed the optionPanel in the menu page. Now when I click on Page1 it's ok, clicking on Page2 causes the same websocket exception as in the original post. Thanks – zobbo May 20 '20 at 14:18
  • Just tested it and it works for me on WildFly 16 (Mojarra 2.3.9.SP01), No errors, No NPE etc... – Kukeltje May 20 '20 at 14:50
  • ok thanks, I'm on GlassFish 5 Mojarra 2.3.2 so maybe there is an issue there? – zobbo May 20 '20 at 14:55
  • 1
    No idea, I don't use it. Investigate.... Effectively you should have tried this on a latest GlassFish with the latest Mojarra before posting... Always a good thing to do and very easy if you have, like you do now, an [mcve]. Therefor always create one!... – Kukeltje May 20 '20 at 15:03
  • Thanks Kukeltje for your help, looks like I will try with the latest versions. Cheers. – zobbo May 20 '20 at 15:04
  • Moving to Glassfish 5.1.0 resolved the issue for the minimal reproducible example, however reverting back to use the primefaces menu still causes the issue., so a bit more investiation required, but I might just drop using the primefaces menu altogether. – zobbo May 21 '20 at 14:55
  • I've discovered that disabling ajax on the primefaces menu also resolves the socket crash so all issues are resolved now. Thanks – zobbo May 21 '20 at 15:09
  • Then create a new issue/question for this and lets investigate. Cannot see directly why using ajax would break it – Kukeltje May 21 '20 at 15:19
  • And create answr but make sure you explucitly mention the jsf version and implementstion – Kukeltje May 21 '20 at 15:21
  • I've created a new post https://stackoverflow.com/questions/61939673/jsf-2-3-websockets-throw-a-nullpointerexception-when-using-primefaces-menuitem-w – zobbo May 21 '20 at 16:54

1 Answers1

1

The websocket exception is fixed by upgrading to the latest stable release of Glassfish (5.1.0) JSF version 2.3 with mojarra 2.3.9.

zobbo
  • 117
  • 2
  • 13