TextEditor component is marked secure='true' but the HTML Sanitizer was not found on the classpath - jsf

Error message:
TextEditor component is marked secure='true' but the HTML Sanitizer was not found on the classpath. Either add the HTML sanitizer to the classpath per the documentation or mark secure='false' if you would like to use the component without the sanitizer.
This is my pom.xml
<?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
https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.jsf</groupId>
<artifactId>showcase</artifactId>
<version>1.0.0</version>
<packaging>war</packaging>
<name>showcase</name>
<url>http://maven.apache.org</url>
<repositories>
<repository>
<id>prime-repo</id>
<name>Prime Repo</name>
<url>http://repository.primefaces.org</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>8.0.RC3</version>
</dependency>
<dependency>
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet-shaded</artifactId>
<version>3.1.3.Final</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>8.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>jakarta.faces</artifactId>
<version>2.3.14</version>
</dependency>
<dependency>
<groupId>jakarta.servlet.jsp.jstl</groupId>
<artifactId>jakarta.servlet.jsp.jstl-api</artifactId>
<version>1.2.7</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.10</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.1</version>
</dependency>
<dependency>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
<version>2.1.7</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<encoding>UTF-8</encoding>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.3</version>
<configuration>
<filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
</configuration>
</plugin>
</plugins>
</build>
</project>
textEditor.xhtml:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<h:outputStylesheet name="primeicons/primeicons.css" library="primefaces"/>
</h:head>
<h:body>
<h:form>
<h3 style="margin-top:0">Basic</h3>
<p:textEditor widgetVar="editor1" value="#{editorView.text}" height="300" style="margin-bottom:10px"/>
<p:commandButton value="Submit" update="display" oncomplete="PF('dlg').show()" icon="pi pi-save" />
<p:commandButton value="Clear" type="button" onclick="PF('editor1').clear();" icon="pi pi-times" />
<h3 class="first">Custom Toolbar</h3>
<p:textEditor widgetVar="editor2" value="#{editorView.text2}" height="300" style="margin-bottom:10px" placeholder="Enter your content">
<f:facet name="toolbar">
<span class="ql-formats">
<button class="ql-bold"></button>
<button class="ql-italic"></button>
<button class="ql-underline"></button>
<button class="ql-strike"></button>
</span>
<span class="ql-formats">
<select class="ql-font"></select>
<select class="ql-size"></select>
</span>
</f:facet>
</p:textEditor>
<p:commandButton value="Submit" update="display" oncomplete="PF('dlg').show()" icon="pi pi-save" />
<p:commandButton value="Clear" type="button" onclick="PF('editor2').clear();" icon="pi pi-times" />
<p:dialog header="Content" widgetVar="dlg" showEffect="fade" hideEffect="fade">
<p:outputPanel id="display">
<h3 style="margin-top:0">Basic</h3>
<h:outputText value="#{editorView.text}" escape="false" />
<h3>Custom</h3>
<h:outputText value="#{editorView.text2}" escape="false" />
</p:outputPanel>
</p:dialog>
</h:form>
</h:body>
</html>
EditorView.java
package com.jsf.showcase.view.input;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
import lombok.Getter;
import lombok.Setter;
#Getter #Setter
#Named
#RequestScoped
public class EditorView {
private String text;
private String text2;
}
PrimeFaces version: 8

I have solved with this dependency. Thanks Kukeltje.
<dependency>
<groupId>com.googlecode.owasp-java-html-sanitizer</groupId>
<artifactId>owasp-java-html-sanitizer</artifactId>
<version>20191001.1</version>
</dependency>

Related to Mario's answer, that dependency is not available today. I used the following dependency and it also works fine:
<dependency>
<groupId>com.googlecode.owasp-java-html-sanitizer</groupId>
<artifactId>html-types</artifactId>
<version>20200713.1</version>
</dependency>

According to the documentation the textEditor element has the secure attribute on true by default. This is because we need the text editor to be protected against XSS attacks (you wouldn't want an attacker to write malicious code in your editor, that can then be executed in other user's browsers)
https://owasp.org/www-community/attacks/xss/
Hence why you need to not only use the dependency owasp-java-html-sanitizer but to keep it up to date in case vulnerabilities in it appear.
https://search.maven.org/artifact/com.googlecode.owasp-java-html-sanitizer/owasp-java-html-sanitizer

Related

Method Not Found ? This not made sense [duplicate]

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.

Strange display behavior for p:dataTable in combination with ui:repeat or p:dataList [duplicate]

This question already has answers here:
ui: repeat + p: datatable question
(2 answers)
Closed 7 years ago.
When I use a primefaces p:displayTable in a ui:repeat or a p:dataList, the resulting display is buggy. Buggy means, the first table defines the columns of the following tables and not the DynamicDataTableCatalog-columns-count as expected.
My reputation isn't enough to post a image... (output png on an other website...) So i write the output in simple html:
<div>
<table id="firstTableWhichDefinesTheColum">
<tr>
<td>a</td>
<td>b</td>
<td>c</td>
</tr>
</table>
<table id="secondTableWithOnlyOneColumn">
<tr>
<td>d</td>
<td>random content or empty, because no data is available</td>
<td>random content or empty, because no data is available</td>
</tr>
</table>
</div>
This is the erroneous code:
<p:dataList value="#{evaluateEntriesMBean.dataTables}"
var="qC" type="definition">
<p:panel header="Übersicht #{qC.catalog.name}"
styleClass="defaultPanelClass subGradient">
<p:dataTable value="#{qC.userAnswers}" var="userAnswer"
tableStyle="margin: auto; width: auto;">
<p:column headerText="Mitarbeiter"
style="text-align: right; width: auto">
<h:outputText value="#{userAnswer.user.geteMail()}" />
</p:column>
<p:columns value="#{qC.columns}" var="column"
columnIndexVar="index"
style="#{evaluateEntriesMBean.getStyleOfAnswer(userAnswer,index)}" >
<f:facet name="header">
<div title="#{column.tooltipText}">
<h:outputText value="#{column.name}" />
</div>
</f:facet>
<div title="#{evaluateEntriesMBean.getTextOfAnswer(userAnswer,index)}" >
<p:graphicImage url="/resources/img/green-trafficlight.png"
width="24"
rendered="#{evaluateEntriesMBean.getTrafficLightOfAnswer(userAnswer,index) == 'Green'}" />
<p:graphicImage url="/resources/img/yellow-trafficlight.png"
width="24"
rendered="#{evaluateEntriesMBean.getTrafficLightOfAnswer(userAnswer,index) == 'Yellow'}" />
<p:graphicImage url="/resources/img/red-trafficlight.png"
width="24"
rendered="#{evaluateEntriesMBean.getTrafficLightOfAnswer(userAnswer,index) == 'Red'}" />
<p:graphicImage url="/resources/img/grey-trafficlight.png"
width="24"
rendered="#{evaluateEntriesMBean.getTrafficLightOfAnswer(userAnswer,index) == 'Unknown'}" />
</div>
</p:columns>
</p:dataTable>
</p:panel>
</p:dataList>
The datamodels which are used in the view:
public class DynamicDataTableCatalog {
private QuestionCatalogHistory catalog;
private List<ColumnHeader> columns;
private List<UserAnswers> userAnswers;
//...
}
public class UserAnswers {
private User user;
private List<Answer> answers;
//...
}
public class ColumnHeader {
String name;
String tooltipText;
//...
}
When i replace the p:dataList with a ui:repeat, the output is the same. Only the c:forEach works but doesn't support ajax updates...
My dependencies (All used libs including the version):
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>3.5</version>
</dependency>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>javax.faces-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.1.12</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1.12</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.ejb</groupId>
<artifactId>ejb-api</artifactId>
<version>3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.sourceforge.jexcelapi</groupId>
<artifactId>jxl</artifactId>
<version>2.6.12</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
I hope someone can tell me if this is a bug or a wrong implementation I've made... Thank you in advance!
It's a Bug in Primefaces which is not fixed at the moment...
Thanks to Kukeltje I know that this is a Primefaces-Bug which isn't fixed at the moment...
https://github.com/primefaces/primefaces/issues/88

Ajax update has no effect, Firefox errors: XML or text declaration not at start of entity

I have small form which will receive values from a class. However pressing the button will not update the selectOneMenu.
Refreshing the form will correctly fill the menu with the correct items.
I was expecting
update="instrument"/>
to refresh the content of the menu. But I guess I am missing something. Note that the method in the bean are getting called on button press. The list is filled and also the int is set when choosing an item.
<h:form id="listForm">
<p:outputLabel for="instrument" value="Instrument " />
<p:selectOneMenu id="instrument" value="#{tradeFactory.intInstrumentID}" style="width:150px">
<p:ajax listener="#{tradeFactory.onInstrumentChange(tradeFactory.intInstrumentID)}" update="instrument" />
<f:selectItem itemLabel="Select Instrument" itemValue="" noSelectionOption="true" />
<f:selectItems value="#{tradeFactory.instrumentID}" />
</p:selectOneMenu>
<p:commandButton value="Update" actionListener="#{tradeFactory.getInstrumentIDs()}" update="instrument"/>
Function for update
#PostConstruct
public void getInstrumentIDs() {
Set<Integer> s = trades.keySet();
instrumentID.clear();
s.stream().forEach(i -> instrumentID.put(String.valueOf(i), String.valueOf(i)));
}
Ajax response body
<?xml version='1.0' encoding='UTF-8'?>
<?xml version='1.0' encoding='UTF-8'?>
<partial-response id="j_id1"><changes><update id="growl"><![CDATA[<span id="growl"></span><script id="growl_s" type="text/javascript">$(function(){PrimeFaces.cw('Growl','widget_growl',{id:'growl',sticky:false,life:5000,escape:true,msgs:[]});});</script>]]></update><update id="listForm:instrument"><![CDATA[<div id="listForm:instrument" class="ui-selectonemenu ui-widget ui-state-default ui-corner-all" style="width:150px"><div class="ui-helper-hidden-accessible"><input id="listForm:instrument_focus" name="listForm:instrument_focus" type="text" autocomplete="off" /></div><div class="ui-helper-hidden-accessible"><select id="listForm:instrument_input" name="listForm:instrument_input" tabindex="-1" onchange="PrimeFaces.ab({s:"listForm:instrument",e:"valueChange",f:"listForm",p:"listForm:instrument",u:"listForm:instrument"});"><option value="">Select Instrument</option><option value="101" selected="selected">101</option></select></div><label id="listForm:instrument_label" class="ui-selectonemenu-label ui-inputfield ui-corner-all"> </label><div class="ui-selectonemenu-trigger ui-state-default ui-corner-right"><span class="ui-icon ui-icon-triangle-1-s ui-c"></span></div><div id="listForm:instrument_panel" class="ui-selectonemenu-panel ui-widget-content ui-corner-all ui-helper-hidden ui-shadow"><div class="ui-selectonemenu-items-wrapper" style="height:auto"><ul class="ui-selectonemenu-items ui-selectonemenu-list ui-widget-content ui-widget ui-corner-all ui-helper-reset"><li class="ui-selectonemenu-item ui-selectonemenu-list-item ui-corner-all" data-label="Select Instrument">Select Instrument</li><li class="ui-selectonemenu-item ui-selectonemenu-list-item ui-corner-all" data-label="101">101</li></ul></div></div></div><script id="listForm:instrument_s" type="text/javascript">$(function(){PrimeFaces.cw("SelectOneMenu","widget_listForm_instrument",{id:"listForm:instrument",widgetVar:"widget_listForm_instrument",behaviors:{valueChange:function(ext) {PrimeFaces.ab({s:"listForm:instrument",e:"valueChange",f:"listForm",p:"listForm:instrument",u:"listForm:instrument"},ext);}}});});</script>]]></update><update id="j_id1:javax.faces.ViewState:0"><![CDATA[6pU4fJ833iSGEfN+jgq6Xf7Cm9bY1/D+lP5rGqXRcyk7Iny5mlcxgMIwtSzAH+wmsNVWqKhQSOW+daWL0ldPSks95pfT4GtmvNE6/0Wlnb4X4379LlfKxTNV9jfRbQxcoVpc+DUYCZwPXvF1ewWdv/lm5KlYlqKjtq8M1YKow1bCObQjfE/UjnTOVisLhJec1I2c0vQPGen58TTJ2xRacq8BYx+Flanxtl8uiiySVVNP+AJaxIym3qSV3tegWXLTTNPNqIAt46Iq1y8NmueLOmgYhkJai3Xc0VLRIaALakjPO3GruPvz16TUVmYXejcsJb9bieuDsh94a6gc+FK6oP/h0zBZ/WDf8wwD9MDlXccfIDwlqFOGyAOjjvVBW/FjtoiIyaMMnlDHeohWYoRGxYdU6Nk1A5sY/sIqJclVgmoqgqmlEqzg2aGji/87w77ewL4mniQYlLDEsh0yMP/XMp7eYfBKMJz/+wjOHIEvy/mlej42rNoNy/DxtgX/2vJmUlWroVK01LIEpKVfHgFyCA1qA001dylXeiGka7WENoqyW4ocPY4/kbFEbbbnPt8O+rJlbC735WQGoZsriHAtJe9cOxKaQ2Ca9x8ISeqgEoVAGRxynDtwVp2EsIOTsBczHvHn7VDmlhEHxSbGq6wmnUPMOHL4TitGt3q3708UL/S5TRmLmHJEFJ1zqhdUJ5KqhkKqyrspU3CqFkKAw8nsrRlZSc9m4Yj3vsiDzTMFnTx4EnF+p227QeKsUbor+AO/7+qbX3yXvWNDsifEoz+gNK5eGp7aWm0jJEHsrdbCsE8pg6AtfO0Cua3lvGIHL1o6ApQqMZtNyPJcYHO3a9giD68m2gfvhXm/XeGubocuP+GlVxViOouHHAnl7ur5ufDU3GYEGd9iIoIt4fLXDblIwoL4rFLRCGHp3eLW2UBDEVcZ+2rQAy0m3CcIMtzUhSHaEub7wEmaKO+gacp1bpygFxSFj0umQFafRbbNuvoU1rhTib+z+xwxwMP+XbYOqp+K0HUFBxMuoymn07KDn1kOzJsvG32CoDyQJ5advznRsg1wWaLz8NJsEMOz/AbPj+eV5Y5b+76mH5VVANpOibTJ2QQYnzl0bR8PdApngOCBQ9pjJoIZ3HTQ5MehorVHK1o58RV0Y88zLzYIeljJWURy8bBIBpKsX6BxZr5noQlxogPtZ47IWy+6tiLqgyfvT8/aAsxOtAtCAgdXQO8y0rv5fI/6M3QfX+slTuDQAUOjYIi+Z0q6SZdwWpVJn43LB7PucRt73nP6T34RUwekzc351O9/IP+XI+bizxoQFGrBVmY=]]></update></changes></partial-response>
Firefox console
15:18:52.737 XML or text declaration not at start of entity1 trades.xhtml:2:1
Maven pom
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.9</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.9</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.2.10</version>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>5.2</version>
</dependency>
The ajax update fail is caused by the double XML prolog in the ajax response:
<?xml version='1.0' encoding='UTF-8'?>
<?xml version='1.0' encoding='UTF-8'?>
There may be only one.
This can be caused by a conflict and/or mismatch in JSF API and impl libraries in the runtime classpath. You need to make sure that your runtime classpath is free of conflicts and/or mismatches in API and impl libraries.
Given that you're using Maven and are using a barebones servletcontainer (Tomcat) as target runtime, best way to include the current Mojarra version (2.2.11) is the single javax.faces.jar which is available by below coordinate:
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.faces</artifactId>
<version>2.2.11</version>
</dependency>
Make sure you remove both jsf-api and jsf-impl coordinates.

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