I have a JSR-168 portlet application running on WebSphere Portal 6.0.
In the application's portlet.xml file, a specific portlet is defined as follows:
<portlet>
<portlet-name>Individual Portlet</portlet-name>
<display-name>Individual Portlet</display-name>
<display-name xml:lang="en">
Individual Portlet
</display-name>
<portlet-class>
com.companyname.util.hibernate.MHFacesHibernatePortlet
</portlet-class>
<init-param>
<name>com.ibm.faces.portlet.page.view</name>
<value>/TEIndividual/TEIndividualView.jsp</value>
</init-param>
<init-param>
<name>wps.markup</name>
<value>html</value>
</init-param>
<expiration-cache>0</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>view</portlet-mode>
</supports>
<resource-bundle>
resources.nl.IndividualPortletResource
</resource-bundle>
<portlet-info>
<title>Individual Portlet</title>
</portlet-info>
<portlet-preferences>
<preference>
<name>portletType</name>
<value>individual</value>
</preference>
<preference>
<name>wmmAttribSalesmanId</name>
<value>facsimileTelephoneNumber</value>
</preference>
</portlet-preferences>
</portlet>
Note that it defines a parameter named "com.ibm.faces.portlet.page.view" with the value "/TEIndividual/TEIndividualView.jsp", which is the initial JSP used when the portlet is rendered.
I need to conditionally change the value of that parameter based on the result of a database query.
I think this might involve a redirect somewhere in the MHFacesHibernatePortlet class.
Is that correct, and what method of the class should I modify?
Edit, with more info and source code for two classes...
I've added code for the MHFacesHibernatePortlet class below, and also the MHFacesPortlet class which it extends.
In the application's portlet.xml file, multiple portlets are all configured to use the MHFacesHibernatePortlet class, but each portlet uses a different initial JSP. The "Individual Portlet" above is just one example.
I need to conditionally change the initial JSP only for some of the portlets, so I have some code that should be able to check the JSP name against a list of the ones I want to change, then run a Hibernate query, then change the JSP name only if necessary.
I saw in MHFacesPortlet.processAction
that it reads the relevant parameter and passes it to request.getPortletSession().setAttribute()
under some conditions, so I tried to put my code there and change the homeJsp
variable, but that didn't work. After adding some logging I found that processAction isn't even called when I go to a page with one of these portlets.
Source for the MHFacesHibernatePortlet class:
package com.companyname.util.hibernate;
import java.io.IOException;
import javax.portlet.PortletException;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import com.companyname.util.portlet.MHFacesPortlet;
public class MHFacesHibernatePortlet extends MHFacesPortlet {
/*
* (non-Javadoc)
*
* @see com.ibm.faces.webapp.FacesGenericPortlet#doConfigure(javax.portlet.RenderRequest,
* javax.portlet.RenderResponse)
*/
public void doConfigure(RenderRequest arg0,RenderResponse arg1)
throws PortletException,IOException {
super.doConfigure(arg0,arg1);
try {
HibernateUtil.commitTransaction();
} finally {
HibernateUtil.closeSession();
}
}
/*
* (non-Javadoc)
*
* @see javax.portlet.GenericPortlet#doView(javax.portlet.RenderRequest,
* javax.portlet.RenderResponse)
*/
public void doView(RenderRequest arg0,RenderResponse arg1)
throws PortletException,IOException {
super.doView(arg0,arg1);
// Close and commit open hibernate transactions
try {
HibernateUtil.commitTransaction();
} finally {
HibernateUtil.closeSession();
}
}
}
Source for the MHFacesPortlet class:
package com.companyname.util.portlet;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletException;
import javax.portlet.PortletMode;
import com.ibm.faces.webapp.FacesGenericPortlet;
public class MHFacesPortlet extends FacesGenericPortlet {
private static final String FACES_CURRENT_PAGE_STUB="com.ibm.faces.portlet.page.";
/** parameter used to fire an extended action */
public static final String PARAMETER_EXTENDED_ACTION="extAction";
/** Action to reset view mode of the portlet */
public static final String ACTION_VIEW_MODE_RESET="viewReset";
public MHFacesPortlet() {
super();
}
/*
* (non-Javadoc)
*
* @see javax.portlet.Portlet#processAction(javax.portlet.ActionRequest,
* javax.portlet.ActionResponse)
*/
public void processAction(ActionRequest request,ActionResponse response)
throws PortletException {
// Check if we need to process an extended action
String extendedAction=(String)request
.getParameter(PARAMETER_EXTENDED_ACTION);
if (extendedAction!=null&&!extendedAction.equals("")) {
// Reset view mode
if (extendedAction.equals(ACTION_VIEW_MODE_RESET)) {
PortletMode portletMode=request.getPortletMode();
String modeString=null;
if (portletMode.equals(PortletMode.EDIT)) modeString="edit";
else if (portletMode.equals(PortletMode.VIEW)) modeString="view";
else if (portletMode.equals(PortletMode.HELP)) modeString="help";
else modeString=portletMode.toString();
String homeJsp=getPortletConfig().getInitParameter(
FACES_CURRENT_PAGE_STUB+modeString);
request.getPortletSession().setAttribute(
FACES_CURRENT_PAGE_STUB+modeString,homeJsp);
}
}
//delegate to ibm faces
super.processAction(request,response);
}
}
MHFacesHibernatePortlet
. (Given theinit-param/name
ofcom.ibm.faces...
, I'm guessing that this portlet class must extend a base IBM portlet class.) – ziesemer