Changing a JSF portlet page without a JSF action

You can switch to a page in a Faces portlet by extending the FacesPortlet class.

  1. When you create a new Faces portlet in, extend the FacesPortlet class by following the steps on the Portlet Settings page of the configuration wizard to

    Generate a custom portlet class.

    If the FacesPortlet class was not extended when creating the portlet, use the Portlet Deployment descriptor to change the portlet class as described in Configuring JSR 168 portlets

  2. Using the FacesPortlet class, implement the getView() method

This method returns a string which will be a valid JSF view ID. A view ID is usually a JSP name with a starting "/" (For example,

/Accounts.jsp or /books/titles/title1.jsp). The FacesPortlet class calls this method every time it needs to determine which page to process. If the method returns null (which is a default), then the standard JSF navigation mechanism is invoked. If the method returns a not-null value, then this value is used instead.

Note: The getView() method is only available for new Faces portlets that you create using V7 of RationalĀ® tools. If you are using old Faces portlet classes (typically, found in portlets you would have created in earlier versions of Rational tools), you will have to set the session attributes as described below. But we recommend that you use the new Faces portlet class and implement the getView() switch.

You can also refer to the chart below for differences between product versions:

Table 1. Differences between Faces portlet class names
Ā  Faces portlet in Rational tools V6.0 or later Faces portlet in Rational tools V7.0 or later
JAR name jsf-portlet.jar jsf-portletbridge.jar
portlet.xml

Portlet class

com.ibm.faces.webapp.FacesGenericPortlet

com.ibm.faces.portlet.FacesPortlet

faces-config.xml

Faces Context Factory

Variable Resolver

com.ibm.faces.context.PortletFacesContextFactoryImpl

com.ibm.faces.application.PortletVariableResolver

n/a

com.ibm.faces.portlet.PortletVariableResolver

For old Faces portlets created with earlier versions of Rational tools

If you want to switch to a page without using a Faces action, you can set a JSP file path to the one of the following session attributes:

Table 2. File Paths for JSP Session Attributes
Session Attribute Name Description
com.ibm.faces.portlet.page.view The JSP file path for the View mode.
com.ibm.faces.portlet.page.edit The JSP file path for the Edit mode.
com.ibm.faces.portlet.page.help The JSP file path for the Help mode.
com.ibm.faces.portlet.page.config The JSP file path for the Configure mode.

For example, you can create a subclass of your Faces portlet and set the session attribute in the doView() method to change the page in some conditions:

public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
		if (...) {
			request.getPortletSession().setAttribute("com.ibm.faces.portlet.page.view", "/MyPage.jsp");
		}

		super.doView(request, response);
	}

The session attributes are only effective before the Faces lifecycle is started by the Faces portlet's methods, such as processAction(), or actionPerformed(), or doView(), etc. Once the Faces lifecycle starts and the Faces UI component tree is created, the session attributes are not read by the Faces portlet.

 

Related concepts

Creating Faces portlets and projects

 

Related tasks

Creating portlet JSP files

Adding and updating Faces portlet modes for existing IBM portlets

Adding and updating Faces portlet modes