]> source.dussan.org Git - vaadin-framework.git/commitdiff
It is now possible to specify widgetset and style as request attributes; portlet...
authorMarc Englund <marc.englund@itmill.com>
Thu, 24 Apr 2008 14:30:16 +0000 (14:30 +0000)
committerMarc Englund <marc.englund@itmill.com>
Thu, 24 Apr 2008 14:30:16 +0000 (14:30 +0000)
Also, a fragment request is now done by setting a ApplicationServlet -specific parameter instead of relying on a portlet -specific one.

svn changeset:4229/svn branch:trunk

portlet-src/com/itmill/toolkit/terminal/gwt/server/ApplicationPortlet.java
src/com/itmill/toolkit/terminal/gwt/server/ApplicationServlet.java

index eebc38330b702e209f4e4e90e643a4f4c036f896..77cca2ac1b0e418a49a5357bf41280786a35edf2 100644 (file)
@@ -18,22 +18,21 @@ import com.itmill.toolkit.Application;
 public class ApplicationPortlet implements Portlet {\r
     // The application to show\r
     protected String app = null;\r
-    // some applications might require that the height is specified\r
-    protected String height = null; // e.g "200px"\r
-\r
-    private PortletConfig config;\r
+    // some applications might require forced height (and, more seldom, width)\r
+    protected String style = null; // e.g "height:500px;"\r
+    protected String widgetset = null;\r
 \r
     public void destroy() {\r
-        config = null;\r
+\r
     }\r
 \r
     public void init(PortletConfig config) throws PortletException {\r
-        this.config = config;\r
         app = config.getInitParameter("application");\r
         if (app == null) {\r
             app = "PortletDemo";\r
         }\r
-        height = config.getInitParameter("height");\r
+        style = config.getInitParameter("style");\r
+        widgetset = config.getInitParameter("widgetset");\r
     }\r
 \r
     public void processAction(ActionRequest request, ActionResponse response)\r
@@ -51,30 +50,30 @@ public class ApplicationPortlet implements Portlet {
     protected void writeAjaxWindow(RenderRequest request,\r
             RenderResponse response) throws IOException {\r
 \r
-        response.setContentType("text/html");\r
-        PrintWriter out = response.getWriter();\r
-\r
         if (app != null) {\r
             PortletSession sess = request.getPortletSession();\r
             PortletApplicationContext ctx = PortletApplicationContext\r
                     .getApplicationContext(sess);\r
 \r
-            /*- TODO store som info somewhere?\r
-            PortletInfo pi = ctx.setPortletInfo(request.getContextPath() + "/"\r
-                    + app + (app.endsWith("/") ? "" : "/"), request\r
-                    .getPortletMode(), request.getWindowState(), request\r
-                    .getUserPrincipal(), (Map) request\r
-                    .getAttribute(PortletRequest.USER_INFO), config);\r
-            -*/\r
-\r
             PortletRequestDispatcher dispatcher = sess.getPortletContext()\r
                     .getRequestDispatcher("/" + app);\r
 \r
             try {\r
-                // TODO height\r
+                request.setAttribute(ApplicationServlet.REQUEST_FRAGMENT,\r
+                        "true");\r
+                if (widgetset != null) {\r
+                    request.setAttribute(ApplicationServlet.REQUEST_WIDGETSET,\r
+                            widgetset);\r
+                }\r
+                if (style != null) {\r
+                    request.setAttribute(ApplicationServlet.REQUEST_APPSTYLE,\r
+                            style);\r
+                }\r
                 dispatcher.include(request, response);\r
 \r
             } catch (PortletException e) {\r
+                response.setContentType("text/html");\r
+                PrintWriter out = response.getWriter();\r
                 out.print("<h1>Servlet include failed!</h1>");\r
                 out.print("<div>" + e + "</div>");\r
                 ctx.setPortletApplication(this, null);\r
index 14d5da3ebf544379311123e7289bb4ed5cbeca09..d0ba830307eaf3e27e0e3bd1c512381a351afcfa 100644 (file)
@@ -86,6 +86,29 @@ public class ApplicationServlet extends HttpServlet {
         VERSION_BUILD = digits[2];
     }
 
+    /**
+     * If the attribute is present in the request, a html fragment will be
+     * written instead of a whole page.
+     */
+    public static final String REQUEST_FRAGMENT = ApplicationServlet.class
+            .getName()
+            + ".fragment";
+    /**
+     * This request attribute forces widgetset used; e.g for portlets that can
+     * not have different widgetsets.
+     */
+    public static final String REQUEST_WIDGETSET = ApplicationServlet.class
+            .getName()
+            + ".widgetset";
+    /**
+     * This request attribute is used to add styles to the main element. E.g
+     * "height:500px" generates a style="height:500px" to the main element,
+     * useful from some embedding situations (e.g portlet include.)
+     */
+    public static final String REQUEST_APPSTYLE = ApplicationServlet.class
+            .getName()
+            + ".style";
+
     // Configurable parameter names
     private static final String PARAMETER_DEBUG = "Debug";
 
@@ -706,10 +729,8 @@ public class ApplicationServlet extends HttpServlet {
             HttpServletResponse response, Window window, String themeName,
             Application application) throws IOException, MalformedURLException {
 
-        // Portlets only want a html fragment
-        // TODO own (itmill) attribute for this e.g
-        // ApplicationServlet.class.getName()+".writeFragment"
-        boolean fragment = (request.getAttribute("javax.portlet.request") != null);
+        // e.g portlets only want a html fragment
+        boolean fragment = (request.getAttribute(REQUEST_FRAGMENT) != null);
         if (fragment) {
             request.setAttribute(Application.class.getName(), application);
         }
@@ -721,8 +742,18 @@ public class ApplicationServlet extends HttpServlet {
         String title = ((window == null || window.getCaption() == null) ? "IT Mill Toolkit 5"
                 : window.getCaption());
 
-        String widgetset = applicationProperties
-                .getProperty(PARAMETER_WIDGETSET);
+        String widgetset = null;
+        // request widgetset takes precedence (e.g portlet include)
+        Object reqParam = request.getAttribute(REQUEST_WIDGETSET);
+        try {
+            widgetset = (String) reqParam;
+        } catch (Exception e) {
+            System.err.println("Warning: request param " + REQUEST_WIDGETSET
+                    + " could not be used (not a String?)" + e);
+        }
+        if (widgetset == null) {
+            widgetset = applicationProperties.getProperty(PARAMETER_WIDGETSET);
+        }
         if (widgetset == null) {
             widgetset = DEFAULT_WIDGETSET;
         }
@@ -820,12 +851,17 @@ public class ApplicationServlet extends HttpServlet {
             page.write("//]]>\n</script>\n");
         }
 
-        page.write("<div id=\"" + appId + "\" class=\"i-app\"></div>\n");
+        String style = null;
+        reqParam = request.getAttribute(REQUEST_APPSTYLE);
+        if (reqParam != null) {
+            style = "style=\"" + reqParam + "\"";
+        }
+        page.write("<div id=\"" + appId + "\" class=\"i-app\" "
+                + (style != null ? style : "") + "></div>\n");
 
         if (!fragment) {
             page.write("</body>\n</html>\n");
         }
-
         page.close();
 
     }