WebSphere Portal6.0で実行されているJSR-168ポートレット・アプリケーションがあります。
アプリケーションのportlet.xmlファイルでは、特定のポートレットが次のように定義されています。
<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」という名前のパラメーターを、ポートレットのレンダリング時に使用される初期JSPである値「/TEIndividual/TEIndividualView.jsp」で定義していることに注意してください。
データベースクエリの結果に基づいて、そのパラメータの値を条件付きで変更する必要があります。
これには、MHFacesHibernatePortletクラスのどこかにリダイレクトが含まれる可能性があると思います。
それは正しいですか、クラスのどのメソッドを変更する必要がありますか?
2つのクラスの詳細とソースコードを使用して編集します...
以下にMHFacesHibernatePortletクラスのコードと、それが拡張するMHFacesPortletクラスのコードを追加しました。
アプリケーションのportlet.xmlファイルでは、複数のポートレットがすべてMHFacesHibernatePortletクラスを使用するように構成されていますが、各ポートレットは異なる初期JSPを使用します。上記の「個別ポートレット」はほんの一例です。
一部のポートレットについてのみ初期JSPを条件付きで変更する必要があるため、JSP名を変更したいもののリストと照合し、Hibernateクエリを実行してから、JSPを変更できるコードがあります。必要な場合にのみ名前を付けます。
MHFacesPortlet.processAction
関連するパラメーターを読み取り、特定のrequest.getPortletSession().setAttribute()
条件下でそれを渡すことがわかったので、そこにコードを配置して変数を変更しようとしましたがhomeJsp
、それは機能しませんでした。ロギングを追加した後、これらのポートレットの1つを含むページに移動しても、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);
}
}