このトピックでは、ポートレット間でプロパティーを交換する方法について説明します。 このトピックを読む前に、コンソール・ページの起動のための概念に熟知している必要があります。
情報は、addSharedPortlet() メソッドを使用して、同じページ上のポートレットに提供することができます。 プロパティー値のタイプは、 com.ibm.portal.propertybroker.property.PropertyValue です。 ページの起動 内の例は、PropertyValue インターフェースのインスタ ンス (propertyValues) を使用してページへパスされたこれらのプロパティーを示し、PropertyFactory インターフェースを使用してオブジェクトを作成した方法を示します。
PortletContext サンプルからの SetServer.java ソースは、同じページ上のポートレットへプロパティーを受け渡す方法を表示します。 既にポートレットが JNDI ルックアップを実行して、PropertyFactory、DynamicUIManagerFactoryService、および URLGeneratorFactoryService サービスが使用可能であることを判別していることを前提としています。 これは ページの起動 で説明されています。
Context ctx = null; ObjectID portletDefinitionID1 = null; ObjectID portletDefinitionID2 = null; String portletname1="com.ibm.isclite.samples.PortletContext/PortletGetPerformance"; String portletname2="com.ibm.isclite.samples.PortletContext/PortletGetApps"; PortletSession ps = request.getPortletSession(false); try { ctx = new InitialContext(com.ibm.portal.jndi.Constants.ENV); portletDefinitionID1 = (ObjectID)ctx.lookup("portal:config/portletdefinition/"+portletname1); portletDefinitionID2 = (ObjectID)ctx.lookup("portal:config/portletdefinition/"+portletname2); } catch (NamingException ne) { logger.log(Level.FINE, "portletdefinitionID not found - Naming exception:"+ne.getMessage()); return; } logger.log(Level.FINE, "portletdefinitionID="+portletDefinitionID1.toString()); try { PropertyController cproperty = propertyFactoryService.createProperty(myconfig); cproperty.setType("String"); PropertyValue[] propertyValues = new PropertyValue[1]; propertyValues[0] = propertyFactoryService.createPropertyValue(request, cproperty, serverName); DynamicUICtrl dmanagerCtrl = dynamicUIManagerFactoryService.getDynamicUICtrl(request, response, "isc.tasklaunch"); ObjectID newPortletID1 = dmanagerCtrl.addSharedPortlet(portletDefinitionID1, null, propertyValues); ObjectID newPortletID2 = dmanagerCtrl.addSharedPortlet(portletDefinitionID2, null, propertyValues); logger.log(Level.FINE, "portlet ID created:"+newPortletID1.getOID()); } catch ...
ObjectID newPageID = dmanagerCtrl.addPage(pageDefinitionID, null, propertyValues); RedirectURLGenerator urlGenerator = urlGeneratorFactoryService.getURLGenerator(request, response); EngineURL redirectURL = urlGenerator.createPageURL(newPageID); response.sendRedirect(redirectURL.toString());
URLGeneratorFactoryService を使用するには、まずポートレットは、このポートレット・サービス用に JNDI ルックアップを実行する必要があります。 GetApps.java ソースを参照して、ポートレット・サービスへの参照の取得方法を調べます。
プロパティーを受信するには、ターゲット・ポートレットは、 portlet.xml 内の com.ibm.portal.pagecontext.enable 設定パラメーターに true の値を指定する必要があります。 ポートレットが以降の更新を受信する場合、com.ibm.portal.context.enable 読み取り専用設定も true に設定される必要があります。 String プロパティー・タイプのみがサポートされ、コンテキストはアクション要求のパラメーターとして渡されます。 以下の例は、GetApps ポートレットが、SetServer ポートレットによって渡されたプロパティーを受信する方法を表示します。
public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException { PortletSession ps = request.getPortletSession(true); appDeployed = request.getParameter("appDeployed"); serverName=request.getParameter("servername"); ps.setAttribute("servername",serverName); ps.setAttribute("appDeployed",appDeployed); launchPage(request, response); }
String action = req.getParameter(com.ibm.portal.action.name); if (action!=null && action.equalsIgnoreCase("com.ibm.portal.pagecontext.receive")) { // code to get the properties as a parameter on the request }