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