Primefaces resources are not loaded - jsf

I'm using Primefaces 5.3 with TomEE, but I when I access my pages the PF resources are not being loaded and I get the following error:
$ is not defined
PrimeFaces is not defined
Even when I access the resource URL I get the following error
URL:
http://localhost:8080/Myapp/javax.faces.resource/theme.css.xhtml?ln=primefaces-aristo
Error:
XML Parsing Error: no root element found Location: http://localhost:8080/Myapp/javax.faces.resource/theme.css.xhtml?ln=primefaces-aristo Line Number 1, Column 1
My page :
<?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:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
</h:head>
<f:view>
<p:growl id="notificationMessage" showDetail="true" />
<p:panel id="basic" header="Basic" footer="Movie Details" style="margin-bottom:20px">
<h:panelGrid columns="1" cellpadding="10">
<p:outputLabel for="mbbData" value="Data Value: " />
<p:inputText id="mbbData" value="#{mbbDataInputController.mbbData}" required="true" />
<p:commandButton action="#{mbbDataInputController.addMbb}" />
</h:panelGrid>
</p:panel>
</f:view>
</html>
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID"
version="3.0">
<display-name>my-service</display-name>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>
WEB-INF/faces-config.xml
</param-value>
</context-param>
<!-- Faces Servlet -->
<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>*.xhtml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>rest-servlet</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.huawei.myapp.service</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>rest-servlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
I also tried to add the following to the page head:
<h:outputScript library="primefaces" name="jquery/jquery.js" target="head" />
but it did not work.
Also please note that as I debugged the PrimeResourceHandler class, the resource are being created and the resource path is in the right jar.

OK, I found the problem and the solution as follows.
Problem:
The problem is that I am using two servlets, javax.faces.webapp.FacesServlet for JSF and org.glassfish.jersey.servlet.ServletContainer for REST web services. and when I requested reource file, actually Jersey servlet were going to serve it for me not the faces servlet.
Solution:
I changed the web.xml url mapping as:
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/javax.faces.resources/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>rest-servlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>

Related

Why does my BootsFaces not render anything?

I am fairly new to Coding with Frameworks. I want to build a Website using JSF and found BootsFaces as a Framework. So I downloaded BootsFaces and followed https://www.bootsfaces.net/quick-start.jsf to get everything going. I added the .jar into the Java Build Path and started a Project like the quick-start. So far so good. Then I wanted to implement some more "advanced" stuff. So I tried to add https://showcase.bootsfaces.net/forms/buttonGroups.jsf just to test if everything works. It didn't, If I copy
<b:buttonGroup>
<b:button value="Left" />
<b:button value="Middle" />
<b:button value="Right" />
</b:buttonGroup>
My Site doesnt show anything when it loads.
Here is my index.xhtml
<!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:b="http://bootsfaces.net/ui"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>Basic Page</title>
</h:head>
<h:body>
<b:buttonGroup>
<b:button value="Left" />
<b:button value="Middle" />
<b:button value="Right" />
</b:buttonGroup>
</h:body>
</html>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
<display-name>Mew</display-name>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
<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>*.xhtml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<context-param>
<param-name>BootsFaces_USETHEME</param-name>
<param-value>true</param-value>
</context-param>
</web-app>
I use Glassfish as a Server if thats important.
Did I forget/not see something very basic? Or isn't BootsFaces even supposed to work like this?

Prettyfaces custom URL is not hitting

I am using pretty faces with jsf 2.0 but it is not showing output when hitting the url. I added the prettyfaces-core-3.3.2.jar. Here is the configurations i have made.
home.xhtml
<!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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:body>
Hello Pretty Faces
</h:body>
</html>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>Pretty</display-name>
<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>
<context-param>
<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class
</listener>
</web-app>
pretty-config.xml
<pretty-config xmlns="http://ocpsoft.org/schema/rewrite-config-prettyfaces"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ocpsoft.org/schema/rewrite-config-prettyfaces
http://ocpsoft.org/xml/ns/prettyfaces/rewrite-config-prettyfaces.xsd">
<url-mapping id="home">
<pattern value="/home" />
<view-id value="/faces/home.xhtml" />
</url-mapping>
</pretty-config>
This is the configurations I have done but it is not working. Can someone tell me the mistake I made in the configurations. Thnaks in advance.

Estado HTTP 500 - Error Parsing /index.xhtml: Error Traced[line: 20] The element type "h:form" must be terminated by the matching end-tag "</h:form>"

I'm starting with PrimeFaces following an example of Youtube, and when I run my application reference error appears.
My environment is as follows:
Server: Tomcat 7.0.50
JavaServerFaces: 2.2.9
PrimeFaces: 5.2
IDE: Eclipse Moon
My "web.xml" code is as follows:
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>PrimeFacesVenta</display-name>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<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>*.xhtml</url-pattern>
</servlet-mapping>
<context-param>
<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
</web-app>
The code of my "index.xhtml" file is as follows:
<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>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<h:title>Insert title here</h:title>
</h:head>
<h:body>
<h:form>
<p:outputLabel value="Nombre" />
<p:inputText value="#{personaBean.persona.nombre}" />
<p:outputLabel for="Sexo" value="Basic:" />
<p:selectOneMenu id="sexo" value="#{personaBean.persona.sexo}" />
<f:selectItem itemLabel="MASCULINO" itemValue="M" />
<f:selectItem itemLabel="FEMENINO" itemValue="F" />
</p:selectOneMenu>
</h:form>
</h:body>
</html>
You see, the it is properly closed with , so I do not understand what happens.
I appreciate any help you can give me.
Greetings!
Gustavo Echenique
The problem was in the following line:
<p:selectOneMenu id="sexo" value="#{personaBean.persona.sexo}" />
The terminator tag "/>" was causing the error, and that it should be ">" only.
I hope you serve others.

RichFaces tags are not executed

I have created a Dynamic Web Project in Eclipse Luna , using JSF 2.2, Jboss AS 7. The problem is that no button is rendered in browser from this code <a4j:commandButton value="a4j button"></a4j:commandButton> after I run the project. The same is true for a4j:commandLink for example.
I tried to modify <url-pattern>/faces/*</url-pattern> into <url-pattern>*.xhtml</url-pattern> (found something like this on the internet) but no result.
Hitting Ctrl Space on <a4j: pops a list of tags so i guess richfaces is properly installed.
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:rich="http://richfaces.org/rich"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:h="http://java.sun.com/jsf/html">
<h:body>
<h:form>
<rich:panel>
<a4j:commandButton value="a4j button"></a4j:commandButton>
</rich:panel>
</h:form>
</h:body>
</html>
web.xml file:
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">`
<display-name>TestProject</display-name>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
<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>
</web-app>
faces-config.xml file:
<faces-config
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-facesconfig_2_2.xsd"
version="2.2">
</faces-config>

Primefaces charts Error

Hi Friends JSF primefaces charts not display i am using following .jar files in my application
1)primefaces-3.0.M1.jar
2)jstl-1.0.2.jar
3)jsf-impl.jar
4)jsf-api.jar
but i am getting below exception
org.apache.jasper.JasperException: /pieChartLive.jsp(16,34) #{..} is not allowed in template text
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:102)
org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:711)
org.apache.jasper.compiler.Node$ELExpression.accept(Node.java:935)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2336)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2386)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2392)
org.apache.jasper.compiler.Node$Root.accept(Node.java:489)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2336)
org.apache.jasper.compiler.Validator.validate(Validator.java:1737)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:178)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:306)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
My Jsp file (pieChartLive.jsp)
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>PieChartLive</title>
<p:resources />
</head>
<body>
<h:form id="livePieChartForm">
<p:pieChart id="votes" value="#{PieChartLiveBean.lunchSalesList}"
var="lunchSalesBean" live="true" refreshInterval="3000"
categoryField="#{lunchSalesBean.dishName}"
dataField="#{lunchSalesBean.salesPercentage}" />
</h:form>
</body>
My web.xml
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
PrimeFaces
pieChartLive.jsp
<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>*.jsf</url-pattern>
</servlet-mapping>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>cupertino</param-value>
</context-param>
My faces-config.xml
<faces-config>
<managed-bean>
<managed-bean-name>PieChartLiveBean</managed-bean-name>
<managed-bean-class>com.sample.primefaces.PieChartLiveBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
You are mixing jsp and facelets. Your facelet has file suffix .jsp but your web.xml mapping for the Faces Servlet is *.jsf. So the Faces Servlet won't be invoked.
Change the file suffix to .jsf and try again.

Resources