4 Replies Latest reply on Sep 10, 2008 12:17 AM by Jack Daniels

    IPC - Event not fired

    krishna Gopu Newbie

      Hi,
      I was trying to work with the example given for IPC but with some custom code of mine. I was not able to achieve any result. Please advice.

      I have a myportal.sar where in i put the jboss-service.xml with the following code.

      <server>
       <mbean
       code="org.jboss.portal.core.event.PortalEventListenerServiceImpl"
       name="portal:service=ListenerService,type=PortalInitListener"
       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">PortalInitListener</attribute>
       <attribute name="ListenerClassName">
       gov.sba.bgportal.jboss.examples.PortalInitService
       </attribute>
       </mbean>
       <mbean
       code="org.jboss.portal.core.event.PortalEventListenerServiceImpl"
       name="portal:service=ListenerService,type=NodeEventListener"
       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">NodeEventListener</attribute>
       <attribute name="ListenerClassName">
       gov.sba.bgportal.jboss.examples.MyEventPortlet$Listener
       </attribute>
       </mbean>
       </server>
      


      My first listener PortalInitListener is of type PortalEventListener and works good for SessionEvents.

      Second one is a PortalNodeEventListener. This never gets fired.
      There are two portlets communicating the information through parameters.

      FirstPortlet:
      public class AlfrescoRenditionPrtlet extends GenericPortlet
      {
       protected void doView(RenderRequest rRequest, RenderResponse rResponse) throws PortletException, IOException, UnavailableException
       {
       String renditionFileURL = rRequest.getPreferences().getValue("renditionFileURL", "/AdminHome/404.html");
       String PropegatedValue = rRequest.getParameterMap().toString();
       String s = "parameterMAP AlfrescoRenditionPrtlet ---->"+PropegatedValue;
       String s1 = "fromContext AlfrescoRenditionPrtlet ---->"+getPortletContext().getAttribute("fromContext");
       rResponse.setContentType("text/html");
       PrintWriter writer = rResponse.getWriter();
       writer.println("<form action=\"" + rResponse.createActionURL() + "\" method=\"post\">");
       writer.println("<input type=\"text\" name=\"EventPropegatedValue\" value=\"Hidden value from PortletItSelf\"/> ");
       writer.println("<input type=\"submit\"/>");
       writer.println("</form><br>");
       writer.println(s+"<br>"+s1);
       writer.close();
       }
      }
      

      SecondPortlet:

      public void processAction(ActionRequest request, ActionResponse response) {
       String PropegatedValue = request.getParameter("EventPropegatedValue");
       response.setRenderParameter("PropegatedValue", PropegatedValue);
      }
      
      protected void doView(RenderRequest rRequest, RenderResponse response) throws PortletException, IOException, UnavailableException
      {
       String PropegatedValue = rRequest.getParameterMap().toString();
       String s = "PropegatedValue MyEventPortlet ---->"+PropegatedValue;
       String renditionFileURL = rRequest.getPreferences().getValue("renditionFileURL", "/AdminHome/404.html");
       String s1 = "fromContext MyEventPortlet ---->"+getPortletContext().getAttribute("fromContext");
       response.setContentType("text/html");
       PrintWriter writer = response.getWriter();
       writer.println(s+"<br>"+s1);
       writer.close();
      }
      


      Listener:
      public static class Listener implements PortalNodeEventListener{
       public PortalNodeEvent onEvent(PortalNodeEventContext context, PortalNodeEvent event) {
       PortalNode node = event.getNode();
       String nodeName = node.getName();
       WindowActionEvent newEvent = null;
       if (nodeName.equals("ARPWindow1") && event instanceof WindowActionEvent)
       {
       WindowActionEvent wae = (WindowActionEvent)event;
       PortalNode window2 = node.resolve("../MEPWindow2");
       if (window2 != null)
       {
       newEvent = new WindowActionEvent(window2);
       Map map = new HashMap<Object,Object>();
       map.put("EventPropegatedValue", "~~~~~This is the value~~~~");
       map.putAll(wae.getParameters());
       newEvent.setParameters(map);
       }
       }
       if (newEvent != null)
       {
       return newEvent;
       }
       else
       {
       return context.dispatch();
       }
       }
       }
      


      I am unable to locate the problem. Any one there to advice me.
      Any sort of help is thanked.




        • 1. Re: IPC - Event not fired
          krishna Gopu Newbie

          I Got it.
          I missed out the link for it in the *-Object.xml. Declaring the listener for the portal.

          • 2. Re: IPC - Event not fired
            Swati Biwal Newbie

            Also posting the code for PortletA and PortletB

            PortletA.java

            package org.jboss.portal.core.samples.basic.event;
            
            import javax.portlet.ActionRequest;
            import javax.portlet.ActionResponse;
            import javax.portlet.GenericPortlet;
            import javax.portlet.PortletException;
            import javax.portlet.PortletSecurityException;
            import javax.portlet.RenderRequest;
            import javax.portlet.RenderResponse;
            import java.io.IOException;
            import java.io.PrintWriter;
            
            /**
             * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
             * @version $Revision: 5448 $
             */
            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();
             }
            }
            


            PortletB.java
            package org.jboss.portal.core.samples.basic.event;
            
            import org.jboss.portal.WindowState;
            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;
            
            import javax.portlet.ActionRequest;
            import javax.portlet.ActionResponse;
            import javax.portlet.GenericPortlet;
            import javax.portlet.PortletException;
            import javax.portlet.PortletSecurityException;
            import javax.portlet.RenderRequest;
            import javax.portlet.RenderResponse;
            import java.io.IOException;
            import java.io.PrintWriter;
            
            /**
             * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
             * @version $Revision: 8785 $
             */
            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();
             }
            
             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.setWindowState(WindowState.MAXIMIZED);
             newEvent.setParameters(wae.getParameters());
             }
             }
            
             //
             if (newEvent != null)
             {
             // If we have a new event redirect to it
             return newEvent;
             }
             else
             {
             // Otherwise bubble up
             return context.dispatch();
             }
             }
             }
            }
            


            • 3. Re: IPC - Event not fired
              kavita narang Newbie

              Hi,
              Can u pls tell the hierarchy of making this IPC portlet ?? i mean what all files are needed and also where to place the same??

              Thanks in advance.


              • 4. Re: IPC - Event not fired
                Jack Daniels Newbie

                I have the exact issue. With regards to referencing the listener in the default-object.xml, where is this file defined. I have a separate .sar directory containing my listener class as well as the jboss-service.xml file.

                Is there a different location where i need to put the reference to listener, other than the default-object.xml file in the portal-core.sar directory?

                Thanks much.