ColdFusion portlet components



You can configure your ColdFusion portlet components to define its modes, window states, title, scope, and parameters.

For references of ColdFusion Portlet API, see the JSR-168 specification for all javax.portlet.* classes.

Currently, WSRP 1.0 is the supported standard for portlets.

Portlet modes

Portal servers typically allow three portlet modes: View, Edit, and Help.

The View mode is the default state when rendering a portlet. The portlet window has links in the title bar that enable you to change the mode to Help or Edit.

To add a Help mode view, add the doHelp() with the same signature as the doView() function.

To support the edit mode create the doEdit().

Portlet window states

Most portal servers support three window states (normal, minimized, and maximized). You can obtain the current window state by calling the getWindowState() method of the ColdFusionPortlet base component.

Portlet title

To set the portlet title, add a method to the CFC called getTitle as follows:

<cffunction name="getTitle" returntype="string" output="false" access="public"> 
        <cfargument name="renderRequest" type="any" required="true" hint="A 
        javax.portlet.RenderRequest java object"> 
        <cfreturn "My ColdFusion Portlet"> 
</cffunction>

Portlet scope

The ColdFusion portlet toolkit defines the variable request.portlet. It contains the following structures:

request.portlet.parameters - Parameters of the Portlet Request 
request.portlet.attributes - attributes of the Portlet Request 
request.portlet.properties - properties of the Portlet Request

These variables are defined for convenience and convention.

Create portlet parameters

To create different page views within your portlet you can configure the render parameters such as renderURL.

For example, to set the renderURL parameter:

  1. Create a renderURL parameter

    <cfset params = StructNew()> 
    <cfset params.page = "somepage"> 
    <cfoutput><a href="#createRenderURL(params)#">Link to somepage</a>
  2. Check for parameter in the page and render conditionally:

    <cfparam name="request.portlet.parameters.page" default=""> 
    <cfif request.portlet.parameters.page IS "somepage"> 
        <cfinclude template="somepage.cfm"> 
    <cfelse> 
        <!--- put step 1 here ---> 
    </cfif>

Processing actions using form posts

To process a form post, use the createActionURL() function, which generates the form action URL.

For example:

<cfoutput> 
    <form action="#createActionURL()#" method="post"> 
        Value:         <input type="text" name="action_value" > 
                <input type="submit" value="Process Action" /> 
    </form> 
</cfoutput>

When the form is submitted, the portal container calls the processAction() method in your CFC. So, add this method as follows:

<cffunction name="processAction" returntype="void" access="public" output="false" hint="Called by the portlet container to allow the portlet to process an action request."> 
    <cfargument name="actionRequest" type="any" required="true" hint="A 
    javax.portlet.ActionRequest java object"> 
    <cfargument name="actionResponse" type="any" required="true" hint="A 
    javax.portlet.ActionResponse java object"> 
    <cfif IsDefined("request.portlet.parameters.action_value")> 
    <!--- do something with this value, such as update your database --->         
    </cfif>     
</cffunction>

Examples

The following examples show how you can configure portlets. You can add the following code to the doView() method depending on whether you are configuring the portlet on a local or remote server.

  • To get portal user information:

    JSR:

    <cfoutput>#renderRequest.getRemoteUser()#</cfoutput>

    WSRP:

    <cfdump var = #renderRequest.getAttribute("javax.portlet.userinfo")#>
  • To display PDF:

    <cfdocument format="pdf" src="http://www.google.com" filename="cfdoc1.pd f " overwrite="true"> 
    </cfdocument> 
    <cfset pdfURL = getPortletResponse().encodeURL(getPortletRequest().getContextPath() & "/<path of pdf>/cfdoc1.pdf")> 
    <cfoutput> 
        <object data="#pdfURL#" type="application/pdf" width="600" height="400"> 
        </object> 
    </cfoutput>
  • To display Ajax components, all the URLs used in portlets must be encoded.

    CFPOD: 
    <cfset sourceURL = getPortletResponse().encodeURL(getPortletRequest().getContextPath() & "/<path to cfm>/expandpath.cfm")> 
    <cfpod name="pod01" source="#sourceURL#" height="500" width="300" title="Example CFPod"/> 
    expandpath: 
    <cfoutput>#ExpandPath("./")#</cfoutput> 
    CFWINDOW: 
    <cfset sourceURL = getPortletResponse().encodeURL(getPortletRequest().getContextPath() & "/<path to cfm>/expandpath.cfm")> 
    <cfwindow title="Test Window" name="myWindow" width="200" height="200" initShow="true" source="#sourceURL#"> 
    </cfwindow>