Java Server Faces (JSF)

(Difference between revisions)
Jump to: navigation, search
(Added another thread about JSF and OpenCms)
Line 1: Line 1:
= Integrating OpenCms and Java Server Faces =
+
Integrating OpenCms with JavaServer Faces is possible. This articles lists all
 +
the work that has to be done to use JSF within OpenCms.
  
Is this possible? Has anybody ever done this?
+
== Prerequisites ==
  
Usefull Links I found:
+
Before you start you have to decide on the software versions you want to use. On the Apache website there is a [[http://myfaces.apache.org/compatibility.html compatibility list]] for Apache's software stack (Tomcat, MyFaces).
 +
 
 +
The following combinations are known to work (*please extend*!):
 +
<table border="1">
 +
  <tr><th>Java Runtime</th><th>OpenCms</th><th>Servlet Container/Application Server</th><th>JSF Implementation</th></tr>
 +
 
 +
  <tr><td>1.5</td><td>7.0.1 (WebApp 2.4)</td><td>Tomcat 6.0.14</td><td>Sun RI 1.1_02</td></tr>
 +
</table>
 +
 
 +
 
 +
 
 +
== Integrating OpenCms and Java Server Faces ==
 +
 
 +
=== Copy JSF Libraries ===
 +
 
 +
First, get the JSF implementation of your choice. Unzip the distribution and search for
 +
the JAR files named <tt>jsf-api.jar</tt> and <tt>jsf-impl.jar</tt> (usually in the lib
 +
directory). Copy these two archives to <tt>WEB-INF/lib</tt> in your OpenCms installation
 +
directory.
 +
 
 +
=== Adapt Webapplication Descriptor ===
 +
 
 +
Next you have to configure the servlet mapping in <tt>WEB-INF/web.xml</tt>. Add the following
 +
sections:
 +
 
 +
<pre>
 +
  <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>
 +
</pre>
 +
 
 +
Note that it has been reported, that suffix-mapping (e.g, *.jsf) should work as well
 +
but I couldn't get it to work, so I used prefix mapping, i.e. "/faces/*", instead.
 +
 
 +
=== Create Faces Configuration ===
 +
 
 +
Next you can create a JSF configuration file in <tt>WEB-INF/faces-config.xml</tt>
 +
like this:
 +
 
 +
<pre>
 +
<?xml version="1.0"?>
 +
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
 +
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 +
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
 +
        http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
 +
        version="1.2">
 +
  <navigation-rule>
 +
      <from-view-id>/opencms/jsf-example.jsp</from-view-id>
 +
      <navigation-case>
 +
        <from-outcome>login</from-outcome>
 +
        <to-view-id>/opencms/jsf-example2.jsp</to-view-id>
 +
      </navigation-case>
 +
  </navigation-rule>
 +
 
 +
  <managed-bean>
 +
      <managed-bean-name>user</managed-bean-name>
 +
      <managed-bean-class>com.corejsf.UserBean</managed-bean-class>
 +
      <managed-bean-scope>session</managed-bean-scope>
 +
  </managed-bean>
 +
</faces-config>
 +
</pre>
 +
 
 +
=== Add Bean Classes ===
 +
 
 +
Add bean classes as you need them to <tt>WEB-INF/classes</tt> or in a JAR file, as
 +
you like.
 +
 
 +
=== Restart Servlet Container ===
 +
 
 +
Restart your servlet container.
 +
 
 +
=== Use your JSF pages with the correct URLs ===
 +
 
 +
Create you JSF pages and access them with the correct URLs. There is nothing special
 +
in creating JSF pages. Just go to OpenCms' workplace, click on "New", select "JSP"
 +
as the type for you new JSF page and insert your code.
 +
 
 +
When you want to access a JSF page use the base URL
 +
http://myhost:8080/opencms/faces/opencms/ with the path of the file in workplace
 +
appended. For example if you have a file jsf-example.jsp in your root-folder of the
 +
<tt>/sites/default</tt> site, access it via the URL
 +
http://myhost:8080/opencms/faces/opencms/jsf-example.jsp.
 +
 
 +
== Usefull Links ==
  
 
* http://www.opencms-forum.de/opencms-forum/viewthread?thread=2068
 
* http://www.opencms-forum.de/opencms-forum/viewthread?thread=2068
 
* http://www.opencms-forum.de/opencms-forum/viewthread?thread=1042
 
* http://www.opencms-forum.de/opencms-forum/viewthread?thread=1042
 
* http://www.nabble.com/forum/ViewPost.jtp?post=13485806&framed=y
 
* http://www.nabble.com/forum/ViewPost.jtp?post=13485806&framed=y

Revision as of 17:07, 19 November 2007

Integrating OpenCms with JavaServer Faces is possible. This articles lists all the work that has to be done to use JSF within OpenCms.

Contents

Prerequisites

Before you start you have to decide on the software versions you want to use. On the Apache website there is a [compatibility list] for Apache's software stack (Tomcat, MyFaces).

The following combinations are known to work (*please extend*!):

Java RuntimeOpenCmsServlet Container/Application ServerJSF Implementation
1.57.0.1 (WebApp 2.4)Tomcat 6.0.14Sun RI 1.1_02


Integrating OpenCms and Java Server Faces

Copy JSF Libraries

First, get the JSF implementation of your choice. Unzip the distribution and search for the JAR files named jsf-api.jar and jsf-impl.jar (usually in the lib directory). Copy these two archives to WEB-INF/lib in your OpenCms installation directory.

Adapt Webapplication Descriptor

Next you have to configure the servlet mapping in WEB-INF/web.xml. Add the following sections:

   <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>

Note that it has been reported, that suffix-mapping (e.g, *.jsf) should work as well but I couldn't get it to work, so I used prefix mapping, i.e. "/faces/*", instead.

Create Faces Configuration

Next you can create a JSF configuration file in WEB-INF/faces-config.xml like this:

<?xml version="1.0"?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
        http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
        version="1.2">
   <navigation-rule>
      <from-view-id>/opencms/jsf-example.jsp</from-view-id>
      <navigation-case>
         <from-outcome>login</from-outcome>
         <to-view-id>/opencms/jsf-example2.jsp</to-view-id>
      </navigation-case>
   </navigation-rule>

   <managed-bean>
      <managed-bean-name>user</managed-bean-name>
      <managed-bean-class>com.corejsf.UserBean</managed-bean-class>
      <managed-bean-scope>session</managed-bean-scope>
   </managed-bean>
</faces-config>

Add Bean Classes

Add bean classes as you need them to WEB-INF/classes or in a JAR file, as you like.

Restart Servlet Container

Restart your servlet container.

Use your JSF pages with the correct URLs

Create you JSF pages and access them with the correct URLs. There is nothing special in creating JSF pages. Just go to OpenCms' workplace, click on "New", select "JSP" as the type for you new JSF page and insert your code.

When you want to access a JSF page use the base URL http://myhost:8080/opencms/faces/opencms/ with the path of the file in workplace appended. For example if you have a file jsf-example.jsp in your root-folder of the /sites/default site, access it via the URL http://myhost:8080/opencms/faces/opencms/jsf-example.jsp.

Usefull Links

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox