0 Replies Latest reply on Dec 2, 2016 6:22 AM by antivirus

    inter portlet communication not working in jboss portal 7.2

    antivirus

      I;m trying to send drop-down value from Portlet A  to Portlet B using form submission.

       

      value is not passed .

       

      Could you please tell what is the issue in this code ?

       

       

       

      Code :

       

      -------------------------default-object.xml---------------------------------------------------

      <?xml version="1.0" encoding="UTF-8"?>

      <!DOCTYPE deployments PUBLIC

         "-//JBoss Portal//DTD Portal Object 2.6//EN"

         "http://www.jboss.org/portal/dtd/portal-object_2_6.dtd">

      <deployments>

        <deployment>

        <parent-ref>default</parent-ref>

        <if-exists>overwrite</if-exists>

        <page>

        <page-name>IPCPage</page-name>

        <window>

        <window-name>PortletAWindow</window-name>

        <instance-ref>PortletAInstance</instance-ref>

        <region>center</region>

        <height>1</height>

       

        </window>

        <window>

        <window-name>PortletBWindow</window-name>

        <instance-ref>PortletBInstance</instance-ref>

        <region>center</region>

        <height>1</height>

        </window>

        <coordination>

                     <wirings>

                        <implicit-mode>TRUE</implicit-mode>

                        <event-wiring>

                           <name>wiringA</name>

                           <sources>

                              <window-coordination>

                                 <window-name>PortletAWindow</window-name>

                                 <qname>{urn:jboss:portal:IPCTest_I:event}CartEvent</qname>

                              </window-coordination>

                           </sources>

                           <destinations>

                              <window-coordination>

                                 <window-name>PortletAWindow</window-name>

                                 <qname>{urn:jboss:portal:IPCTest_I:event}CartEvent</qname>

                              </window-coordination>

                              <window-coordination>

                                 <window-name>PortletBWindow</window-name>

                                 <qname>{urn:jboss:portal:IPCTest_I:event}CartEvent</qname>

                              </window-coordination>

                           </destinations>

                        </event-wiring>

                     </wirings>

                  </coordination>

        </page>

        </deployment>

      </deployments>

       

       

       

       

      -----------------------------------------------------------------portal.xml----------------------------------------------------------

       

       

      <?xml version="1.0" encoding="UTF-8"?>

      <portlet-app

        xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"

        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

        xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"

        version="2.0">

       

       

        <portlet>

        <portlet-name>PortletA</portlet-name>

        <display-name>PortletA</display-name>

        <portlet-class>

        com.abc.PortletA

        </portlet-class>

        <supports>

        <mime-type>text/html</mime-type>

        <portlet-mode>VIEW</portlet-mode>

        </supports>

        <portlet-info>

        <title>PortletA</title>

        </portlet-info>

        <supported-publishing-event>

               <qname xmlns:jbp="urn:jboss:portal:IPCTest_I:event">jbp:CartEvent</qname>

            </supported-publishing-event>

        </portlet>

       

        <portlet>

        <portlet-name>PortletB</portlet-name>

        <display-name>PortletB</display-name>

        <portlet-class>

        com.abc.PortletB

        </portlet-class>

        <supports>

        <mime-type>text/html</mime-type>

        <portlet-mode>VIEW</portlet-mode>

        </supports>

        <portlet-info>

        <title>PortletB</title>

        </portlet-info>

        <supported-processing-event>

               <qname xmlns:jbp="urn:jboss:portal:IPCTest_I:event">jbp:CartEvent</qname>

            </supported-processing-event>

        </portlet>

      </portlet-app>

       

       

       

       

      --------------------------------------------------------portlet-instances.xml--------------------------------------------

      <?xml version="1.0" encoding="UTF-8"?>

      <!DOCTYPE deployments PUBLIC

      "-//JBoss Portal//DTD Portlet Instances 2.6//EN"

      "http://www.jboss.org/portal/dtd/portlet-instances_2_6.dtd">

      <deployments>

        <deployment>

        <instance>

        <instance-id>PortletAInstance</instance-id>

        <portlet-ref>PortletA</portlet-ref>

        </instance>

        </deployment>

        <deployment>

        <instance>

        <instance-id>PortletBInstance</instance-id>

        <portlet-ref>PortletB</portlet-ref>

        </instance>

        </deployment>

      </deployments>

       

       

       

       

      --------------------------------------------------------PortletA.java--------------------------------------------

       

       

      package com.abc;

       

       

      import java.io.IOException;

      import java.io.PrintWriter;

       

       

      import javax.portlet.ActionRequest;

      import javax.portlet.ActionResponse;

      import javax.portlet.GenericPortlet;

      import javax.portlet.PortletException;

      import javax.portlet.PortletSecurityException;

      import javax.portlet.PortletURL;

      import javax.portlet.RenderRequest;

      import javax.portlet.RenderResponse;

       

       

      public class PortletA extends GenericPortlet {

        protected void doView(RenderRequest request, RenderResponse response)

        throws PortletException, PortletSecurityException, IOException {

        response.setContentType("text/html");

        PrintWriter writer = response.getWriter();

        PortletURL addURL = response.createActionURL();

              addURL.setParameter("op", "add");

        writer.println("<form action=\"" + addURL.toString() + "\" 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();

        }

        public void processAction(ActionRequest actionRequest, ActionResponse actionResponse)

               throws PortletException, IOException {

               String value = actionRequest.getParameter("color");

               actionResponse.setEvent(CartEvent.QNAME, new CartEvent(value));

        }

      }

       

       

      --------------------------------------------------------PortletB.java--------------------------------------------

      package com.abc;

       

       

      import java.io.IOException;

      import java.io.PrintWriter;

      import java.util.List;

       

       

      import javax.portlet.ActionRequest;

      import javax.portlet.ActionResponse;

      import javax.portlet.Event;

      import javax.portlet.EventRequest;

      import javax.portlet.EventResponse;

      import javax.portlet.GenericPortlet;

      import javax.portlet.PortletException;

      import javax.portlet.PortletSecurityException;

      import javax.portlet.PortletSession;

      import javax.portlet.RenderRequest;

      import javax.portlet.RenderResponse;

       

       

      import org.jboss.portal.api.node.PortalNode;

      import org.jboss.portal.api.node.event.PortalNodeEvent;

      import org.jboss.portal.api.node.event.PortalNodeEventContext;

      import org.jboss.portal.api.node.event.PortalNodeEventListener;

      import org.jboss.portal.api.node.event.WindowActionEvent;

       

       

      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 = (String)request.getPortletSession().getAttribute("color");

        response.setContentType("text/html");

        PrintWriter writer = response.getWriter();

        writer.println("<div" + (color == null ? "" : " style=\"color:" + color + ";\"") + ">some text in color</div>");

        writer.close();

        }

       

       

        public void processEvent(EventRequest eventRequest, EventResponse eventResponse)

               throws PortletException, IOException

           {

        CartEvent cartEvent = null;

               PortletSession session = eventRequest.getPortletSession();

              

               Event event = eventRequest.getEvent();

               if(event.getName().equals("CartEvent"))

               {

                   cartEvent = (CartEvent)event.getValue();

                  

               }

               session.setAttribute("color", cartEvent.getId());

           }

      }

      --------------------------------------------------------CartEvent.java--------------------------------------------

      package com.abc;

       

       

      import java.io.Serializable;

      import javax.xml.namespace.QName;

       

       

      public class CartEvent

          implements Serializable

      {

       

       

          public CartEvent(String id)

          {

              this.id = id;

          }

       

       

          public String getId()

          {

              return id;

          }

       

       

          private String id;

          public static final QName QNAME = new QName("urn:jboss:portal:IPCTest_I:event", "CartEvent");

       

       

      }

       

       

      --------------------------------------------------------portlet-instances.xml--------------------------------------------