<?xml version='1.0' encoding='utf-8' ?>
<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
<!ENTITY % BOOK_ENTITIES SYSTEM "../../Reference_Guide.ent">
%BOOK_ENTITIES;
]>
<section id="sect-Reference_Guide-Portlet_Primer" role="NotInToc">
	<title>Portlet Primer</title>

	<para xml:id="sect-Reference_Guide-Portlet_Primer-JSR_168_and_JSR_286_overview">
		<citetitle>
			<emphasis role="bold">JSR-168 and JSR-286 overview</emphasis>
		</citetitle>
	</para>
		<para>
			The Java Community Process (<emphasis>JCP</emphasis>) uses Java Specification Requests (<emphasis>JSR</emphasis>s) to define proposed specifications and technologies designed for the Java platform.
		</para>
		<para>
			The Portlet Specifications aim at defining portlets that can be used by any <ulink url="http://www.jcp.org/en/jsr/detail?id=168">JSR-168 (Portlet 1.0)</ulink> or <ulink url="http://www.jcp.org/en/jsr/detail?id=286">JSR-286 (Portlet 2.0)</ulink> portlet container.
		</para>
		<para>
			Most Java EE (Enterprise Edition) portals include at least one compliant portlet container, and &PRODUCT; is no exception. In fact, &PRODUCT; includes a container that supports both versions.
		</para>
		<para>
			This chapter gives a brief overview of the Portlet Specifications, but portlet developers are strongly encouraged to read the <ulink url="http://www.jcp.org/en/jsr/detail?id=286">JSR-286 Portlet Specification</ulink> .
		</para>
		<para>
			&PRODUCT; is fully JSR-286 compliant. Any JSR-168 or JSR-286 portlet operates as it is mandated by the respective specifications inside the portal.
		</para>
		<itemizedlist>
			<listitem>
				<para xml:id="sect-Reference_Guide-JSR_168_and_JSR_286_overview-Portal_Pages">
					<emphasis role="bold">Portal Pages</emphasis>
				</para>
				<para>
					A portal can be considered as a series of web pages with different <emphasis>areas</emphasis> within them. Those areas contain different <emphasis>windows</emphasis> and each <emphasis>window</emphasis> contains portlet. The diagram below visually represents this nesting:
				</para>
				<mediaobject>
					<imageobject role="html">
						<imagedata fileref="images/PortletDevelopment/Standard/SpecPortalDef.png" format="PNG" scale="1" width="300" align="center"/>
					</imageobject>
                    <imageobject role="fo">
						<imagedata fileref="images/PortletDevelopment/Standard/SpecPortalDef.png" format="PNG" scalefit="1" width="150mm" align="center" />
					</imageobject>
				</mediaobject>
			</listitem>
			<listitem>
				<para xml:id="sect-Reference_Guide-JSR_168_and_JSR_286_overview-Rendering_Modes">
					<emphasis role="bold">Rendering Modes</emphasis>
				</para>
				<para>
					A portlet can have different view modes. Three modes are defined by the JSR-286 specification:
				</para>
				<variablelist>
					<varlistentry>
						<term>View</term>
						<listitem>
							<para>
								Generate the markup reflecting the current state of the portlet.
							</para>
						</listitem>
					</varlistentry>
					<varlistentry>
						<term>Edit</term>
						<listitem>
							<para>
								Allow you to customize the behavior of the portlet.
							</para>
						</listitem>
					</varlistentry>
					<varlistentry>
						<term>Help</term>
						<listitem>
							<para>
								Provide information to the user as to how to use the portlet.
							</para>
						</listitem>
					</varlistentry>
				</variablelist>
			</listitem>
			<listitem>
				<para xml:id="sect-Reference_Guide-JSR_168_and_JSR_286_overview-Window_States">
					<emphasis role="bold">Window States</emphasis>
				</para>
				<para>
					Window states are an indicator of how much page space a portlet consumes on any given page. The three states defined by the JSR-168 specification are:
				</para>
			<variablelist>
				<varlistentry>
					<term>Normal</term>
					<listitem>
						<para>
							A portlet shares this page with other portlets.
						</para>
					</listitem>
				</varlistentry>
				<varlistentry>
					<term>Minimized</term>
					<listitem>
						<para>
							A portlet may show very little information, or none at all.
						</para>
					</listitem>
				</varlistentry>
				<varlistentry>
					<term>Maximized</term>
					<listitem>
						<para>
							A portlet may be the only portlet displayed on this page.
						</para>
					</listitem>
				</varlistentry>
			</variablelist>
			</listitem>
		</itemizedlist>

		<section id="sect-Reference_Guide-Tutorials-Deploying_your_first_Portlet">
			<title>Deploying your first Portlet</title>
			
		<note>
			<itemizedlist>
			<listitem>
			<para>
			The tutorials contained in this chapter are targeted towards portlet developers. It is also recommended that developers read and understand the <ulink url="http://www.jcp.org/en/jsr/detail?id=286"> JSR-286 Portlet Specification </ulink> .
			</para>
			</listitem>
			<listitem>
			<para>
				This example is using Maven to compile and build the web archive. Maven versions can be downloaded from <ulink url="http://maven.apache.org/download.html">maven.apache.org</ulink>
			</para>
			</listitem>
			</itemizedlist>
		</note>
			<para>
				This section describes how to deploy a portlet in &PRODUCT;. A sample portlet called <emphasis>SimplestHelloWorld</emphasis> is located in the <emphasis>examples</emphasis> directory at the root of your &PRODUCT; binary package. This sample is used in the following examples.
			</para>
			<section id="sect-Reference_Guide-Deploying_your_first_Portlet-Compiling">
				<title>Compiling</title>
				<para>
					To compile and package the application:
				</para>
				<procedure>
					<step>
						<para>
							Navigate to the <emphasis>SimplestHelloWorld</emphasis> directory and execute:
						</para>
						
<programlisting>mvn package
</programlisting>
					</step>
					<step>
						<para>
							If the compile is successfully packaged, the result will be available in: <emphasis>SimplestHelloWorld/target/SimplestHelloWorld-0.0.1.war </emphasis>.
						</para>
					</step>
					<step>
						<para>
							Copy the package file into <emphasis>$PLATFORM_JBOSS_HOME/server/default/deploy</emphasis>.
						</para>
					</step>
					<step>
						<para>
							Start the JBoss Application Server (if it is not already running).
						</para>
					</step>
					<step>
						<para>
							Create a new portal page and add the portlet to it.
						</para>
						<mediaobject>
							<imageobject role="html">
								<objectinfo id="obje-Reference_Guide-Compiling-SimplestHelloWorldPortlet_deployed_on_a_new_page"><title>SimplestHelloWorldPortlet deployed on a new page</title>
								</objectinfo><imagedata fileref="images/PortletDevelopment/Standard/first_portlet/deployed.png" format="PNG" width="444" align="center" />
							</imageobject>
                            <imageobject role="fo">
								<objectinfo id="obje-Reference_Guide-Compiling-SimplestHelloWorldPortlet_deployed_on_a_new_page"><title>SimplestHelloWorldPortlet deployed on a new page</title>
								</objectinfo><imagedata fileref="images/PortletDevelopment/Standard/first_portlet/deployed.png" format="PNG" width="150mm" scalefit="1" align="center" />
							</imageobject>
						</mediaobject>
					</step>
				</procedure>

			</section>
			
			<section id="sect-Reference_Guide-Deploying_your_first_Portlet-Package_Structure">
				<title>Package Structure</title>
				<para>
					Like other Java EE applications, &PRODUCT; portlets are packaged in the .war files. A typical portlet .war file can include servlets, resource bundles, images, HTML, JavaServer Pages (JSP), and other static or dynamic files.
				</para>
				<para>
					The following is an example of the directory structure of the <emphasis role="bold">SimplestHelloWorld</emphasis> portlet:
				</para>
				<programlistingco>
					<areaspec>
						<area coords="9" id="area-Reference_Guide-Deploying_your_first_Portlet-Package_Structure.javaclass" />
						<area coords="10" id="area-Reference_Guide-Deploying_your_first_Portlet-Package_Structure.portlet" />
						<area coords="11" id="area-Reference_Guide-Deploying_your_first_Portlet-Package_Structure.web" />
					</areaspec>
<programlisting>|-- SimplestHelloWorld-0.0.1.war
|   `-- WEB-INF
|       |-- classes
|       |   `-- org
|       |       `-- gatein
|       |           `-- portal
|       |               `-- examples
|       |                   `-- portlets
|       |                       `-- SimplestHelloWorldPortlet.class
|       |-- portlet.xml
|       `-- web.xml
</programlisting>
					<calloutlist>
						<callout arearefs="area-Reference_Guide-Deploying_your_first_Portlet-Package_Structure.javaclass">
							<para>
								The compiled Java class implementing <emphasis>javax.portlet.Portlet</emphasis> (through <emphasis>javax.portlet.GenericPortlet </emphasis> )
							</para>
						</callout>
						<callout arearefs="area-Reference_Guide-Deploying_your_first_Portlet-Package_Structure.portlet">
							<para>
								This is the mandatory descriptor files for portlets. It is used during deployment.
							</para>
						</callout>
						<callout arearefs="area-Reference_Guide-Deploying_your_first_Portlet-Package_Structure.web">
							<para>
								This is the mandatory descriptor for web applications.
							</para>
						</callout>
					</calloutlist>
				</programlistingco>

			</section>
			
			<section id="sect-Reference_Guide-Deploying_your_first_Portlet-Portlet_Class">
				<title>Portlet Class</title>
				<para>
					Below is the <emphasis>SimplestHelloWorldPortlet/src/main/java/org/gatein/portal/examples/portlets/SimplestHelloWorldPortlet.java </emphasis> Java source:
				</para>
				<programlistingco>
					<areaspec>
						<area coords="10" id="area-Reference_Guide-Deploying_your_first_Portlet-Portlet_Class.extends" />
						<area coords="13" id="area-Reference_Guide-Deploying_your_first_Portlet-Portlet_Class.doview" />
						<area coords="15" id="area-Reference_Guide-Deploying_your_first_Portlet-Portlet_Class.writer" />
						<area coords="16" id="area-Reference_Guide-Deploying_your_first_Portlet-Portlet_Class.write" />
						<area coords="17" id="area-Reference_Guide-Deploying_your_first_Portlet-Portlet_Class.close" />
					</areaspec>
<programlisting language="java">package org.gatein.portal.examples.portlets;
 
import java.io.IOException;
import java.io.PrintWriter;
 
import javax.portlet.GenericPortlet;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
 
public class SimplestHelloWorldPortlet extends GenericPortlet
{
   public void doView(RenderRequest request, 
                       RenderResponse response) throws IOException
   {
      PrintWriter writer = response.getWriter();
      writer.write(&#34;Hello World !&#34;);
      writer.close();
   }
}
</programlisting>
					<calloutlist>
						<callout arearefs="area-Reference_Guide-Deploying_your_first_Portlet-Portlet_Class.extends">
							<para>
								All portlets must implement the <emphasis>javax.portlet.Portlet</emphasis> interface. The portlet API provides a convenient implementation of this interface.
							</para>
							<para>
								The <emphasis>javax.portlet.Portlet</emphasis> interface uses the <emphasis>javax.portlet.GenericPortlet</emphasis> class which implements the <emphasis>Portlet render</emphasis> method to dispatch to abstract mode-specific methods. This makes it easier to support the standard portlet modes.
							</para>
							<para>
								<emphasis>Portlet render</emphasis> also provides a default implementation for the <emphasis>processAction</emphasis>, <emphasis>init</emphasis> and <emphasis>destroy</emphasis> methods. It is recommended to extend <emphasis>GenericPortlet</emphasis> for most cases.
							</para>
						</callout>
						<callout arearefs="area-Reference_Guide-Deploying_your_first_Portlet-Portlet_Class.doview">
							<para>
								If only the <emphasis>view</emphasis> mode is required, only the <emphasis>doView</emphasis> method needs to be implemented. The <emphasis>GenericPortlet</emphasis><emphasis>render</emphasis> implementation calls our implementation when the <emphasis>view</emphasis> mode is requested.
							</para>
						</callout>
						<callout arearefs="area-Reference_Guide-Deploying_your_first_Portlet-Portlet_Class.writer">
							<para>
								Use the <emphasis>RenderResponse</emphasis> to obtain a writer to be used to produce content.
							</para>
						</callout>
						<callout arearefs="area-Reference_Guide-Deploying_your_first_Portlet-Portlet_Class.write">
							<para>
								Write the markup to display.
							</para>
						</callout>
						<callout arearefs="area-Reference_Guide-Deploying_your_first_Portlet-Portlet_Class.close">
							<para>
								Close the writer.
							</para>
						</callout>
					</calloutlist>
				</programlistingco>
				
				<para>
					<note>
						<title>Markup Fragments</title>
						<para>
							Portlets are responsible for generating markup fragments, as they are included on a page and are surrounded by other portlets. This means that a portlet outputing HTML must not output any markup that cannot be found in a <emphasis>&#60;body&#62;</emphasis> element.
						</para>
					</note>
				</para>
			</section>
			
			<section id="sect-Reference_Guide-Deploying_your_first_Portlet-Application_Descriptors">
				<title>Application Descriptors</title>
				<para>
					&PRODUCT; requires certain descriptors to be included in a portlet WAR file. These descriptors are defined by the Jave EE (<emphasis>web.xml</emphasis>) and Portlet Specification (<emphasis>portlet.xml</emphasis>).
				</para>
				<para>
					Below is an example of the <emphasis>SimplestHelloWorldPortlet/WEB-INF/portlet.xml</emphasis> file. This file must adhere to its definition in the JSR-286 Portlet Specification. More than one portlet application may be defined in this file:
				</para>
				<programlistingco>
					<areaspec>
						<area coords="8" id="area-Reference_Guide-Deploying_your_first_Portlet-Application_Descriptors.portletname" />
						<area coords="9" id="area-Reference_Guide-Deploying_your_first_Portlet-Application_Descriptors.portletclass" />
						<area coords="12" id="area-Reference_Guide-Deploying_your_first_Portlet-Application_Descriptors.supports" />
						<area coords="15" id="area-Reference_Guide-Deploying_your_first_Portlet-Application_Descriptors.portletinfo" />
					</areaspec>
<programlisting language="xml">
&#60;portlet-app xmlns=&#34;http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd&#34;
   xmlns:xsi=&#34;http://www.w3.org/2001/XMLSchema-instance&#34;
   xsi:schemaLocation=&#34;http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd 
                                         http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd&#34;
   version=&#34;2.0&#34;&#62;
   &#60;portlet&#62;
      &#60;portlet-name&#62;SimplestHelloWorldPortlet&#60;/portlet-name&#62;
      &#60;portlet-class&#62;
         org.gatein.portal.examples.portlets.SimplestHelloWorldPortlet
      &#60;/portlet-class&#62;
      &#60;supports&#62;
        &#60;mime-type&#62;text/html&#60;/mime-type&#62;
      &#60;/supports&#62;
      &#60;portlet-info&#62;
          &#60;title&#62;Simplest Hello World Portlet&#60;/title&#62;
      &#60;/portlet-info&#62;
   &#60;/portlet&#62;
&#60;/portlet-app&#62;
</programlisting>
					<calloutlist>
						<callout arearefs="area-Reference_Guide-Deploying_your_first_Portlet-Application_Descriptors.portletname">
							<para>
								Define the portlet name. It does not have to be the class name.
							</para>
						</callout>
						<callout arearefs="area-Reference_Guide-Deploying_your_first_Portlet-Application_Descriptors.portletclass">
							<para>
								The Fully Qualified Name (<emphasis>FQN</emphasis>) of your portlet class must be declared here.
							</para>
						</callout>
						<callout arearefs="area-Reference_Guide-Deploying_your_first_Portlet-Application_Descriptors.supports">
							<para>
								The <emphasis>&#60;supports&#62; </emphasis> element declares all of the markup types that a portlet supports in the <emphasis>render</emphasis> method. This is accomplished via the <emphasis>&#60;mime-type&#62; </emphasis> element, which is required for every portlet.
							</para>
							<para>
								The declared MIME types must match the capability of the portlet. It allows administrators to pair which modes and window states are supported for each markup type.
							</para>
							<para>
								This does not have to be declared as all portlets must support the <emphasis>view</emphasis> portlet mode.
							</para>
							<para>
								Use the <emphasis>&#60;mime-type&#62; </emphasis> element to define which markup type the portlet supports. In the example above, this is <emphasis>text/html</emphasis>. This section tells the portal to only output HTML.
							</para>
						</callout>
						<callout arearefs="area-Reference_Guide-Deploying_your_first_Portlet-Application_Descriptors.portletinfo">
							<para>
								When rendered, the portlet&#39;s title is displayed as the header in the portlet window, unless it is overridden programmatically. In the example above, the title would be <emphasis>Simplest Hello World Portlet</emphasis> .
							</para>
						</callout>
					</calloutlist>
				</programlistingco>

			</section>

		</section>
		
		<section id="sect-Reference_Guide-Tutorials-JavaServer_Pages_Portlet_Example">
			<title>JavaServer Pages Portlet Example</title>
			<para>
				This section discusses:
			</para>
			<orderedlist>
				<listitem>
					<para>
						Add more features to the previous example.
					</para>
				</listitem>
				<listitem>
					<para>
						Use a JSP page to render the markup.
					</para>
				</listitem>
				<listitem>
					<para>
						Use the portlet tag library to generate links to the portlet in different ways.
					</para>
				</listitem>
				<listitem>
					<para>
						Use the other standard portlet modes.
					</para>
				</listitem>
			</orderedlist>
				<note>
					<para>
						The example used in this section can be found in the <emphasis>JSPHelloUser</emphasis> directory.
					</para>
				</note>
			<procedure>
				<step>
					<para>
						Execute <command>mvn package</command> in this directory.
					</para>
				</step>
				<step>
					<para>
						Copy <emphasis>JSPHelloUser/target/JSPHelloUser-0.0.1.war </emphasis> to the <emphasis>deploy</emphasis> directory of JBoss Application Server.
					</para>
				</step>
				<step>
					<para>
						Select the new <emphasis>JSPHelloUser</emphasis> tab in your portal.
					</para>
				</step>
			</procedure>
			
			<mediaobject>
				<imageobject role="html">
					<imagedata align="center" fileref="images/PortletDevelopment/Standard/jsp_portlet/output.png" format="PNG" scalefit="1" width="444" />
				</imageobject>
                <imageobject role="fo">
					<imagedata align="center" fileref="images/PortletDevelopment/Standard/jsp_portlet/output.png" format="PNG" scalefit="1" width="150mm" />
				</imageobject>
			</mediaobject>
			<note>
				<para>
					The <emphasis>EDIT</emphasis> button only appears with logged-in users, which is not the case in the screenshot.
				</para>
			</note>
			<section id="sect-Reference_Guide-JavaServer_Pages_Portlet_Example-Package_Structure">
				<title>Package Structure</title>
				<para>
					The package structure in this tutorial does not much differ from the previous example, with the exception of adding some JSP files detailed later.
				</para>
				<para>
					The JSPHelloUser portlet contains the mandatory portlet application descriptors. The following is an example of the directory structure of the JSPHelloUser portlet:
				</para>
				
<programlisting>JSPHelloUser-0.0.1.war
    |-- META-INF
    |   |-- MANIFEST.MF
    |-- WEB-INF
    |   |-- classes
    |   |   `-- org
    |   |       `-- gatein
    |   |           `-- portal
    |   |               `-- examples
    |   |                   `-- portlets
    |   |                       `-- JSPHelloUserPortlet.class
    |   |-- portlet.xml
    |   `-- web.xml
    `-- jsp
        |-- edit.jsp
        |-- hello.jsp
        |-- help.jsp
        `-- welcome.jsp
</programlisting>
			</section>
			
			<section id="sect-Reference_Guide-JavaServer_Pages_Portlet_Example-Portlet_Class">
				<title>Portlet Class</title>
				<para>
					The code below is from the <filename> JSPHelloUser/src/main/java/org/gatein/portal/examples/portlets/JSPHelloUserPortlet.java </filename> Java source. It is split in different pieces.
				</para>
				<programlistingco>
					<areaspec>
						<area coords="18" id="area-Reference_Guide-JavaServer_Pages_Portlet_Example-Portlet_Class.doView" />
						<area coords="21" id="area-Reference_Guide-JavaServer_Pages_Portlet_Example-Portlet_Class.renderParameter" />
						<area coords="25" id="area-Reference_Guide-JavaServer_Pages_Portlet_Example-Portlet_Class.requestDispatcher" />
						<area coords="26" id="area-Reference_Guide-JavaServer_Pages_Portlet_Example-Portlet_Class.include" />
					</areaspec>
<programlisting language="java">package org.gatein.portal.examples.portlets;
 
import java.io.IOException;
 
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
import javax.portlet.PortletRequestDispatcher;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.portlet.UnavailableException;
 
public class JSPHelloUserPortlet extends GenericPortlet
{
    
   public void doView(RenderRequest request, RenderResponse response)
       throws PortletException, IOException
   {
      String sYourName = (String) request.getParameter(&#34;yourname&#34;);
      if (sYourName != null)
      {
         request.setAttribute(&#34;yourname&#34;, sYourName);
         PortletRequestDispatcher prd = 
            getPortletContext().getRequestDispatcher(&#34;/jsp/hello.jsp&#34;);
         prd.include(request, response);
      }
      else
      {
         PortletRequestDispatcher prd = getPortletContext().getRequestDispatcher(&#34;/jsp/welcome.jsp&#34;);
         prd.include(request, response);
      }
   }
...
</programlisting>
					<calloutlist>
						<callout arearefs="area-Reference_Guide-JavaServer_Pages_Portlet_Example-Portlet_Class.doView">
							<para>
								Override the <emphasis>doView</emphasis> method (as in the first tutorial).
							</para>
						</callout>
						<callout arearefs="area-Reference_Guide-JavaServer_Pages_Portlet_Example-Portlet_Class.renderParameter">
							<para>
								This entry attempts to obtain the value of the render parameter named <emphasis>yourname</emphasis>. If defined, it should redirect to the <emphasis>hello.jsp</emphasis> JSP page or to the <emphasis>welcome.jsp</emphasis> JSP page.
							</para>
						</callout>
						<callout arearefs="area-Reference_Guide-JavaServer_Pages_Portlet_Example-Portlet_Class.requestDispatcher">
							<para>
								Get a request dispatcher on a file located within the web archive.
							</para>
						</callout>
						<callout arearefs="area-Reference_Guide-JavaServer_Pages_Portlet_Example-Portlet_Class.include">
							<para>
								Perform the inclusion of the markup obtained from the JSP.
							</para>
						</callout>
					</calloutlist>
				</programlistingco>
				
				<para>
					Like the <emphasis>VIEW</emphasis> portlet mode, the specification defines two other modes; <emphasis>EDIT</emphasis> and <emphasis>HELP</emphasis>.
				</para>
				<para>
					These modes need to be defined in the <emphasis>portlet.xml</emphasis> descriptor. This enables the corresponding buttons on the portlet&#39;s window.
				</para>
				<para>
					The generic portlet that is inherited dispatches different views to the methods: <emphasis>doView</emphasis> , <emphasis>doHelp</emphasis> and <emphasis>doEdit</emphasis>.
				</para>
				
<programlisting language="java">...
   protected void doHelp(RenderRequest rRequest, RenderResponse rResponse) throws PortletException, IOException,
         UnavailableException
   {
      rResponse.setContentType(&#34;text/html&#34;);
      PortletRequestDispatcher prd = getPortletContext().getRequestDispatcher(&#34;/jsp/help.jsp&#34;);
      prd.include(rRequest, rResponse);
   }

   protected void doEdit(RenderRequest rRequest, RenderResponse rResponse) throws PortletException, IOException,
         UnavailableException
   {
      rResponse.setContentType(&#34;text/html&#34;);
      PortletRequestDispatcher prd = getPortletContext().getRequestDispatcher(&#34;/jsp/edit.jsp&#34;);
      prd.include(rRequest, rResponse);
   }
...
</programlisting>
				<para>
					Portlet calls happen in one or two phases: when the portlet is rendered and when the portlet is actioned <emphasis>and then</emphasis> rendered.
				</para>
				<para>
					An action phase is a phase where containing some state changes. The render phase will have access to render parameters that will be passed each time the portlet is refreshed (with the exception of caching capabilities).
				</para>
				<para>
					The code to be executed during an action has to be implemented in the <emphasis>processAction</emphasis> method of the portlet.
				</para>
				<programlistingco>
					<areaspec>
						<area coords="2" id="area-Reference_Guide-JavaServer_Pages_Portlet_Example-Portlet_Class.processAction" />
						<area coords="5" id="area-Reference_Guide-JavaServer_Pages_Portlet_Example-Portlet_Class.getActionParameter" />
						<area coords="6" id="area-Reference_Guide-JavaServer_Pages_Portlet_Example-Portlet_Class.setRenderParameter" />
					</areaspec>
<programlisting language="java">...
         public void processAction(ActionRequest aRequest, ActionResponse aResponse) throws PortletException, IOException,
         UnavailableException
   {
      String sYourname = (String) aRequest.getParameter(&#34;yourname&#34;);
      aResponse.setRenderParameter(&#34;yourname&#34;, sYourname);
   }
...
</programlisting>
					<calloutlist>
						<callout arearefs="area-Reference_Guide-JavaServer_Pages_Portlet_Example-Portlet_Class.processAction">
							<para>
								<emphasis>processAction</emphasis> is the method from <emphasis>GernericPorlet</emphasis> to override for the <emphasis>action</emphasis> phase.
							</para>
						</callout>
						<callout arearefs="area-Reference_Guide-JavaServer_Pages_Portlet_Example-Portlet_Class.getActionParameter">
							<para>
								Here the parameter is retrieved through an <emphasis>action URL</emphasis> .
							</para>
						</callout>
						<callout arearefs="area-Reference_Guide-JavaServer_Pages_Portlet_Example-Portlet_Class.setRenderParameter">
							<para>
								The value of <emphasis>yourname</emphasis> is kept to make it available in the rendering phase. The previous line simply copies action parameters to a render parameter for this example.
							</para>
						</callout>
					</calloutlist>
				</programlistingco>

			</section>
			
			<section id="sect-Reference_Guide-JavaServer_Pages_Portlet_Example-JSP_files_and_the_Portlet_Tag_Library">
				<title>JSP files and the Portlet Tag Library</title>
				<para>
					The <emphasis>help.jsp</emphasis> and <emphasis>edit.jsp</emphasis> files are very simple. Note that CSS styles are used as defined in the portlet specification. This ensures that the portlet will render successfully within the theme and across portal vendors.
				</para>
				
<programlisting language="html">&#60;div class=&#34;portlet-section-header&#34;&#62;Help mode&#60;/div&#62;
&#60;div class=&#34;portlet-section-body&#34;&#62;This is the help mode where you can find useful information.&#60;/div&#62;</programlisting>
				
<programlisting language="html">&#60;div class=&#34;portlet-section-header&#34;&#62;Edit mode&#60;/div&#62;
&#60;div class=&#34;portlet-section-body&#34;&#62;This is the edit mode where you can change your portlet preferences.&#60;/div&#62;</programlisting>
				<para>
					The landing page contains the links and form to call the portlet:
				</para>
				<programlistingco>
					<areaspec>
						<area coords="1" id="area-Reference_Guide-JavaServer_Pages_Portlet_Example-JSP_files_and_the_Portlet_Tag_Library.taglib" />
						<area coords="13" id="area-Reference_Guide-JavaServer_Pages_Portlet_Example-JSP_files_and_the_Portlet_Tag_Library.method1" />
						<area coords="20" id="area-Reference_Guide-JavaServer_Pages_Portlet_Example-JSP_files_and_the_Portlet_Tag_Library.method2.1" />
						<area coords="24" id="area-Reference_Guide-JavaServer_Pages_Portlet_Example-JSP_files_and_the_Portlet_Tag_Library.method2.2" />
						<area coords="30" id="area-Reference_Guide-JavaServer_Pages_Portlet_Example-JSP_files_and_the_Portlet_Tag_Library.method3.1" />
						<area coords="31" id="area-Reference_Guide-JavaServer_Pages_Portlet_Example-JSP_files_and_the_Portlet_Tag_Library.method3.2" />
					</areaspec>
<programlisting>&#60;%@ taglib uri=&#34;http://java.sun.com/portlet&#34; prefix=&#34;portlet&#34; %&#62;
 
&#60;div class=&#34;portlet-section-header&#34;&#62;Welcome !&#60;/div&#62;
 
&#60;br/&#62;
 
&#60;div class=&#34;portlet-font&#34;&#62;Welcome on the JSP Hello User portlet,
my name is GateIn Portal. What&#39;s yours ?&#60;/div&#62;
 
&#60;br/&#62;
 
&#60;div class=&#34;portlet-font&#34;&#62;Method 1: We simply pass the parameter to the render phase:&#60;br/&#62;
&#60;a href=&#34;&#60;portlet:renderURL&#62;&#60;portlet:param name=&#34;yourname&#34; value=&#34;John Doe&#34;/&#62;
                &#60;/portlet:renderURL&#62;&#34;&#62;John Doe&#60;/a&#62;&#60;/div&#62;
 
&#60;br/&#62;
 
&#60;div class=&#34;portlet-font&#34;&#62;Method 2: We pass the parameter to the render phase, using valid XML:
Please check the source code to see the difference with Method 1.
&#60;portlet:renderURL var=&#34;myRenderURL&#34;&#62;
    &#60;portlet:param name=&#34;yourname&#34; value=&#39;John Doe&#39;/&#62;
&#60;/portlet:renderURL&#62;
&#60;br/&#62;
&#60;a href=&#34;&#60;%= myRenderURL %&#62;&#34;&#62;John Doe&#60;/a&#62;&#60;/div&#62;
 
&#60;br/&#62;
 
&#60;div class=&#34;portlet-font&#34;&#62;Method 3: We use a form:&#60;br/&#62;
 
&#60;portlet:actionURL var=&#34;myActionURL&#34;/&#62;
&#60;form action=&#34;&#60;%= myActionURL %&#62;&#34; method=&#34;POST&#34;&#62;
         &#60;span class=&#34;portlet-form-field-label&#34;&#62;Name:&#60;/span&#62;
         &#60;input class=&#34;portlet-form-input-field&#34; type=&#34;text&#34; name=&#34;yourname&#34;/&#62;
         &#60;input class=&#34;portlet-form-button&#34; type=&#34;Submit&#34;/&#62;
&#60;/form&#62;
&#60;/div&#62;
</programlisting>
					<calloutlist>
						<callout arearefs="area-Reference_Guide-JavaServer_Pages_Portlet_Example-JSP_files_and_the_Portlet_Tag_Library.taglib">
							<para>
								The portlet taglib which needs to be declared.
							</para>
						</callout>
						<callout arearefs="area-Reference_Guide-JavaServer_Pages_Portlet_Example-JSP_files_and_the_Portlet_Tag_Library.method1">
							<para>
								The first method shown here is the simplest one. <emphasis>portlet:renderURL</emphasis> will create a URL that calls the render phase of the current portlet and append the result at the place of the markup (within a tag). A parameter is also added directly to the URL.
							</para>
						</callout>
						<callout arearefs="area-Reference_Guide-JavaServer_Pages_Portlet_Example-JSP_files_and_the_Portlet_Tag_Library.method2.1">
							<para>
								In this method, the <emphasis>var</emphasis> attribute is used. This avoids having one XML tag within another. Instead of printing the url, the <emphasis>portlet:renderURL</emphasis> tag will store the result in the referenced variable ( <emphasis>myRenderURL</emphasis>).
							</para>
						</callout>
						<callout arearefs="area-Reference_Guide-JavaServer_Pages_Portlet_Example-JSP_files_and_the_Portlet_Tag_Library.method2.2">
							<para>
								The variable <emphasis>myRenderURL</emphasis> is used like any other JSP variable.
							</para>
						</callout>
						<callout arearefs="area-Reference_Guide-JavaServer_Pages_Portlet_Example-JSP_files_and_the_Portlet_Tag_Library.method3.1">
							<para>
								The third method mixes the form submission and action request. Again, a temporary variable is used to put the created URL into.
							</para>
						</callout>
						<callout arearefs="area-Reference_Guide-JavaServer_Pages_Portlet_Example-JSP_files_and_the_Portlet_Tag_Library.method3.2">
							<para>
								The action URL is used in the HTML form.
							</para>
						</callout>
					</calloutlist>
				</programlistingco>
				
				<para>
					In the third method, the action phase is triggered first, then the render phase is triggered, which outputs some content back to the web browser based on the available render parameters. 
					<mediaobject>
						<imageobject role="html">
							<imagedata fileref="images/PortletDevelopment/Standard/jsp_portlet/process.png" format="PNG" scale="1" width="444" align="center" />
						</imageobject>
                        <imageobject role="fo">
							<imagedata fileref="images/PortletDevelopment/Standard/jsp_portlet/process.png" format="PNG" scalefit="1" width="120mm" align="center" />
						</imageobject>
					</mediaobject>
				</para>
			</section>
			
			<section id="sect-Reference_Guide-JavaServer_Pages_Portlet_Example-JSF_example_using_the_JBoss_Portlet_Bridge">
				<title>JSF example using the JBoss Portlet Bridge </title>
				<para>
					To write a portlet using JSF, it is required to have a &#39;bridge&#39;. This software allows developers to write a portlet application as if it was a JSF application. The bridge then negotiates the interactions between the two layers.
				</para>
				<para>
					An example of the JBoss Portlet Bridge is available in <emphasis>examples/JSFHelloUser</emphasis>. The configuration is slightly different from a JSP application. This example can be used as a base to configure instead of creating a new application.
				</para>
				<para>
					As in any JSF application, the file <emphasis>faces-config.xml</emphasis> is required. It must contain the following information:
				</para>
				
<programlisting language="xml">&#60;faces-config&#62;
...
    &#60;application&#62;
      &#60;view-handler&#62;org.jboss.portletbridge.application.PortletViewHandler&#60;/view-handler&#62;
      &#60;state-manager&#62;org.jboss.portletbridge.application.PortletStateManager&#60;/state-manager&#62;
   &#60;/application&#62;
...
&#60;/faces-config&#62;
</programlisting>
				<para>
					The portlet bridge libraries must be available and are usually bundled with the <emphasis>WEB-INF/lib</emphasis> directory of the web archive.
				</para>
				<para>
					The other differences as compared to a regular portlet application can be found in the portlet descriptor. All details about it can be found in the JSR-301 specification that the JBoss Portlet Bridge implements.
				</para>
				<programlistingco>
					<areaspec>
						<area coords="9" id="area-Reference_Guide-JavaServer_Pages_Portlet_Example-JSF_example_using_the_JBoss_Portlet_Bridge.portlet" />
						<area coords="21" id="area-Reference_Guide-JavaServer_Pages_Portlet_Example-JSF_example_using_the_JBoss_Portlet_Bridge.view" />
						<area coords="26" id="area-Reference_Guide-JavaServer_Pages_Portlet_Example-JSF_example_using_the_JBoss_Portlet_Bridge.edit" />
						<area coords="31" id="area-Reference_Guide-JavaServer_Pages_Portlet_Example-JSF_example_using_the_JBoss_Portlet_Bridge.help" />
					</areaspec>
<programlisting language="xml">&#60;?xml version=&#34;1.0&#34; encoding=&#34;UTF-8&#34;?&#62;
&#60;portlet-app xmlns=&#34;http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd&#34;
   xmlns:xsi=&#34;http://www.w3.org/2001/XMLSchema-instance&#34;
   xsi:schemaLocation=&#34;http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd 
                                         http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd&#34;
   version=&#34;2.0&#34;&#62;
   &#60;portlet&#62;
      &#60;portlet-name&#62;JSFHelloUserPortlet&#60;/portlet-name&#62;
      &#60;portlet-class&#62;javax.portlet.faces.GenericFacesPortlet&#60;/portlet-class&#62;
      &#60;supports&#62;
         &#60;mime-type&#62;text/html&#60;/mime-type&#62;
         &#60;portlet-mode&#62;view&#60;/portlet-mode&#62;
         &#60;portlet-mode&#62;edit&#60;/portlet-mode&#62;
         &#60;portlet-mode&#62;help&#60;/portlet-mode&#62;
      &#60;/supports&#62;
      &#60;portlet-info&#62;
         &#60;title&#62;JSF Hello User Portlet&#60;/title&#62;
      &#60;/portlet-info&#62;
      
      &#60;init-param&#62;
         &#60;name&#62;javax.portlet.faces.defaultViewId.view&#60;/name&#62;
         &#60;value&#62;/jsf/welcome.jsp&#60;/value&#62;
      &#60;/init-param&#62;
 
      &#60;init-param&#62;
         &#60;name&#62;javax.portlet.faces.defaultViewId.edit&#60;/name&#62;
         &#60;value&#62;/jsf/edit.jsp&#60;/value&#62;
      &#60;/init-param&#62;
 
      &#60;init-param&#62;
         &#60;name&#62;javax.portlet.faces.defaultViewId.help&#60;/name&#62;
         &#60;value&#62;/jsf/help.jsp&#60;/value&#62;
      &#60;/init-param&#62;
 
   &#60;/portlet&#62;
&#60;/portlet-app&#62;
</programlisting>
					<calloutlist>
						<callout arearefs="area-Reference_Guide-JavaServer_Pages_Portlet_Example-JSF_example_using_the_JBoss_Portlet_Bridge.portlet">
							<para>
								All JSF portlets define <emphasis>javax.portlet.faces.GenericFacesPortlet </emphasis> as the portlet class. This class is part of the JBoss Portlet Bridge.
							</para>
						</callout>
						<callout arearefs="area-Reference_Guide-JavaServer_Pages_Portlet_Example-JSF_example_using_the_JBoss_Portlet_Bridge.view">
							<para>
								This is a mandatory parameter to define what&#39;s the default page to display.
							</para>
						</callout>
						<callout arearefs="area-Reference_Guide-JavaServer_Pages_Portlet_Example-JSF_example_using_the_JBoss_Portlet_Bridge.edit">
							<para>
								This parameter defines which page to display on the &#39;edit&#39; mode.
							</para>
						</callout>
						<callout arearefs="area-Reference_Guide-JavaServer_Pages_Portlet_Example-JSF_example_using_the_JBoss_Portlet_Bridge.help">
							<para>
								This parameter defines which page to display on the &#39;help&#39; mode.
							</para>
						</callout>
					</calloutlist>
				</programlistingco>

			</section>

		</section>

</section>


