我有一个在 WebSphere Portal 6.0 上运行的 JSR-168 portlet 应用程序。
在应用程序的 portlet.xml 文件中,特定的 portlet 定义如下:
<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>
请注意,它定义了一个名为“com.ibm.faces.portlet.page.view”的参数,其值为“/TEIndividual/TEIndividualView.jsp”,这是呈现portlet 时使用的初始JSP。
我需要根据数据库查询的结果有条件地更改该参数的值。
我认为这可能涉及 MHFacesHibernatePortlet 类中某处的重定向。
这是正确的,我应该修改类的什么方法?
编辑,包含两个类的更多信息和源代码......
我为下面的 MHFacesHibernatePortlet 类以及它扩展的 MHFacesPortlet 类添加了代码。
在应用程序的 portlet.xml 文件中,多个 portlet 都配置为使用 MHFacesHibernatePortlet 类,但每个 portlet 使用不同的初始 JSP。上面的“个人 Portlet”只是一个例子。
我只需要有条件地更改某些 portlet 的初始 JSP,因此我有一些代码应该能够根据我想要更改的列表检查 JSP 名称,然后运行 Hibernate 查询,然后更改 JSP仅在必要时命名。
我看到MHFacesPortlet.processAction
它读取相关参数并request.getPortletSession().setAttribute()
在某些条件下将其传递给,因此我尝试将代码放在那里并更改homeJsp
变量,但这不起作用。添加一些日志记录后,我发现当我转到具有这些 portlet 之一的页面时,甚至没有调用 processAction。
MHFacesHibernatePortlet 类的来源:
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();
}
}
}
MHFacesPortlet 类的来源:
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);
}
}