]> source.dussan.org Git - vaadin-framework.git/commitdiff
#3117 initial JSR-286 shared portlet parameter support and example
authorHenri Sara <henri.sara@itmill.com>
Wed, 2 Dec 2009 10:29:00 +0000 (10:29 +0000)
committerHenri Sara <henri.sara@itmill.com>
Wed, 2 Dec 2009 10:29:00 +0000 (10:29 +0000)
svn changeset:10126/svn branch:6.2

WebContent/WEB-INF/portlet.xml
src/com/vaadin/terminal/gwt/server/PortletApplicationContext2.java

index b4a40e77aa2e03244e613eb99d10d9e04688799b..54529685b1d96b0b9f31f65dc1cb630386ad64a6 100644 (file)
@@ -2,6 +2,7 @@
 <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>PortletDemoPortlet</portlet-name>
                <display-name>Vaadin PortletDemo</display-name>
                        <short-title>HelloWorld</short-title>
                </portlet-info>         
        </portlet>
-       
-       <!--
+
+       <!--    
        <portlet>
                <portlet-name>VaadinInterPortletEventPortlet</portlet-name>
                <display-name>Hello World Event</display-name>
                <portlet-info>
                        <title>Inter-portlet events</title>
                        <short-title>Inter-portlet events</short-title>
-               </portlet-info>         
+               </portlet-info>
                <supported-processing-event>
                <qname xmlns:vaadin="http://www.vaadin.com/hello">vaadin:Hello</qname>
                </supported-processing-event>
                <supported-publishing-event>
                <qname xmlns:vaadin="http://www.vaadin.com/hello">vaadin:FromVaadin</qname>
                </supported-publishing-event>
+               <supported-public-render-parameter>HelloState</supported-public-render-parameter>               
        </portlet>
        
        <portlet>
                <supported-publishing-event>
                <qname xmlns:vaadin="http://www.vaadin.com/hello">vaadin:ReplyToVaadin</qname>
                </supported-publishing-event>
+               <supported-public-render-parameter>HelloState</supported-public-render-parameter>               
        </portlet>
        -->
 
                </security-role-ref>
        </portlet>
        
+       <!--
+               These can be used to customize the event object types.
+               The types must be serializable and have JAXB binding.
+       -->
        <event-definition>
                <qname xmlns:vaadin="http://www.vaadin.com/hello">vaadin:Hello</qname>
                <value-type>java.lang.String</value-type>
                <value-type>java.lang.String</value-type>
        </event-definition>
 
+       <public-render-parameter>
+               <identifier>HelloState</identifier>
+               <qname xmlns:vaadin="http://www.vaadin.com/params">vaadin:HelloState</qname>
+       </public-render-parameter>
+       
        <!--
                This can be used to work around an issue in liferay 5.0-5.1.1
 
index f6217774e2e8e38ad65e249c766c0018198a138f..2471680d29caa90b74b8c3e228086c09d28ea551 100644 (file)
@@ -52,6 +52,9 @@ public class PortletApplicationContext2 extends AbstractWebApplicationContext {
     private Map<String, QName> eventActionDestinationMap = new HashMap<String, QName>();
     private Map<String, Serializable> eventActionValueMap = new HashMap<String, Serializable>();
 
+    private Map<String, String> sharedParameterActionNameMap = new HashMap<String, String>();
+    private Map<String, String> sharedParameterActionValueMap = new HashMap<String, String>();
+
     public File getBaseDirectory() {
         String resultPath = session.getPortletContext().getRealPath("/");
         if (resultPath != null) {
@@ -154,7 +157,15 @@ public class PortletApplicationContext2 extends AbstractWebApplicationContext {
             // cleanup
             eventActionDestinationMap.remove(key);
             eventActionValueMap.remove(key);
+        } else if (sharedParameterActionNameMap.containsKey(key)) {
+            // this action request is only to set shared render parameters
+            response.setRenderParameter(sharedParameterActionNameMap.get(key),
+                    sharedParameterActionValueMap.get(key));
+            // cleanup
+            sharedParameterActionNameMap.remove(key);
+            sharedParameterActionValueMap.remove(key);
         } else {
+            // normal action request, notify listeners
             Set<PortletListener> listeners = portletListeners.get(app);
             if (listeners != null) {
                 for (PortletListener l : listeners) {
@@ -250,16 +261,16 @@ public class PortletApplicationContext2 extends AbstractWebApplicationContext {
 
     /**
      * Sends a portlet event to the indicated destination.
-     * 
+     *
      * Internally, an action may be created and opened, as an event cannot be
      * sent directly from all types of requests.
-     * 
+     *
      * The event destinations and values need to be kept in the context until
      * sent. Any memory leaks if the action fails are limited to the session.
-     * 
+     *
      * Event names for events sent and received by a portlet need to be declared
      * in portlet.xml .
-     * 
+     *
      * @param window
      *            a window in which a temporary action URL can be opened if
      *            necessary
@@ -294,4 +305,50 @@ public class PortletApplicationContext2 extends AbstractWebApplicationContext {
                     "Portlet events can only be sent from a portlet request");
         }
     }
+
+    /**
+     * Sets a shared portlet parameter.
+     *
+     * Internally, an action may be created and opened, as shared parameters
+     * cannot be set directly from all types of requests.
+     *
+     * The parameters and values need to be kept in the context until sent. Any
+     * memory leaks if the action fails are limited to the session.
+     *
+     * Shared parameters set or read by a portlet need to be declared in
+     * portlet.xml .
+     *
+     * @param window
+     *            a window in which a temporary action URL can be opened if
+     *            necessary
+     * @param name
+     *            parameter identifier
+     * @param value
+     *            parameter value
+     */
+    public void setSharedRenderParameter(Window window, String name,
+            String value) throws IllegalStateException {
+        if (response instanceof MimeResponse) {
+            String actionKey = "" + System.currentTimeMillis();
+            while (sharedParameterActionNameMap.containsKey(actionKey)) {
+                actionKey = actionKey + ".";
+            }
+            PortletURL actionUrl = generateActionURL(actionKey);
+            if (actionUrl != null) {
+                sharedParameterActionNameMap.put(actionKey, name);
+                sharedParameterActionValueMap.put(actionKey, value);
+                window.open(new ExternalResource(actionUrl.toString()));
+            } else {
+                // this should never happen as we already know the response is a
+                // MimeResponse
+                throw new IllegalStateException(
+                        "Shared parameters can only be set from a portlet request");
+            }
+        } else if (response instanceof StateAwareResponse) {
+            ((StateAwareResponse) response).setRenderParameter(name, value);
+        } else {
+            throw new IllegalStateException(
+                    "Shared parameters can only be set from a portlet request");
+        }
+    }
 }