0

I want to update component from JSF bean .
but receive NullPointerException :

java.lang.NullPointerException
    at org.primefaces.PrimeFaces$Ajax.update(PrimeFaces.java:335)
    at org.primefaces.PrimeFaces$Ajax.update(PrimeFaces.java:359)
    at ir.moke.logmag.view.LogView.start(LogView.java:21)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.jboss.weld.injection.StaticMethodInjectionPoint.invoke(StaticMethodInjectionPoint.java:95)
    at [internal classes]
    at ir.moke.logmag.api.TestLog.addLog(TestLog.java:20)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.ibm.ws.jaxrs20.cdi.component.JaxRsFactoryImplicitBeanCDICustomizer.serviceInvoke(JaxRsFactoryImplicitBeanCDICustomizer.java:302)
    at [internal classes]    

this is my example code :

LogView.java

@SessionScoped
@Named
public class LogView implements Serializable {
    private String name;

    public void start(@Observes String name) {
        this.name = name;
        System.out.println("Receive : " + name);
        PrimeFaces.current().ajax().update("form:log");
    }

    public String getName() {
        return name;
    }
} 

TestLog.java

@Path("/log")
public class TestLog {

    @Inject
    private Event<String> event;

    @POST
    @Path("/add")
    public Response addLog(String name) {
        System.out.println("API " + name);
        event.fire(name);
        return Response.accepted().build();
    }
}

HTML

<h:body>
    <h:form id="form">
        <p:outputLabel value="Output : "/><br/>
        <p:outputLabel id="log" value="#{logView.name}"/>
    </h:form>
</h:body>    

I want to send message from rest api and update component on JSF page .
How can fix this problem ?

My environment :
Liberty 19.0.0.4
JavaEE 8
JSF 2.3

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
mah454
  • 1,571
  • 15
  • 38
  • 1
    Sorry, too quick.... The NPE IS in the PF code, but the cause can be found in another (real) duplicate. You cannot use PrimeFaces.current() in a non-jsf request (e.g. called from a CDI event). You need to use push here. Let me find a good dupliate. And please check the corrected title. That is what is actually happening – Kukeltje Jun 25 '19 at 09:50
  • I can not understand ! , why can not found clientId ? without cdi event do work without any problem . – mah454 Jun 25 '19 at 09:55
  • 2
    The problem is not that the client id cannot be found, it is that there is no JSF context. The way you should do this is in https://stackoverflow.com/questions/25947790/real-time-updates-from-database-using-jsf-java-ee – Kukeltje Jun 25 '19 at 09:58

0 Answers0