1 Reply Latest reply on Apr 29, 2010 9:39 AM by Soren Schmidt

    How to develop an IPC(inter Portlet Comunication) with PRP (Public Render Parameter)

    jhakeline llican Newbie

      How to develop an IPC (Inter Portlet Communication) with PRP (Public Render Parameter)

       

      1. 1.   Generate Maven Project.

      First one generate maven proyect with following archetype:

       

            mvn archetype:generate

         -DarchetypeGroupId=org.jboss.portletbridge.archetypes

         -DarchetypeArtifactId=1.2-basic

         -DarchetypeVersion=2.0.0.CR1

         -DgroupId=com.intralot.portlet

         -DartifactId=PltPruebaPRP

         -DarchetypeRepository=http://repository.jboss.org/maven2/

      1. 2.   Changes to realizing in the created template

      After creating my template I did the following thing:

       

           - In the pom.xml file

                  ...
                  <build>
                        <defaultGoal>package</defaultGoal>
                        <finalName>PltPruebaPRP</finalName>
                        <sourceDirectory>src/main/java</sourceDirectory>
                        ....
                  </build>
                  ...
                           <deployer>
                              <type>installed</type>
                              <deployables>
                                 <deployable>
                                    <location>target/PltPruebaPRP.war</location>
                                    <pingURL>http://localhost:8080/simple-portal/</pingURL>
                                 </deployable>
                              </deployables>
                           </deployer>
      

       

           - In faces-config.xml

       

      <?xml version='1.0' encoding='UTF-8'?>
      <faces-config version="1.2"
                    xmlns="http://java.sun.com/xml/ns/javaee"
                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                    xmlns:bridge="http://myfaces.apache.org/portletbridge"
                    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
      
      <application>
             <view-handler>
                   org.jboss.portletbridge.application.PortletViewHandler
             </view-handler>
             <state-manager>
                   org.jboss.portletbridge.application.PortletStateManager
             </state-manager>
      </application>
      
      <managed-bean>
             <managed-bean-name>myBean</managed-bean-name>
             <managed-bean-class>com.intralot.portlet.MyBean</managed-bean-class>
             <managed-bean-scope>session</managed-bean-scope>
      </managed-bean>
      
      <managed-bean>
             <managed-bean-name>myEventHandler</managed-bean-name>
             <managed-bean-class>
                   com.intralot.portlet.controlador.managedbean.MyEventHandler
             </managed-bean-class>
             <managed-bean-scope>session</managed-bean-scope>
      </managed-bean>
      
      <managed-bean>
             <managed-bean-name>myPRPBean</managed-bean-name>
             <managed-bean-class>
                   com.intralot.portlet.controlador.managedbean.MyPRPBean
             </managed-bean-class>
             <managed-bean-scope>session</managed-bean-scope>
      </managed-bean>
      
      <application>
             <application-extension>
                   <bridge:public-parameter-mappings>
                         <bridge:public-parameter-mapping>
                               <parameter>PltPruebaPRP1:idNot</parameter>
                               <model-el>#{myPRPBean.id}</model-el>
                         </bridge:public-parameter-mapping>
                   </bridge:public-parameter-mappings>
             </application-extension>
      </application>
      
      <navigation-rule>
             <navigation-case>
                   <from-outcome>actualizar</from-outcome>
                   <to-view-id>/home.xhtml</to-view-id>
             </navigation-case>
      </navigation-rule>
      
      </faces-config>
      

       

           - In portlet.xml

       

      <portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
                   version="2.0"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd">
      
            <portlet>
                  <portlet-name>PltPruebaPRP1</portlet-name>
                  <portlet-class> javax.portlet.faces.GenericFacesPortlet </portlet-class>
                  <init-param>
                        <name>javax.portlet.faces.defaultViewId.view</name>
                        <value>/portlet1/home.xhtml</value>
                  </init-param>
                  ...        
                  <supported-public-render-parameter>idNot
                  </supported-public-render-parameter>
                  <supported-publishing-event>
                        <qname xmlns:jbp="urn:jboss:portal:samples:event">jbp:MyEvent</qname>
                  </supported-publishing-event>
            </portlet>
      
            <portlet>
                  <portlet-name>PltPruebaPRP2</portlet-name>
                  <portlet-class> javax.portlet.faces.GenericFacesPortlet </portlet-class>
                  <init-param>
                        <name>javax.portlet.faces.defaultViewId.view</name>
                        <value>/portlet2/home.xhtml</value>
                  </init-param>
                  ...
                  <init-param>
                        <name>javax.portlet.faces.preserveActionParams</name>
                        <value>true</value>
                  </init-param>
                  <init-param>
                        <name>javax.portlet.faces.bridgeEventHandler</name>
                        <value>com.intralot.portlet.controlador.managedbean.MyEventHandler </value>
                  </init-param>
                  <init-param>
                        <name>javax.portlet.faces.bridgePublicRenderParameterHandler</name>
                        <value>com.intralot.portlet.controlador.managedbean.MyPRPHandler</value>
                  </init-param>
                  <supported-public-render-parameter>idNot
                  </supported-public-render-parameter>
                  <supported-publishing-event>
                        <qname xmlns:jbp="urn:jboss:portal:samples:event">jbp:MyEvent</qname>
                  </supported-publishing-event>
      
            </portlet>
      
      
      
            <event-definition>
                  <qname xmlns:jbp="urn:jboss:portal:samples:event">jbp:MyEvent</qname>
                  <value-type>com.intralot.portlet.controlador.managedbean.MyEvent </value-type>
            </event-definition>
      
            <public-render-parameter>
                  <identifier>idNot</identifier>
                  <qname xmlns:j="http://jboss.org/params">j:idNot</qname>
            </public-render-parameter>
      
      </portlet-app>
      

       

       

       

       

      1. 3.        Project’s Structure

       

      -        File MyPRPBean.java

       

      public class MyPRPBean {
        int id;      
        //getters y setters
      }
      

       

      Dibujo.bmp

       

       

       

       

      -        File MyEventHandler.java

       

            public class MyEventHandler
                  implements BridgeEventHandler {
      
                  public EventNavigationResult handleEvent(FacesContext context, Event event) {
                        System.out.println("Evento: "+event.getName());
                        return null;
                  }
            }
       
      

       

       

       

       

       

       

       

       

      -        File MyPRPHandler.java

       

      public class MyPRPHandler implements BridgePublicRenderParameterHandler{
      
            public void processUpdates(FacesContext context){
                     ELContext elContext = context.getELContext();
                     MyPRPBean bean =
                  (MyPRPBean) elContext.getELResolver().getValue(elContext, null, "myPRPBean");
                  if(null != bean){
                        System.out.println("processUpdates from PRPHandler: " + bean.getId());
                  } else {
                        System.out.println("evento nulo** ");
                  }
            }
      
      }
      
      

      -        File MyBean.java

       

      public class MyBean {
      
            private String cadena="";
      
            //getters y setters
      
            public String accion() {
                  try {
                        Object response =                                                                        FacesContext.getCurrentInstance().getExternalContext().getRequest();
                        if (response instanceof StateAwareResponse) {
                                StateAwareResponse stateResponse = (StateAwareResponse) response;
                                stateResponse.setRenderParameter("id",cadena);
                        }    
                  } catch (Exception e) {
                  }
                  return "actualizar";
            }
      
      }
      
      

       

      -        File      /portlet1/home.xhtml

       

      -        /portlet2/home.xhtml

             <h1>Hola portlet 2</h1>
             <p>Parametro ingresado: #{myPRPBean.id}</p>
      
      

       

       

      1. Generated the Project with Maven: # mvn package

       

      1. Then the deployment, portlets don’t  produce nothing, I mean that don’t produce an event in any place neither interface or  console

      Dibujo.bmp

       

      Dibujo.bmp

       

      1. My question is: ¿What part of code is wrong? ¿Is posible have both portlets in  .war file for separate?