Skip to content

Mis en ligne par admin - 18 novembre 2011 - Astuces Diverses

Transformer en Portlet une Application JSF

Voici les différentes étapes permettant d’utiliser le JBoss Portlet Bridge afin de transformer une application JSF (dans ce cas-ci utilisant les Facelets) en Portlet intégrable dans Liferay. Dans le cas d’une application ayant par exemple, de la navigation de page, d’autres étapes qui ne sont pas discutées ici seront nécessaires.

Etapes:

1. Créer le fichier WEB-INF/liferay-display.xml (nom de la portlet à intégrer):


<display>
  <category name="SSE Grid">
    <portlet id="ssegrid" />
  </category>
</display>

2. Créer le fichier WEB-INF/liferay-portlet.xml (options liferay pour la portlet, tels que script à importer) :

<liferay-portlet-app>
  <portlet>
    <portlet-name>ssegrid</portlet-name>
    <instanceable>true</instanceable>
    <render-weight>1</render-weight>
    <ajaxable>true</ajaxable>
    <header-portal-css>/ssegrid/rfRes/org/richfaces/skin.xcss.jsf</header-portal-css>
    <header-portal-javascript>/ssegrid/rfRes/org/ajax4jsf/framework.pack.js.jsf</header-portal-javascript>
    <header-portal-javascript>/ssegrid/rfRes/org/richfaces/ui.pack.js.jsf</header-portal-javascript>
  </portlet>
</liferay-portlet-app>

3. Créer le fichier WEB-INF/portlet.xml (class du gestionnaire de portlet et autres paramètres):

<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:spb="http://www.spacebel.be/portlets/events"
  xmlns:gvs="http://www.genesis.org/ns/gvs"
  xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
  version="2.0">
  <portlet id="ssegrid">
    <portlet-name>ssegrid</portlet-name>
    <display-name>SSE Grid</display-name>
    <portlet-class>javax.portlet.faces.GenericFacesPortlet</portlet-class>
    <init-param>
      <name>javax.portlet.faces.defaultViewId.view</name>
      <value>/pages/ssegrid.xhtml</value>
    </init-param>
    <init-param>
      <name>javax.portlet.faces.preserveActionParams</name>
      <value>true</value>
    </init-param>
    <expiration-cache>0</expiration-cache>
    <supports>
      <mime-type>text/html</mime-type>
      <portlet-mode>view</portlet-mode>
    </supports>
    <portlet-info>
      <title>SSE Grid</title>
      <short-title>SSE Grid</short-title>
      <keywords>sse grid</keywords>
    </portlet-info>
  </portlet>

</portlet-app>

4. Copier les libs portlets dans WEB-INF/lib (portletbridge-api, PortalResourceBuidler, util-bridges, …)

5. Créer le fichier WEB-INF/jboss-web.xml :


<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:spb="http://www.spacebel.be/portlets/events"
  xmlns:gvs="http://www.genesis.org/ns/gvs"
  xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
  version="2.0">

  <portlet id="ssegrid">
    <portlet-name>ssegrid</portlet-name>
    <display-name>SSE Grid</display-name>
    <portlet-class>javax.portlet.faces.GenericFacesPortlet</portlet-class>
    <init-param>
      <name>javax.portlet.faces.defaultViewId.view</name>
      <value>/pages/ssegrid.xhtml</value>
    </init-param>
    <init-param>
      <name>javax.portlet.faces.preserveActionParams</name>
      <value>true</value>
    </init-param>
    <expiration-cache>0</expiration-cache>
    <supports>
      <mime-type>text/html</mime-type>
      <portlet-mode>view</portlet-mode>
    </supports>
    <portlet-info>
      <title>SSE Grid</title>
      <short-title>SSE Grid</short-title>
      <keywords>sse grid</keywords>
    </portlet-info>
  </portlet>
</portlet-app>

6. Modifier WEB-INF/web.xml pour permettre la compatibilité Portlet :

  
<?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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  version="2.5">
  <description>SSE Grid</description>
  <display-name>ssegrid</display-name>
  <context-param>
    <param-name>com.sun.faces.injectionProvider</param-name>
    <param-value>be.spacebel.ssegrid.SPBInjectionProvider</param-value>
  </context-param>
  <context-param>
    <param-name>com.sun.faces.expressionFactory</param-name>
    <param-value>org.jboss.el.ExpressionFactoryImpl</param-value>
  </context-param>
  <context-param>
    <param-name>com.sun.faces.validateXml</param-name>
    <param-value>true</param-value>
  </context-param>
  <context-param>
    <param-name>com.sun.faces.verifyObjects</param-name>
    <param-value>false</param-value>
  </context-param>
  <context-param>
    <param-name>facelets.BUILD_BEFORE_RESTORE</param-name>
    <param-value>false</param-value>
  </context-param>
  <context-param>
    <param-name>facelets.DEVELOPMENT</param-name>
    <param-value>true</param-value>
  </context-param>
  <context-param>
    <param-name>facelets.REFRESH_PERIOD</param-name>
    <param-value>2</param-value>
  </context-param>
  <context-param>
    <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
    <param-value>.xhtml</param-value>
  </context-param>
  <context-param>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>server</param-value>
  </context-param>
  <context-param>
    <param-name>javax.portlet.faces.renderPolicy</param-name>
    <param-value>ALWAYS_DELEGATE</param-value>
  </context-param>
  <context-param>
    <param-name>org.ajax4jsf.COMPRESS_SCRIPT</param-name>
    <param-value>false</param-value>
  </context-param>
  <context-param>
    <param-name>org.ajax4jsf.RESOURCE_URI_PREFIX</param-name>
    <param-value>rfRes</param-value>
  </context-param>
  <context-param>
    <param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
    <param-value>org.jboss.portletbridge.application.FaceletPortletViewHandler</param-value>
  </context-param>
  <context-param>
    <param-name>org.ajax4jsf.handleViewExpiredOnClient</param-name>
    <param-value>true</param-value>
  </context-param>
  <context-param>
    <param-name>org.jboss.portletbridge.WRAP_SCRIPTS</param-name>
    <param-value>true</param-value>
  </context-param>
  <context-param>
    <param-name>org.richfaces.LoadScriptStrategy</param-name>
    <param-value>NONE</param-value>
  </context-param>
  <context-param>
    <param-name>org.richfaces.LoadStyleStrategy</param-name>
    <param-value>NONE</param-value>
  </context-param>
  <context-param>
    <param-name>request_response_factory.maxSizeParam</param-name>
    <param-value>200</param-value>
  </context-param>
  <context-param>
    <param-name>request_response_factory.minSizeParam</param-name>
    <param-value>0</param-value>
  </context-param>
  <context-param>
    <param-name>request_response_factory.partitionParam</param-name>
    <param-value>10</param-value>
  </context-param>
  <context-param>
    <param-name>vendorPortletXML.sun.impl</param-name>
    <param-value>com.sun.portal.portletcontainer.common.descriptor.SunPortletXMLImpl</param-value>
  </context-param>
  <context-param>
    <param-name>vendorPortletXML.sun.name</param-name>
    <param-value>sun-portlet.xml</param-value>
  </context-param>
  <context-param>
    <param-name>vendorPortletXML.sun.validate</param-name>
    <param-value>false</param-value>
  </context-param>

  <!-- Defining and mapping the RichFaces filter -->

  <filter>
    <display-name>RichFaces Filter</display-name>
    <filter-name>richfaces</filter-name>
    <filter-class>org.ajax4jsf.Filter</filter-class>
    <init-param>
      <param-name>createTempFiles</param-name>
      <param-value>false</param-value>
    </init-param>
    <init-param>
      <param-name>maxRequestSize</param-name>
      <param-value>1000000</param-value>
    </init-param>
  </filter>
  <filter>
    <filter-name>PortletAppEngineFilter</filter-name>
    <filter-class>com.sun.portal.portletcontainer.appengine.PortletAppEngineFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>PortletAppEngineFilter</filter-name>
    <servlet-name>PortletAppEngineServlet</servlet-name>
    <dispatcher>INCLUDE</dispatcher>
  </filter-mapping>
  <filter-mapping>
    <filter-name>richfaces</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
  </filter-mapping>
  <listener>
    <listener-class>com.liferay.portal.kernel.servlet.PortletContextListener</listener-class>
  </listener>
  <servlet>
    <servlet-name>PortletAppEngineServlet</servlet-name>
    <servlet-class>com.sun.portal.portletcontainer.appengine.PortletAppEngineServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet>
    <servlet-name>Liferay</servlet-name>
    <servlet-class>com.liferay.portal.kernel.servlet.PortletServlet</servlet-class>
    <init-param>
      <param-name>portlet-class</param-name>
      <param-value>javax.portlet.faces.GenericFacesPortlet</param-value>
    </init-param>
    <load-on-startup>0</load-on-startup>
  </servlet>
  <servlet>
    <servlet-name>Resource Servlet</servlet-name>
    <servlet-class>org.primefaces.resource.ResourceServlet</servlet-class>
  </servlet>
  <servlet>
    <servlet-name>TranslateServlet</servlet-name>
    <servlet-class>be.spacebel.ontology.presentation.ajax.TranslateServlet</servlet-class>
  </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>*.jsf</url-pattern>
  </servlet-mapping>
  <servlet>
    <servlet-name>AxisServlet</servlet-name>
    <servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>AxisServlet</servlet-name>
    <url-pattern>/services/*</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>Liferay</servlet-name>
    <url-pattern>/ssegrid/*</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>PortletAppEngineServlet</servlet-name>
    <url-pattern>/servlet/PortletAppEngineServlet</url-pattern>
  </servlet-mapping>

  <session-config>
    <session-timeout>30</session-timeout>
  </session-config>
</web-app>

7. Modifier WEB-INF/faces-config.xml :
Ajouter

<application>
    <view-handler>org.jboss.portletbridge.application.PortletViewHandler</view-handler>
    <state-manager>org.jboss.portletbridge.application.PortletStateManager</state-manager>
    <locale-config>
      <default-locale>en</default-locale>
      <supported-locale>en</supported-locale>
    </locale-config>
  </application>

Articles similaires

Les articles suivants abordent des thèmes communs.

Commentaires

Partagez vos remarques.

Il n'y a pas de commentaires pour cet article.

Add a Comment

Fill in the form and submit.