Roufid

Easy tutorial to work with JSF in Liferay portal on Tomcat

This tutorial will allow you to use Jsf with Liferay on tomcat .

Important point: Tomcat is not natively a Java EE application server but a servlet container. It does not contain the libraries needed to use JSF. So we have to add them manually.

The two JSF JARs needed are jsf-api.jar and jsp-impl.jar. We will use Mojarra as JSF implementation.

There are two ways to use JSF on your Liferay projects. Either by adding it to the application as dependencies (the project classpath) or by adding it in the global context of Tomcat (tomcat/lib/ext) and declaring it as provided”.

Both ways will be presented below.

1- Include the JARs in the application context classpath

The first way to use JSF with Liferay is to include the two needed dependencies (jsf-api.jar and jsf-impl.jar) in the project classpath (WEB-INF/lib).  To do so, add the following code to all your Liferay projects pom.xml.

Note that the dependencies are included during the compile scope and if you open the jar generated, after a mvn install, you will find the JSF JARs under the WEB-INF/lib.

2- Include the JARs in Tomcat global classpath

The second way to use JSF with Liferay is to make the JARs provided by the Tomcat server. Some changes of the jsfimpl.jar are to do because of the Mojarra ConfigureListner. Follow these instructions :

  1. Download jsf-api.jar and jsp-impl.jar (click on download (JAR)) and save it on your computer
  2. Copy the two JARs to the $LIFERAY_HOME/tomcat/lib/ext folder
  3. Open a terminal window (Press “windows + r” and tape “cmd” a click “Enter“)
  4. Navigate to your $LIFERAY_HOME/tomcat/lib/ext

  5. Create a temporary folder named jsf-impl
  6. Navigate to the created folder
  7. Extract the jsf-impl.jar into the created folder (Be sure to have the path to the Java JDK /bin in the “PATH” environment variable)
  8. Open the file “jsf_core.tld” located in “jsf-impl/META-INF” and remove the following lines (from 87 to 89)
  9. Save and close the modified file
  10. Remove the Mojarra servlet container initializer file “javax.servlet.ServletContainerInitializer” located under “jsf-impl-2.2.9/META-INF/services”
  11. Create a new archive
  12. Remove the temporary folder
  13. Follow one of the two following sub-steps
    a. Add the liferay-faces-init.jar dependency in each Liferay JSF project by adding the following code to each pom.xml :
    b. Add the following code in each WEB-INF/web.xml of all your JSF projects :
  14. Declare the jsf-api and jsf-impl dependencies as provided in each JSF project pom.xml:

You can now create Liferay portlets using JSF !