Code: Select all
WARNING [http-nio-8080-exec-14] com.sun.faces.lifecycle.InvokeApplicationPhase.execute /book_add.xhtml @25,81 actionListener="#{bookBean.addBook}": java.lang.NullPointerException javax.el.ELException: /book_add.xhtml @25,81 actionListener="#{bookBean.addBook}": java.lang.NullPointerException
NotifyPush.java
Code: Select all
@PushEndpoint("/notify")
public class NotifyPush {
@OnMessage(encoders = {JSONEncoder.class})
public FacesMessage onMessage(FacesMessage message) {
return message;
}
}
Code: Select all
@ManagedBean(name = "bookBean")
@SessionScoped
public class BookBean implements Serializable{
private Book book = new Book();
private static List<Book> lstBook = new ArrayList();
public void addBook(ActionEvent event) {
this.lstBook.add(book);
notifyPUSH();
}
public void notifyPUSH() {
String summary = "Next Element";
String detail = "Add to List";
String CHANNEL = "/notify";
EventBus eventBus = EventBusFactory.getDefault().eventBus();
eventBus.publish(CHANNEL, new FacesMessage(StringEscapeUtils.escapeHtml3(summary), StringEscapeUtils.escapeHtml3(detail)));
}
//getters and setters
}
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Push Servlet</servlet-name>
<servlet-class>org.primefaces.push.PushServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>Push Servlet</servlet-name>
<url-pattern>/primepush/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/book_list.xhtml</welcome-file>
</welcome-file-list>
</web-app>
Code: Select all
<?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:p="http://primefaces.org/ui">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<h:form>
<h2>ADD BOOK</h2>
<p:panelGrid columns="3">
<p:outputLabel value="Code :" />
<p:inputText value="#{bookBean.book.code}"/>
<h:outputText value="   "/>
<p:outputLabel value="Title : " />
<p:inputText value="#{bookBean.book.name}"/>
<h:outputText value="   "/>
<p:outputLabel value="Num. Pages : " />
<p:inputText value="#{bookBean.book.numPages}"/>
<h:outputText value="   "/>
</p:panelGrid>
<p:commandButton value="Add" actionListener="#{bookBean.addBook}" />
</h:form>
</h:body>
Thanks for all