3 Replies Latest reply on Dec 5, 2011 7:04 AM by sseidel

    Inter portlet Communication refresh View problem

    pascal dev Newbie

      I try to make a sample sample of IPC on the GateIn portal. the environment is :

      JSF 1.2

      PortletBridge 2.0.0.CR1

      Richfaces 3.3.2.SR1

      GateIn 3.0.0 Final on JBOSS 5.1.0 jdk 6

       

      There is a sourveEventPortlet. it launch an event with an user action on a <h:commandButton>. A listenerEventPortlet receive this event But i do not succeed to refresh the portlet window. I saw the same problem on another topic, but I don't understand why it isn't working.

       

      pom.xml dependencies :


      <dependencies>
          <dependency>
            <groupId>javax.portlet</groupId>
            <artifactId>portlet-api</artifactId>
            <version>2.0</version>
            <scope>provided</scope>
          </dependency>
         
           <!-- Portlet bridge -->
            <dependency>
               <groupId>org.jboss.portletbridge</groupId>
               <artifactId>portletbridge-api</artifactId>
               <version>2.0.0.CR1</version>
            </dependency>

       

            <dependency>
               <groupId>org.jboss.portletbridge</groupId>
               <artifactId>portletbridge-impl</artifactId>
               <version>2.0.0.CR1</version>
            </dependency>
           
            <dependency>
                <groupId>javax.el</groupId>
                <artifactId>el-api</artifactId>
                <version>1.0</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>jstl</artifactId>
                <version>1.1.2</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>javax.faces</groupId>
                <artifactId>jsf-api</artifactId>
                <version>1.2</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>javax.faces</groupId>
                <artifactId>jsf-impl</artifactId>
                <version>1.2-b19</version>
                <scope>provided</scope>
            </dependency>
           
            <dependency>
                <groupId>org.richfaces.framework</groupId>
                <artifactId>richfaces-api</artifactId>
                <version>3.3.2.SR1</version>
            </dependency>
            <dependency>
                <groupId>org.richfaces.framework</groupId>
                <artifactId>richfaces-impl</artifactId>
                <version>3.3.2.SR1</version>
            </dependency>
            <dependency>
                <groupId>org.richfaces.ui</groupId>
                <artifactId>richfaces-ui</artifactId>
                <version>3.3.2.SR1</version>
            </dependency>
           
            <dependency>
              <groupId>com.sun.facelets</groupId>
              <artifactId>jsf-facelets</artifactId>
              <version>1.1.15.B1</version>
            </dependency>
           
             <dependency>
               <groupId>javax.xml.bind</groupId>
              <artifactId>jaxb-api</artifactId>
              <version>2.0</version>
              <scope>provided</scope>
            </dependency>  
             
        </dependencies>

       

      web.xml :

       

      <?xml version="1.0"?>
      <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
              version="2.4">

       


         <context-param>
            <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
            <param-value>.xhtml</param-value>
         </context-param>

       

         <context-param>
            <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
            <param-value>server</param-value>
         </context-param>

       

         <context-param>
            <param-name>javax.portlet.faces.RENDER_POLICY</param-name>
            <param-value>NEVER_DELEGATE</param-value>
         </context-param>

       

         <servlet>
            <servlet-name>Faces Servlet</servlet-name>
            <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
         </servlet>

       

         <servlet-mapping>
            <servlet-name>Faces Servlet</servlet-name>
            <url-pattern>/faces/*</url-pattern>
         </servlet-mapping>

       

         <servlet-mapping>
            <servlet-name>Faces Servlet</servlet-name>
            <url-pattern>*.resource</url-pattern>
         </servlet-mapping>

         <filter>
          <display-name>RichFaces Filter</display-name>
          <filter-name>richfaces</filter-name>
          <filter-class>org.ajax4jsf.Filter</filter-class>
        </filter>
       
        <filter-mapping>
          <filter-name>richfaces</filter-name>
          <servlet-name>Faces Servlet</servlet-name>
          <dispatcher>REQUEST</dispatcher>
          <dispatcher>FORWARD</dispatcher>
          <dispatcher>INCLUDE</dispatcher>
        </filter-mapping>
       
        <context-param>
          <param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
          <param-value>org.jboss.portletbridge.application.FaceletPortletViewHandler</param-value>
        </context-param>

       

        <context-param>
          <param-name>javax.portlet.faces.renderPolicy</param-name>
          <param-value>ALWAYS_DELEGATE</param-value>
        </context-param>
      </web-app>

       

      faces-config;xml :

       

      <faces-config xmlns="http://java.sun.com/xml/ns/javaee"
                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
                    version="1.2">

       

          <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>source</managed-bean-name>
            <managed-bean-class>       

                mypackage.SourceEventPortlet
            </managed-bean-class>
            <managed-bean-scope>session</managed-bean-scope>
            <managed-property>
              <property-name>name</property-name>
              <property-class>java.lang.String</property-class>
              <value/>
            </managed-property>
         </managed-bean>
         <managed-bean>
            <managed-bean-name>listener</managed-bean-name>
            <managed-bean-class>
               mypackage.ListenerEventPortlet
            </managed-bean-class>
            <managed-bean-scope>session</managed-bean-scope>
         </managed-bean>
        
         <navigation-rule>
          <from-view-id>/xhtml/source.xhtml</from-view-id>
            <navigation-case>
               <from-outcome>none</from-outcome>
               <to-view-id>/xhtml/source.xhtml</to-view-id>
            </navigation-case>
         </navigation-rule>
         <navigation-rule>
          <from-view-id>/xhtml/listener.xhtml</from-view-id>
            <navigation-case>
               <from-outcome>test</from-outcome>
               <to-view-id>/xhtml/listener.xhtml</to-view-id>
            </navigation-case>
         </navigation-rule>
        
      </faces-config>

       

      portlet.xml :

       

      <?xml version="1.0" encoding="UTF-8"?>
      <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
         http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd">
         <portlet>
            <portlet-name>ipc_jsf_source_portlet</portlet-name>
            <portlet-class>javax.portlet.faces.GenericFacesPortlet</portlet-class>
            <supports>
               <mime-type>text/html</mime-type>
               <portlet-mode>view</portlet-mode>
            </supports>
            <portlet-info>
               <title>Source event portlet</title>
            </portlet-info>
            <init-param>
               <name>javax.portlet.faces.defaultViewId.view</name>
               <value>/xhtml/source.xhtml</value>
            </init-param>
            <init-param>
            <name>javax.portlet.faces.preserveActionParams</name>
            <value>true</value>
          </init-param>
            <init-param>
            <name>javax.portlet.faces.autoDispatchEvents</name>
            <value>true</value>
          </init-param>
          <expiration-cache>-0</expiration-cache>
          <supported-publishing-event>
              <qname xmlns:gtn="urn:jboss:portal:samples:event">gtn:PersonEvent</qname>
          </supported-publishing-event>
         </portlet>
         <portlet>
            <portlet-name>ipc_jsf_listener_portlet</portlet-name>
            <portlet-class>javax.portlet.faces.GenericFacesPortlet</portlet-class>
            <supports>
               <mime-type>text/html</mime-type>
               <portlet-mode>view</portlet-mode>
            </supports>
            <portlet-info>
               <title>Source event portlet</title>
            </portlet-info>
            <init-param>
               <name>javax.portlet.faces.defaultViewId.view</name>
               <value>/xhtml/listener.xhtml</value>
            </init-param>
            <init-param>
              <name>javax.portlet.faces.preserveActionParams</name>
              <value>true</value>
            </init-param>
            <init-param> 
              <name>javax.portlet.faces.autoDispatchEvents</name>
              <value>true</value>
            </init-param>
            <init-param>
              <name>javax.portlet.faces.bridgeEventHandler</name>
              <value>mypackage.ListenerEventPortlet</value>
            </init-param>
            <expiration-cache>-0</expiration-cache>
            <supported-processing-event>
                 <qname xmlns:gtn="urn:jboss:portal:samples:event">gtn:PersonEvent</qname>
            </supported-processing-event>
         </portlet>
        
         <event-definition>
          <qname xmlns:gtn="urn:jboss:portal:samples:event">gtn:PersonEvent</qname>
          <value-type><?xml version="1.0" encoding="UTF-8"?>
      <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
         http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd">
         <portlet>
            <portlet-name>ipc_jsf_source_portlet</portlet-name>
            <portlet-class>javax.portlet.faces.GenericFacesPortlet</portlet-class>
            <supports>
               <mime-type>text/html</mime-type>
               <portlet-mode>view</portlet-mode>
               <!--
               <portlet-mode>edit</portlet-mode>
               <portlet-mode>help</portlet-mode>
                -->
            </supports>
            <portlet-info>
               <title>Source event portlet</title>
            </portlet-info>
            <init-param>
               <name>javax.portlet.faces.defaultViewId.view</name>
               <value>/xhtml/source.xhtml</value>
            </init-param>
            <init-param>
            <name>javax.portlet.faces.preserveActionParams</name>
            <value>true</value>
          </init-param>
            <init-param>
            <name>javax.portlet.faces.autoDispatchEvents</name>
            <value>true</value>
          </init-param>
          <expiration-cache>-0</expiration-cache>
          <supported-publishing-event>
              <qname xmlns:gtn="urn:jboss:portal:samples:event">gtn:PersonEvent</qname>
          </supported-publishing-event>
         </portlet>
         <portlet>
            <portlet-name>ipc_jsf_listener_portlet</portlet-name>
            <portlet-class>javax.portlet.faces.GenericFacesPortlet</portlet-class>
            <supports>
               <mime-type>text/html</mime-type>
               <portlet-mode>view</portlet-mode>
            </supports>
            <portlet-info>
               <title>Source event portlet</title>
            </portlet-info>
            <init-param>
               <name>javax.portlet.faces.defaultViewId.view</name>
               <value>/xhtml/listener.xhtml</value>
            </init-param>
            <init-param>
              <name>javax.portlet.faces.preserveActionParams</name>
              <value>true</value>
            </init-param>
            <init-param> 
              <name>javax.portlet.faces.autoDispatchEvents</name>
              <value>true</value>
            </init-param>
            <init-param>
              <name>javax.portlet.faces.bridgeEventHandler</name>
              <value>fr.generali.gatein.portlet.test.richfaces.ipc.ListenerEventPortlet</value>
            </init-param>
            <expiration-cache>-0</expiration-cache>
            <supported-processing-event>
                 <qname xmlns:gtn="urn:jboss:portal:samples:event">gtn:PersonEvent</qname>
            </supported-processing-event>
         </portlet>
        
         <event-definition>
          <qname xmlns:gtn="urn:jboss:portal:samples:event">gtn:PersonEvent</qname>
          <value-type>fr.generali.gatein.portlet.test.richfaces.ipc.PersonEvent</value-type>
        </event-definition>
      </portlet-app>mypackage.PersonEvent</value-type>
        </event-definition>
      </portlet-app>

       

      SourceEventPortlet :

       

      public class SourceEventPortlet {
         
          private String name = "NOM";
          private String firstName = "PRENOM";
          public String getName() {
              return name;
          }
          public void setName(String name) {
              this.name = name;
          }
          public String getFirstName() {
              return firstName;
          }
          public void setFirstName(String firstName) {
              this.firstName = firstName;
          }  
         
          public void test(ActionEvent e) {
              System.out.println("public void listen(ActionEvent e)");
              Object resp = FacesContext.getCurrentInstance().getExternalContext().getResponse();
              System.out.println("response is instance of : " + resp.getClass().getName());
              if (resp instanceof PortletResponse){
                  System.out.println("response is instance of : PortletResponse");
              }else {
                  System.out.println("response is not instance of : PortletResponse");
              }
          }
         
          public void handleSimpleAction() {
              Object response = FacesContext.getCurrentInstance().getExternalContext().getResponse();
              if (response instanceof StateAwareResponse){
                  System.out.println("response is stateAwareResponse");
                  StateAwareResponse stateResponse = (StateAwareResponse) response;
                  stateResponse.setEvent(PersonEvent.QNAME, new PersonEvent());
              }
          }

       

      PersonEvent :

       

      @XmlRootElement
      public class PersonEvent implements Serializable {
          /**
           *
           */
          private static final long serialVersionUID = -412417493053007419L;
         
          public static final QName QNAME = new QName("urn:jboss:portal:samples:event", "PersonEvent");
         
          private String personName = "BRIANN";

       

          public String getPersonName() {
              return personName;
          }

       

          public void setPersonName(String personName) {
              this.personName = personName;
          } 
      }

       

      xhtml/source.xhtml :

       

      <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:ui="http://java.sun.com/jsf/facelets"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:a4j="http://richfaces.org/a4j"
          xmlns:rich="http://richfaces.org/rich">

       

          <f:view>
              <h:form>
                  <h:outputFormat value="#{source.name}"/>
                  <br/>
                  <h:outputFormat value="#{source.firstName}"/>
                  <h:commandButton  value="action" action="#{source.handleSimpleAction}"/>
              </h:form>
          </f:view>   
      </html>

       

      ListenerEventPortlet :

       

      public class ListenerEventPortlet implements BridgeEventHandler {
         
          private String field = "HELLO";

       

          public String getField() {
              return field;
          }

       

          public void setField(String field) {
              this.field = field;
          }
         
          public EventNavigationResult handleEvent(FacesContext context, Event event) {
              System.out.println("public EventNavigationResult handleEvent(FacesContext context, Event event)");
              PersonEvent personEvent = ((PersonEvent)event.getValue());
              String name = personEvent.getPersonName();
              System.out.println("name = " + name);
              this.field = name;
              context.getExternalContext().getSessionMap().put(event.getName(), event.getValue());
              Object obj = context.getExternalContext().getSessionMap().get("eventReceiverBean");
              if (null == obj){
                  System.out.println("context.getCurrentInstance().getExternalContext().getSessionMap().get(eventReceiverBean) is NULL");
              } else {
                  System.out.println("is instance of " + obj.getClass().getName());
              }
              return new EventNavigationResult("/xhtml/listener.xhtml", "test");
          }
      }

       

      xhtml/listener.xhtml :

       

      <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:ui="http://java.sun.com/jsf/facelets"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:a4j="http://richfaces.org/a4j"
          xmlns:rich="http://richfaces.org/rich">

       

         
          <f:view>
              <h:form>
                  <h:outputFormat value="#{listener.field}"/>
              </h:form>
          </f:view>   
      </html>

       

      may be this code is wrong :

       

       

      context.getExternalContext().getSessionMap().put(event.getName(), event.getValue());

      or

      new EventNavigationResult("/xhtml/listener.xhtml", "test")

      ??

        • 1. Re: Inter portlet Communication refresh View problem
          pascal dev Newbie

          Hello,

           

          I did several tests.

           

          The portlet listener is a managedBean that implements tthe BridgeEventHandler interface to receive an event (portlet 2.0).

          I use this managed bean with a view : /xhtml/listener.xhtml

           

          <html xmlns="http://www.w3.org/1999/xhtml"
              xmlns:ui="http://java.sun.com/jsf/facelets"
              xmlns:h="http://java.sun.com/jsf/html"
              xmlns:f="http://java.sun.com/jsf/core"
              xmlns:a4j="http://richfaces.org/a4j"
              xmlns:rich="http://richfaces.org/rich">

           

             
              <f:view>
                  <h:form>
                      <h:outputFormat value="#{listener.field}"/>
                  </h:form>
              </f:view>   
          </html>

           

          For my test, i have changed the getter code of the managedBean to trace the pointer value of instance :

           

          In the faces-config.xml :

           

          <managed-bean>
                <managed-bean-name>listener</managed-bean-name>
                <managed-bean-class>
                  mypackage.ListenerEventPortlet
                </managed-bean-class>
                <managed-bean-scope>session</managed-bean-scope>
             </managed-bean>

           

          the managedbean :

           

          public class ListenerEventPortlet implements BridgeEventHandler {
             
              private String field = "HELLO";
              private String messageEvent = null;
             
             public String getField() {
                  System.out.println("String getField() ; messageEvent = " + this.messageEvent);
                  System.out.println("instance of ListenerEventPortlet ; this.hashCode() = " + this.hashCode());
                  return field;
              }

           

              public void setField(String field) {
                  System.out.println("void setField(String field) ; messageEvent = " + this.messageEvent);
                  this.field = field;
              }
             
              public EventNavigationResult handleEvent(FacesContext context, Event event) {
                  System.out.println("public EventNavigationResult handleEvent(FacesContext context, Event event)");
                  PersonEvent personEvent = ((PersonEvent)event.getValue());
                  String name = personEvent.getPersonName();
                  System.out.println("name = " + name);
                  this.messageEvent = name;
                  System.out.println("event name = " + event.getName());
                  System.out.println("instance of ListenerEventPortlet ; this.hashCode() = " + this.hashCode());
                  context.getExternalContext().getSessionMap().put(event.getName(), event.getValue());
                  Object obj = context.getExternalContext().getSessionMap().get("eventReceiverBean");
                  if (null == obj){
                      System.out.println("context.getCurrentInstance().getExternalContext().getSessionMap().get(eventReceiverBean) is NULL");
                  } else {
                      System.out.println("is instance of " + obj.getClass().getName());
                  }
                  return  new EventNavigationResult("/xhtml/listener.xhtml", "test1");
              }
          }

           

           

          server.log :

           

          10:47:22,562 INFO  [compiler] Added Library from: vfszip:/E:/working/server/GateIn-3.0.0-GA/server/default/deploy/jbossweb.sar/jsf-libs/jsf-impl.jar/META-INF/mojarra_ext.taglib.xml
          10:47:22,625 INFO  [STDOUT] String getField() ; messageEvent = null
          10:47:22,625 INFO  [STDOUT] instance of ListenerEventPortlet ; this.hashCode() = 25157521
          10:47:22,687 INFO  [bridge] Bridge Strategy was not activated due to org/jboss/seam/Seam
          10:47:24,671 INFO  [STDOUT] response is stateAwareResponse
          10:47:24,671 INFO  [portal:UIPortlet] The Portlet PortletContext[local./ipc_jsf_portlet.ipc_jsf_source_portlet] supports producing the event : {urn:jboss:portal:samples:event}PersonEvent
          10:47:24,671 INFO  [portal:UIPortlet] The portlet PortletContext[local./exoadmin.StarToolbarPortlet] doesn't support consuming the event : {urn:jboss:portal:samples:event}PersonEvent
          10:47:24,671 INFO  [portal:UIPortlet] The portlet PortletContext[local./exoadmin.UserToolbarSitePortlet] doesn't support consuming the event : {urn:jboss:portal:samples:event}PersonEvent
          10:47:24,671 INFO  [portal:UIPortlet] The portlet PortletContext[local./exoadmin.UserToolbarGroupPortlet] doesn't support consuming the event : {urn:jboss:portal:samples:event}PersonEvent
          10:47:24,671 INFO  [portal:UIPortlet] The portlet PortletContext[local./exoadmin.UserToolbarDashboardPortlet] doesn't support consuming the event : {urn:jboss:portal:samples:event}PersonEvent
          10:47:24,671 INFO  [portal:UIPortlet] The portlet PortletContext[local./exoadmin.AdminToolbarPortlet] doesn't support consuming the event : {urn:jboss:portal:samples:event}PersonEvent
          10:47:24,671 INFO  [portal:UIPortlet] The portlet PortletContext[local./exoadmin.UserInfoPortlet] doesn't support consuming the event : {urn:jboss:portal:samples:event}PersonEvent
          10:47:24,671 INFO  [portal:UIPortlet] The portlet PortletContext[local./web.LogoPortlet] doesn't support consuming the event : {urn:jboss:portal:samples:event}PersonEvent
          10:47:24,671 INFO  [portal:UIPortlet] The portlet PortletContext[local./dashboard.TabbedDashboardPortlet] doesn't support consuming the event : {urn:jboss:portal:samples:event}PersonEvent
          10:47:24,671 INFO  [portal:UIPortlet] The Portlet PortletContext[local./ipc_jsf_portlet.ipc_jsf_listener_portlet] supports comsuming the event : {urn:jboss:portal:samples:event}PersonEvent
          10:47:24,671 INFO  [STDOUT] public EventNavigationResult handleEvent(FacesContext context, Event event)
          10:47:24,671 INFO  [STDOUT] name = BRIANN
          10:47:24,671 INFO  [STDOUT] event name = PersonEvent
          10:47:24,671 INFO  [STDOUT] instance of ListenerEventPortlet ; this.hashCode() = 6552483
          10:47:24,671 INFO  [STDOUT] context.getCurrentInstance().getExternalContext().getSessionMap().get(eventReceiverBean) is NULL
          10:47:24,671 INFO  [portal:UIPortletActionListener] Events were generated outside the scope of an AJAX call, hence will make a full render of the page
          10:47:24,671 INFO  [portal:UIPortlet] The portlet PortletContext[local./ipc_jsf_portlet.ipc_jsf_source_portlet] doesn't support consuming the event : {urn:jboss:portal:samples:event}PersonEvent
          10:47:24,671 INFO  [portal:UIPortlet] The portlet PortletContext[local./web.FooterPortlet] doesn't support consuming the event : {urn:jboss:portal:samples:event}PersonEvent
          10:47:24,687 INFO  [STDOUT] String getField() ; messageEvent = null
          10:47:24,687 INFO  [STDOUT] instance of ListenerEventPortlet ; this.hashCode() = 25157521

           

           

          Indeed, there are two instances of the class ListenerEventPortlet :

            - one instance is come from the faces-config  jsf managedbean  (25157521)

            - the other is provided by the event system  (6552483)

           

          So, i can't refresh the view with the data receive from the portlet event because, it isn't the same instance of class.

           

          Do i make a mistake in my code ?

          Someone could explain me the underground system of event portlet with the portletBirdge ?

          • 2. Re: Inter portlet Communication refresh View problem
            invincible_virus Newbie

            hi

             

            This Post is a bit old. But still, I'll ask

            Did u get any solution or raised any bugs on PortletBridge?

             

            p.s. I am facing similar issue.

             

            Thanks.

            • 3. Re: Inter portlet Communication refresh View problem
              sseidel Newbie

              I think the error of the original poster was to not distinguish between the backing bean and the bridge event handler. These two are separate and must be separate. To transfer data from the BridgeEventHandler to the BackingBean, use the FacesContext and either the SessionParameters or EL expressions.

               

              stefan