Method Not Found ? This not made sense [duplicate] - jsf

This question already has answers here:
How to use PrimeFaces p:fileUpload? Listener method is never invoked or UploadedFile is null / throws an error / not usable
(11 answers)
Closed 5 years ago.
I'm trying to implement a FileUpload feature in a simple JSF/CDI project, with correct dependencies(i think) and the same code that i found in the primefaces showcase.
But for some reason, the FileUpload event does not found the listener in my ManagedBean.
I hope i can see something that i'm missing here, i already inspected the code a lot of times but i dont find anything that could be causing the problem.
My Xhtml page:
<html>
<h:head>
</h:head>
<body>
<h:form>
<p:fileUpload fileUploadListener="#{file.uploadHandler()}"
mode="advanced" dragDropSupport="false" update="messages"
sizeLimit="100000" fileLimit="3"
allowTypes="/(\.|\/)(gif|jpe?g|txt)$/" />
<p:growl id="messages" showDetail="true" />
</h:form>
</body>
</html>
My ManagedBean:
import javax.faces.view.ViewScoped;
import javax.inject.Named;
import org.primefaces.event.FileUploadEvent;
#Named
#ViewScoped
public class File implements Serializable {
private static final long serialVersionUID = -6644472075906217176L;
private String fileName;
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public void uploadHandler(FileUploadEvent event) {
System.out.println("Nome do Arquivo: " + event.getFile().getFileName());
}
}
My pom.file :
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.2.14</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>6.1</version>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
Console:
15:59:36,935 WARNING [javax.enterprise.resource.webcontainer.jsf.lifecycle] (default task-27) /index.xhtml #16,45 fileUploadListener="#{file.uploadHandler()}": Method not found: class timesheet.business.bean.File.uploadHandler(): javax.el.MethodNotFoundException: /index.xhtml #16,45 fileUploadListener="#{file.uploadHandler()}": Method not found: class timesheet.business.bean.File.uploadHandler()

You should specify the method reference in fileUpload component
<p:fileUpload fileUploadListener="#{file.uploadHandler}"
Please note that there should be no () after the method name.

Related

JSF problem. XML file does not appear to have any style information associated with it [duplicate]

This question already has answers here:
Opening JSF Facelets page shows "This XML file does not appear to have any style information associated with it."
(2 answers)
JSF returns blank/unparsed page with plain/raw XHTML/XML/EL source instead of rendered HTML output
(1 answer)
Closed 2 years ago.
I'm initiating in java jsf, I created an xhtml simple to show table in localhost but I am receiving this error "This XML file does not appear to have any style information associated with it. The document tree is shown below." I don't have any idea of to solve this. My project is very simple is only to display a jsf table with records of mysql table.
Below is my project.
Especialidade:
package itc.itcsystems.beans;
public class Especialidade
{
private int ID;
private String Especialidade;
public Especialidade()
{
}
public Especialidade(int ID, String Especialidade)
{
this.ID = ID;
this.Especialidade = Especialidade;
}
public int getID() {
return ID;
}
public void setID(int ID) {
this.ID = ID;
}
public String getEspecialidade() {
return Especialidade;
}
public void setEspecialidade(String Especialidade) {
this.Especialidade = Especialidade;
}
}
EspecialidadesDAO:
package itc.itcsystems.beans;
import java.io.Serializable;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
#ManagedBean
#SessionScoped
public class EspecialidadesDAO implements Serializable
{
public Connection conectar;
public Connection conectardb;
private static final long serialVersionUID = 1L;
public EspecialidadesDAO()
{
conectar = new Conectar_Banco_W00().getConnection();
}
public List<Especialidade> getEspecialidade()
{
String LISTHemog = "SELECT Especialidade "
+ "FROM Tabela_Especialidades_Medicas";
Connection conexao = null;
PreparedStatement pstm = null;
ResultSet rs = null;
ArrayList<Especialidade> medico = new ArrayList<Especialidade>();
try
{
conexao = new Conectar_Banco_W00().getConnection();
pstm = conexao.prepareStatement(LISTHemog);
rs = pstm.executeQuery();
while (rs.next())
{
Especialidade especialidade = new Especialidade();
especialidade.setEspecialidade(rs.getString("Especialidade"));
medico.add(especialidade);
}
Conectar_Banco_W00.fecharConexao(conexao, pstm, rs);
}
catch(SQLException e)
{
e.printStackTrace();
}
return medico;
}
}
TabelaEspecialidade:
<?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="https://www.w3.org/1999/xhtml"
xmlns:f="https://java.sun.com/jsf/core"
xmlns:h="https://java.sun.com/jsf/html">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<h:dataTable value="#{EspecialidadesDAO.getEspecialidade}" var="tipo" border="2">
<h:column>
<f:facet name="header">Escolha especialidade</f:facet>
#{EspecialidadesDAO.tipo}
</h:column>
</h:dataTable>
</h:body>
</html>
Dependencies:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>itc.itcsystems</groupId>
<artifactId>ITC_Systems_ClientesMedicos</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>ITC_Systems_ClientesMedicos</name>
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.2.20</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.sun.faces/jsf-impl -->
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.2.20</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet.jsp.jstl/jstl -->
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>7.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
The result of execution:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<html xmlns="https://www.w3.org/1999/xhtml" xmlns:f="https://java.sun.com/jsf/core" xmlns:h="https://java.sun.com/jsf/html">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<h:dataTable value="#{EspecialidadesDAO.getEspecialidade}" var="tipo" border="2">
<h:column>
<f:facet name="header">Escolha especialidade</f:facet>
#{EspecialidadesDAO.tipo}
</h:column>
</h:dataTable>
</h:body>
</html>```
Thanks in advance.

EventBusFactory JSF1073

I'm trying to implement logic in JSF that accepts parameters and then updates some output on the xhtml page. The following is all borrowed from the primefaces pushdata showcase
XHTML:
<f:view>
<h:form id="form">
<f:metadata>
<f:viewParam name="data" value="#{viewParamPush.data}" />
<f:event type="preRenderView" listener="#{viewParamPush.prerender}" />
</f:metadata>
<h:outputText id="out" value="#{viewParamPush.data}" style="font-size:16px" />
<p:socket onMessage="handleMessage" channel="/QR" />
<script type="text/javascript">
function handleMessage(data) {
$('#out').text(data);
}
</script>
</h:form>
</f:view>
ViewParamPush:
ManagedBean
#RequestScoped
public class ViewParamPush implements Serializable{
private String data;
public String getData() {
return data;
}
public void setData(String data) {
util.sysprint("setData " + data, true);
this.data = data;
}
public void prerender() {
util.sysprint("prerender", true);
EventBus eventBus = EventBusFactory.getDefault().eventBus();
util.sysprint("prerender2", true);
even
tBus.publish("/QR", data);
util.sysprint("prerender3", true);
}
}
ViewParamResource:
#PushEndpoint("/QR")
public class ViewParamResource {
#OnMessage(encoders = {JSONEncoder.class})
public String onMessage(String data) {
util.sysprint("ViewParamResource onMessage", true);
return StringEscapeUtils.escapeHtml4(data);
}
}
I get the following exception when eventBus.publish("/QR", data); is called. I understand what a null pointer is however I don't understand why publish("/QR", data); in this case is causing one. Is there something wrong with my syntax?
FATAL: JSF1073: javax.el.ELException caught during processing of RENDER_RESPONSE 6 : UIComponent-ClientId=, Message=/QR.xhtml #21,95 listener="#{viewParamPush.prerender}": java.lang.NullPointerException
FATAL: /QR.xhtml #21,95 listener="#{viewParamPush.prerender}": java.lang.NullPointerException
javax.el.ELException: /QR.xhtml #21,95 listener="#{viewParamPush.prerender}": java.lang.NullPointerException
I added *.xhtml to the url patterns in order to be able to call the script QR.xhtml?data=some data.. I assume that required in order to pass parameters to the script although I wonder if that affects the publish method
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
**<url-pattern>*.xhtml</url-pattern>**
</servlet-mapping>
Dependencies:
<dependencies>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>5.3</version>
</dependency>
<dependency>
<groupId>org.glassfish.extras</groupId>
<artifactId>appserv-rt</artifactId>
<version>3.1.1</version>
</dependency>
<!-- http://mvnrepository.com/artifact/org.atmosphere/atmosphere-runtime -->
<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-runtime</artifactId>
<version>2.4.4</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.marklogic</groupId>
<artifactId>java-client-api</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.primefaces.themes</groupId>
<artifactId>cupertino</artifactId>
<version>1.0.10</version>
</dependency>
<dependency>
<groupId>org.primefaces.extensions</groupId>
<artifactId>primefaces-extensions</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>com.helger</groupId>
<artifactId>ph-schematron</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
<version>2.1.7</version>
<exclusions>
<exclusion>
<groupId>bouncycastle</groupId>
<artifactId>bcprov-jdk14</artifactId>
</exclusion>
<exclusion>
<groupId>bouncycastle</groupId>
<artifactId>bcmail-jdk14</artifactId>
</exclusion>
<exclusion>
<groupId>org.bouncycastle</groupId>
<artifactId>bctsp-jdk14</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>net.sf.barcode4j</groupId>
<artifactId>barcode4j-light</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>net.glxn</groupId>
<artifactId>qrgen</artifactId> <!-- QR code support -->
<version>1.4</version>
</dependency>
</dependencies>
I've previously encountered this error. The reason for this failure is due to the Atmosphere version.
Then use it as below :
pom.xml
<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-runtime</artifactId>
<version>2.4.3</version>
</dependency>
<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-runtime-native</artifactId>
<version>2.4.3</version>
</dependency>
web.xml
<servlet>
<servlet-name>Push Servlet</servlet-name>
<servlet-class>org.primefaces.push.PushServlet</servlet-class>
<init-param>
<param-name>org.atmosphere.cpr.broadcasterCacheClass</param-name>
<param-value>org.atmosphere.cache.UUIDBroadcasterCache</param-value>
</init-param>
<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>
This way you can try. It works this for me.

PrimeFaces LazyDataModel#load() method not invoked anymore after adding OmniFaces

PrimeFaces LazyDataModel worked before adding OmniFaces jar into pom.xml.
It invokes load() method of LazyDataModel.
LazyPostDataModel.java
public class LazyPostDataModel extends LazyDataModel<Post> {
private PostService postService;
private PostCriteria postCriteria;
public LazyPostDataModel(PostService postService, PostCriteria postCriteria) {
this.postCriteria = postCriteria;
this.postService = postService;
}
#Override
public List<Post> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String,Object> filters) {
//other process
}
}
I just add the following dependency into pom.xml for OmniFaces. It does not invoke load() method .
<dependency>
<groupId>org.omnifaces</groupId>
<artifactId>omnifaces</artifactId>
<version>2.2</version>
</dependency>
post.xhtml
<h:form id="postTableForm">
<p:inputText value="#{ManagePostActionBean.postCriteria.name}"/>
<p:commandButton value="Search" action="#{ManagePostActionBean.search}" update="postTable"/>
<p:outputPanel id="listPanel">
<p:dataTable var="post" value="#{ManagePostActionBean.postDataModel}" id="postTable"
paginator="true" style="width:100%;" lazy="true"
rows="10"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="10, 20, 30, 40, 50, 100" rowIndexVar="index">
<p:column headerText="No" style="width:50px;">
<h:outputText value="#{index + 1}" />
</p:column>
<p:column headerText="Name">
<h:outputText value="#{post.name}" />
</p:column>
<p:column headerText="Description">
<h:outputText value="#{post.description}" />
</p:column>
</p:dataTable>
</p:outputPanel>
</h:form>
ManagePostActionBean.java
#Named(value = "ManagePostActionBean")
#ViewScoped
public class ManagePostActionBean {
#Inject
private PostService postService;
private LazyDataModel<Post> postDataModel;
private PostCriteria postCriteria;
public void onLoad() {
System.out.println("ManagePostActionBean Init....");
postCriteria = new PostCriteria();
postDataModel = new LazyPostDataModel(postService, postCriteria);
}
public LazyDataModel<Post> getPostDataModel() {
return postDataModel;
}
public PostCriteria getPostCriteria() {
return postCriteria;
}
public void setPostCriteria(PostCriteria postCriteria) {
this.postCriteria = postCriteria;
}
public void search() {
resetPagination();
postDataModel = new LazyPostDataModel(postService, postCriteria);
}
}
my environment is
JSF 2.2
Primefaces 5.0
JDK 1.7
apache-tomee-webprofile-1.7.3 (TomEE)
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mutu</groupId>
<artifactId>spring-primefaces</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<repositories>
<repository>
<id>prime-repo</id>
<name>PrimeFaces Maven Repository</name>
<url>http://repository.primefaces.org</url>
<layout>default</layout>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.2.8-02</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.2.8-02</version>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>5.0</version>
</dependency>
<dependency>
<groupId>org.primefaces.themes</groupId>
<artifactId>all-themes</artifactId>
<version>1.0.10</version>
</dependency>
<dependency>
<groupId>org.primefaces.themes</groupId>
<artifactId>green-cool</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.8</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.8.1</version>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>2.4.1</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.omnifaces</groupId>
<artifactId>omnifaces</artifactId>
<version>2.2</version>
</dependency>
</dependencies>
</project>
You're using TomEE 1.x, which ships with JSF 2.1 (Apache MyFaces).
OmniFaces 2.2 requires JSF 2.2.
You have 2 options:
Downgrade to OmniFaces 2.1. Even though OmniFaces 2.x officially requires JSF 2.2, OmniFaces versions 2.0 and 2.1 do not have deploy time JSF 2.2 dependencies. OmniFaces version 2.2 was with <o:viewAction> tag the first version to require JSF 2.2 during deploy time.
Upgrade to TomEE 7.x, the first version to implement Java EE 7 and thus inherently JSF 2.2. It's currently only available as M1 release. Final release is expected within months.

Primefaces push - not reaching endpoint

I have problems with my maven web application implementing primefaces push. I can't figure out why, but I'm not reaching my endpoint.
I'm running on,
Tomcat 7.0.59
Java EE 6 Web
PrimeFaces 5.0
Atmosphere 2.1.3
JSF 2.2
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>feestnet_v3</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>feestnet_v3</name>
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.faces</artifactId>
<version>2.2.7</version>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>5.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.5.2</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId>
<version>2.5.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-runtime</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
<dependency>
<groupId>org.primefaces.themes</groupId>
<artifactId>all-themes</artifactId>
<version>1.0.10</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>6.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<url>http://repository.primefaces.org/</url>
<id>PrimeFaces-maven-lib</id>
<layout>default</layout>
<name>Repository for library PrimeFaces-maven-lib</name>
</repository>
<repository>
<id>prime-repo</id>
<name>Prime Repo</name>
<url>http://repository.primefaces.org</url>
<layout>default</layout>
</repository>
</repositories>
MailObserver.java (pushing the message)
package nv.messaging;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ActionEvent;
import org.primefaces.push.EventBus;
import org.primefaces.push.EventBusFactory;
#ManagedBean
#SessionScoped
public class MailObserver implements Serializable{
private int toId;
private int fromId;
private String title;
private String message;
public String inboxText;
public String htmlMessage;
public MailObserver(){
inboxText = "Inbox";
htmlMessage = "Test message";
}
public void pushMessage(ActionEvent event){
EventBus eventBus = EventBusFactory.getDefault().eventBus();
eventBus.publish("/message", htmlMessage);
System.out.println("Message sent");
}
public void update() {
}
public String getInboxText() {
return inboxText;
}
public void setInboxText(String inboxText) {
this.inboxText = inboxText;
}
public int getToId() {
return toId;
}
public void setToId(int toId) {
this.toId = toId;
}
public int getFromId() {
return fromId;
}
public void setFromId(int fromId) {
this.fromId = fromId;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getHtmlMessage() {
return htmlMessage;
}
public void setHtmlMessage(String htmlMessage) {
this.htmlMessage = htmlMessage;
}
}
MailEndpoint.java
import org.primefaces.push.annotation.OnMessage;
import org.primefaces.push.annotation.PushEndpoint;
import org.primefaces.push.impl.JSONEncoder;
#PushEndpoint(value = "/message")
public class MailEndpoint {
#OnMessage(encoders = {JSONEncoder.class})
public String onMessage(String message) {
System.out.println("Mail endpoint reached : " + message);
return message;
}
}
for completeness
layout.xhtml
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<f:view contentType="text/html">
<h:head>
<style>
.ui-layout-resizer{
background-color: black;
}
</style>
<f:facet name="first">
<meta content='text/html; charset=UTF-8' http-equiv="Content-Type"/>
<title>PrimeFaces</title>
</f:facet>
</h:head>
<h:body>
<f:metadata>
<f:event type="preRenderView" listener="#{security.securePage()}"/>
<f:event type="preRenderView" listener="#{security.authorisation('ALL')}"/>
</f:metadata>
<p:layout fullPage="true">
<p:layoutUnit position="north" size="100" resizable="true" closable="true" collapsible="true" gutter="1">
Header
<p:socket channel="/message" onMessage="handleMessage" ></p:socket>
</p:layoutUnit>
<p:layoutUnit position="south" size="100" closable="true" collapsible="true" gutter="1">
Footer
</p:layoutUnit>
<p:layoutUnit position="west" size="auto" header="Left" collapsible="true" gutter="1">
<p:menu>
<p:submenu label="Resources">
<p:menuitem value="Message" url="/secure/messages/message.xhtml" />
<p:menuitem value="Documentation" url="http://www.primefaces.org/documentation.html" />
<p:menuitem value="Forum" url="http://forum.primefaces.org/" />
<p:menuitem value="Themes" url="http://www.primefaces.org/themes.html" />
</p:submenu>
</p:menu>
</p:layoutUnit>
<p:layoutUnit position="center">
<ui:insert name="content">Put default content here, if any.</ui:insert>
</p:layoutUnit>
</p:layout>
<script type="text/javascript" >
function handleMessage(data) {
console.log(data);
}
</script>
</h:body>
</f:view>
</html>
I think I should see a message in the output from MailEndpoint but, I only get the message from MailObserver.pushMessage. Any ideas on what is going on?
I found the problem. I changed the wrong web.xml. To make it work, you need to add this to web.xml
<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>

How to connect command button to action handler in PrimeFaces mobile rendering mode?

I have a PrimeFaces page with following form:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:pm="http://primefaces.org/mobile">
<f:view renderKitId="PRIMEFACES_MOBILE"/>
<h:head>
</h:head>
<h:body>
<pm:page>
<pm:header title="Test"></pm:header>
<pm:content>
<p:panel header="Login">
<h:form>
<pm:field>
<p:outputLabel for="basic" value="User:"/>
<p:inputText id="basic"/>
</pm:field>
<pm:field>
<p:outputLabel for="password" value="Password:"/>
<p:password id="password"/>
</pm:field>
<p:commandButton value="Login" type="button"
actionListener="#{index.loginButtonAction}"/>
</h:form>
</p:panel>
</pm:content>
</pm:page>
</h:body>
</html>
And I have the class IndexView defined as follows.
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
#ManagedBean(name = "index")
#RequestScoped
public class IndexView {
public void loginButtonAction(ActionEvent actionEvent)
{
System.out.println("loginButtonAction");
addMessage("loginButtonAction");
}
public void registerButtonAction(ActionEvent actionEvent)
{
System.out.println("registerButtonAction");
addMessage("registerButtonAction");
}
public void addMessage(String summary) {
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, summary, null);
FacesContext.getCurrentInstance().addMessage(null, message);
}
}
When I press the Login button, nothing happens. I don't even see the message in the logs.
What do I need to change in order for loginButtonAction action to be called, when the button has been pressed?
The dependencies from my pom.xml file look are these:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.1</version>
<scope>test</scope>
</dependency>
<!-- PrimeFaces (start) -->
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>5.1</version>
</dependency>
<!-- PrimeFaces (end) -->
<!-- JSF 2 (start) -->
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1.11</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.1.11</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
</dependency>
<!-- JSF 2 (end) -->
</dependencies>
Try removing
type="button"
From your commandButton. As long as its type is button it would only be clickable and won't send form data to the server.

Resources