Inter portlet Communication refresh View problem
pascal_dev Apr 15, 2010 4:17 AMI 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")
??