Author: thomas.heute(a)jboss.com
Date: 2010-06-29 08:58:00 -0400 (Tue, 29 Jun 2010)
New Revision: 13947
Modified:
docs/enterprise/trunk/Reference_Guide/en-US/Portal_API.xml
Log:
JBEPP-158: Remove note about future JSR-286 support from EPP 4.3 docs
Modified: docs/enterprise/trunk/Reference_Guide/en-US/Portal_API.xml
===================================================================
--- docs/enterprise/trunk/Reference_Guide/en-US/Portal_API.xml 2010-06-28 09:35:12 UTC
(rev 13946)
+++ docs/enterprise/trunk/Reference_Guide/en-US/Portal_API.xml 2010-06-29 12:58:00 UTC
(rev 13947)
@@ -481,166 +481,6 @@
<para>That's it - we now have a user counter that will display it
states each time a user logs-in our logs-out.</para>
</section>
<section>
- <title>Achieving Inter Portlet Communication with the events
mechanism</title>
- <para>The first version of the Portlet Specification (JSR 168),
regretfully, did not cover interaction between
- portlets. The side-effect of diverting the issue to the subsequent release of
the specification, has
- forced portal vendors to each craft their own proprietary API to achieve inter
portlet communication. Here we will
- see how we can use the event mechanism to pass parameters from one portlet to
the other (and only to the other portlet).</para>
- <para>The overall scenario will be that Portlet B will need to be updated
based on some parameter set on Portlet A.
- To achieve that we will use a portal node event.</para>
- <para>Portlet A is a simple Generic portlet that has a form that sends a
color name:
- <programlisting><![CDATA[
-public class PortletA extends GenericPortlet
-{
- protected void doView(RenderRequest request, RenderResponse response)
- throws PortletException, PortletSecurityException, IOException
- {
- response.setContentType("text/html");
- PrintWriter writer = response.getWriter();
- writer.println("<form action=\"" + response.createActionURL() +
"\" method=\"post\">");
- writer.println("<select name=\"color\">");
- writer.println("<option>blue</option>");
- writer.println("<option>red</option>");
- writer.println("<option>black</option>");
- writer.println("</select>");
- writer.println("<input type=\"submit\"/>");
- writer.println("</form>");
- writer.close();
- }
-}
- ]]></programlisting>
- </para>
- <para>The other portlet (Portlet B) that will receive parameters from
Portlet A is also a simple Generic portlet:
- <programlisting><![CDATA[
-public class PortletB extends GenericPortlet
-{
-
- public void processAction(ActionRequest request, ActionResponse response)
- throws PortletException, PortletSecurityException, IOException
- {
- String color = request.getParameter("color");
- if (color != null)
- {
- response.setRenderParameter("color", color);
- }
- }
-
- protected void doView(RenderRequest request, RenderResponse response)
- throws PortletException, PortletSecurityException, IOException
- {
- String color = request.getParameter("color");
- response.setContentType("text/html");
- PrintWriter writer = response.getWriter();
- writer.println("<div" +
- (color == null ? "" : " style=\"color:" + color +
";\"") +
- ">some text in color</div>");
- writer.close();
- }
-
- // Inner listener explained after
-}
- ]]></programlisting>
- </para>
- <para>With those two portlets in hands, we just want to pass parameters
from Portlet A to Portlet B (the color in
- as a request parameter in our case). In order to achieve this goal, we will
write an inner Listener in Portlet B
- that will be triggered on any WindowActionEvent of Portlet A. This listener will
create a new WindowActionEvent
- on the window of Portlet B.
- <programlisting role="java"><![CDATA[
-public static class Listener implements PortalNodeEventListener
-{
- public PortalNodeEvent onEvent(PortalNodeEventContext context, PortalNodeEvent event)
- {
- PortalNode node = event.getNode();
- // Get node name
- String nodeName = node.getName();
- // See if we need to create a new event or not
- WindowActionEvent newEvent = null;
- if (nodeName.equals("PortletAWindow") && event instanceof
WindowActionEvent)
- {
- // Find window B
- WindowActionEvent wae = (WindowActionEvent)event;
- PortalNode windowB = node.resolve("../PortletBWindow");
- if (windowB != null)
- {
- // We can redirect
- newEvent = new WindowActionEvent(windowB);
- newEvent.setParameters(wae.getParameters());
-
- newEvent.setMode(wae.getMode());
- newEvent.setWindowState(WindowState.MAXIMIZED);
-
- // Redirect to the new event
- return newEvent;
- }
- }
- // Otherwise bubble up
- return context.dispatch();
- }
-}
- ]]></programlisting>
- </para>
- <para>
- It is important to note here some of the important items in this listener
class.
- Logic used to determine if the requesting node was Portlet A.:
-
<programlisting>nodeName.equals("PortletAWindow")</programlisting>
- </para>
- <para>
- Get the current window object so we can dispatch the event to it:
- <programlisting>PortalNode windowB =
node.resolve("../PortletBWindow");</programlisting>
- </para>
- <para>
- Set the original parameter from Portlet A, so Portlet B can access them in
its processAction():
-
<programlisting>newEvent.setParameters(wae.getParameters());</programlisting>
- </para>
- <!--
- <para>
- Modify Portlet B windowmode and/or windowstate (ie, Maximize and place in
Edit Mode):
- <programlisting>
-newEvent.setMode(wae.getMode()); // Mode.EDIT;
-newEvent.setWindowState(wae.getWindowState()); //
WindowState.MAXIMIZED</programlisting>
- </para>
- -->
- <para>
- We still need to register our listener as an mbean:
- <programlisting role="xml">
-<![CDATA[<mbean
- code="org.jboss.portal.core.event.PortalEventListenerServiceImpl"
- name="portal:service=ListenerService,type=test_listener"
- xmbean-dd=""
- xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
- <xmbean/>
- <depends
- optional-attribute-name="Registry"
-
proxy-type="attribute">portal:service=ListenerRegistry</depends>
- <attribute name="RegistryId">test_listener</attribute>
- <attribute name="ListenerClassName">
- org.jboss.portal.core.samples.basic.event.PortletB$Listener
- </attribute>
-</mbean>]]></programlisting>
- For node events, we also need to declare on which node we want to listen,
this is done by modifying
- the <literal>*-object.xml</literal> that defines your portal
nodes. In this example we want to trigger
- the listener each time the window containing the portlet A is actioned. We
can add the <literal>listener</literal>
- tag to specify that out listener with
<literal>RegistryId</literal>=test_listener should be triggered
- on events on the embedding object.
- <programlisting>
-<![CDATA[...
- <window>
- <window-name>PortletAWindow</window-name>
- <instance-ref>PortletAInstance</instance-ref>
- <region>center</region>
- <height>0</height>
- <listener>test_listener</listener>
- </window>
-...]]>
- </programlisting>
- Of course we could have added it at the page level instead of the window
level. Note that a unique listener
- can be specified, the event mechanism is primarily done to let the developer
change the navigation state of the
- portal, this example being a nice side-effect of this feature.
- </para>
- <note><para>The portlet 2.0 specification (JSR 286) will cover Inter
Portlet Communication so that portlets using it
- can work with different portal vendors.</para></note>
- </section>
- <section>
<title>Link to other pages</title>
<para>Linking to some other pages or portals is also out of the scope of
the portlet
specification. As seen previously JBoss Portal offers an API in order to create
links
Show replies by thread