Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

Web Development

Using JSF and JSR 168 Portals to Develop Ajax Applications


Integrating Basic JSF Components Into Portals

On one hand, the JSF specification supports the Portlet deployment use-case via an abstract API, which allows going beyond Servlets, but its reference implementation cannot be executed, as is in a JSR 168 Portlet environment. In this context, the JSF Portlet bridge reference implementation, or the bridge corresponding to your particular JSF implementation, is needed, along with the default JSF reference implementation.

Even though a JSF Portlet is packaged almost as a regular JSF application, some differences exist. The additional steps needed to create a Portlet with JSF technology are the following:

  1. Copy jsf-portlet.jar Portlet bridge into the WEB-INF/lib directory of your JSF application.
  2. Add a new portlet.xml Portlet deployment descriptor in the WEB-INF directory of the application.

    Below is a typical portlet.xml deployment descriptor, where the INIT_VIEW parameter is replaced to refer to your JSP page.

    <portlet-app […]>
      <portlet>
        <description>JSF Portlet</description>
        <portlet-name>jsfPortlet </portlet-name>
        <display-name>JSF Portlet</display-name>
        <portlet-class>com.sun.faces.portlet.FacesPortlet</portlet-class>
        <init-param>
          <description>Portlet init view page</description>
          <name>com.sun.faces.portlet.INIT_VIEW</name>
          <value>/index.jsp</value>
        </init-param>
        <supports>
          <mime-type>text/html</mime-type>
          <portlet-mode>VIEW</portlet-mode>
        </supports>		
        <portlet-info>
          <title>JSF Portlet</title>
          <short-title>jsfPortlet</short-title>
        </portlet-info>
      </portlet>
    </portlet-app>
    

  3. Avoid any <html>, <head>, <body> or any other forbidden tags as per the JSR 168 specifications in your JSF/JSP pages of your Portlet. Remember that the resulting pages will later be included in the portal HTML page.
  4. Use only JSF tags in tags themselves in tags to ensure unique IDs among the different Portlets. The tag renderer makes sure that all of its subcomponents use unique IDs among the different Portlets across the whole portal page. For instance:

    <f:view>
      <p:portletPage>
         <h:form>
            <h:anyComponent/>
         </h:form>
      </p:portletPage>
    </f:view>
    

  5. Deploy the resulting Portlet WAR file as specified by your chosen portal environment.

With these five steps, you can deploy your JSF components in a JSR 168 portal. But if you want to go beyond the JSF default implementation for components with Ajax behaviors, you will need to go through additional steps.


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.