Posts Tagged ‘JSF2’
(long tweet) Could not find backup for factory javax.faces.context.FacesContextFactory.
Case
On deploying a JSF 2.2 / Primefaces 5 application on Jetty 9, I got the following error:
java.lang.IllegalStateException: Could not find backup for factory javax.faces.context.FacesContextFactory.
The issue seems linked to Jetty, since I could not reproduce the issue on Tomcat 8.
Quickfix
In the web.xml
, add the following block:
<listener> <listener-class>com.sun.faces.config.ConfigureListener</listener-class> </listener>
(long tweet) How to use comments in JSF 2?
If you write comments in an XHTML file (used by JSF2) as regular XML comments (ie starting with <!--
and ending with -->
), you may probably find them in the HTML source generated “by” JSF. To prevent that, add the following bloxk in your web.xml
:
<context-param> <param-name>facelets.SKIP_COMMENTS</param-name> <param-value>true</param-value> </context-param>
(long tweet) Jetty / Unified Expression Language / NoSuchMethodError: javax.el.ELResolver.invoke
Case
On deploying a JSF project on Jetty (via Maven plugin), when I display the XHtml page I get an error, which starts with:
java.lang.NoSuchMethodError: javax.el.ELResolver.invoke(Ljavax/el/ELContext;Ljava/lang/Object;Ljava/lang/Object;[Ljava/lang/Class;[Ljava/lang/Object;)Ljava/lang/Object; at com.sun.el.parser.AstValue.getValue(AstValue.java:111) at com.sun.el.parser.AstValue.getValue(AstValue.java:163) at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionIm
Quick fix
I fixed the issue by removing the dependencies to Unified Expression Language (EL API), either direct or induced:
<dependency> <groupId>org.glassfish.web</groupId> <artifactId>el-impl</artifactId> <version>2.2</version> </dependency> <dependency> <groupId>javax</groupId> <artifactId>javaee-web-api</artifactId> <version>6.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>com.sun.el</groupId> <artifactId>el-ri</artifactId> <version>1.0</version> </dependency> <dependency> <groupId>javax.el</groupId> <artifactId>el-api</artifactId> <version>2.2</version> </dependency> <dependency> <groupId>com.sun.el</groupId> <artifactId>el-ri</artifactId> <version>1.0</version> </dependency>
Actually, some JARs that had to be depended on have been included within Tomcat and Jetty, that’s why some conflict of JARs happen to be. What prevented me to fix quickly the issue was that Tomcat and Jetty seem not to embed the same version on EL
(long tweet) This page calls for XML namespace declared with prefix body but no taglibrary exists for that namespace.
Case
On creating a new JSF 2 page, I get the following warning when the page is displayed:
Warning: This page calls for XML namespace declared with prefix body but no taglibrary exists for that namespace.
Fix
In the XHTML page, replace the HTML 4 headers:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html>...</html>
with XHTML headers:
<?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:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"> ...</html>
(long tweet) Add RichFaces to a Maven / JSF 2 project
Case
You have a JSF 2 project that you need upgrade with jBoss RichFaces and Ajax4JSF, (I assume the process is similar for other libraries, such as Primefaces, ICEfaces, etc.).
Quick Fix
In XHTML
In XHTML pages, add the namespaces related to Richfaces:
xmlns:a4j="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich"
In Maven
In Maven’s pom.xml
, I suggest to add a property, such as:
<properties> <richfaces.version>4.1.0.Final</richfaces.version> </properties>
Add the following dependency blocks:
<dependency> <groupId>org.richfaces.ui</groupId> <artifactId>richfaces-components-ui</artifactId> <version>${richfaces.version}</version> </dependency> <dependency> <groupId>org.richfaces.core</groupId> <artifactId>richfaces-core-impl</artifactId> <version>${richfaces.version}</version> </dependency>