Sun Java System Portal Server 7 Developer's Guide

Sample Code Fragments for Provider to Portlet Conversion

This section includes some sample code fragments for Provider to Portlet conversion.

Provider to Portlet Mapping

The 

Maps To (or can use) 

ProviderContext.getStringAttribute("firstname");

Map ui =  (Map)renderRequest.getAttribute("javax.portlet.userinfo");
String firstname = (String)ui.get("firstname");
ProviderContext.getSessionProperty()/setSessionProperty()
PortletSession.getAttribute(), PortletSession.setAttribute()
ProviderContext.getDesktopURL()
PortletURL.RenderResponse.createRenderURL(), RenderResponse.createActionURL()

Dispatching to a JSP


PortletRequestDispatcher dispatcher = pContext.getRequestDispatcher("test.jsp");
dispatcher.include(request, response);

Help Documentation

Help documentation for portlets follows a different scheme than in the providers. The help file name is stored as a preference and content is generated from that file the same way as any other content type.

getHelp()

In Provider, this method returns a helpURL which can be pointing to a static help file.

doHelp()

For portlets, this method has to be implemented for writing out the help content dynamically.

Title Mapping

getTitle()

For ProviderAdapter, this method returns the title from the Display Profile title property.

For portlets, the title is returned by the portlet implementation.

editType Property

For a provider, the editType display profile property can be specified to determine whether the provider implementation will draw the complete edit page or a subset of it.

For portlets, the editType is always EDIT_COMPLETE and the complete page including the form, the Finish, and the Cancel buttons have to be generated by the portlet. Only the banner and footer are drawn by the PortletEdit.jsp in PortalServer-DataDir/portals/portal-ID/desktop/default directory.

PortletPreferences Mapping

The

ProfileProviderAdapter.getStringProperty(key)

maps to

PortletPreferences.getValue(key, default)

The

ProfileProviderAdapter.getListProperty(key)

maps to

PortletPreferences.getValues(key, default[])