From: Marc Englund Date: Thu, 24 Apr 2008 14:30:16 +0000 (+0000) Subject: It is now possible to specify widgetset and style as request attributes; portlet... X-Git-Tag: 6.7.0.beta1~4869 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3906892b7b64558ea054dccbf091b0e8c048fa44;p=vaadin-framework.git It is now possible to specify widgetset and style as request attributes; portlet tools uses this. 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 --- diff --git a/portlet-src/com/itmill/toolkit/terminal/gwt/server/ApplicationPortlet.java b/portlet-src/com/itmill/toolkit/terminal/gwt/server/ApplicationPortlet.java index eebc38330b..77cca2ac1b 100644 --- a/portlet-src/com/itmill/toolkit/terminal/gwt/server/ApplicationPortlet.java +++ b/portlet-src/com/itmill/toolkit/terminal/gwt/server/ApplicationPortlet.java @@ -18,22 +18,21 @@ import com.itmill.toolkit.Application; public class ApplicationPortlet implements Portlet { // The application to show protected String app = null; - // some applications might require that the height is specified - protected String height = null; // e.g "200px" - - private PortletConfig config; + // some applications might require forced height (and, more seldom, width) + protected String style = null; // e.g "height:500px;" + protected String widgetset = null; public void destroy() { - config = null; + } public void init(PortletConfig config) throws PortletException { - this.config = config; app = config.getInitParameter("application"); if (app == null) { app = "PortletDemo"; } - height = config.getInitParameter("height"); + style = config.getInitParameter("style"); + widgetset = config.getInitParameter("widgetset"); } public void processAction(ActionRequest request, ActionResponse response) @@ -51,30 +50,30 @@ public class ApplicationPortlet implements Portlet { protected void writeAjaxWindow(RenderRequest request, RenderResponse response) throws IOException { - response.setContentType("text/html"); - PrintWriter out = response.getWriter(); - if (app != null) { PortletSession sess = request.getPortletSession(); PortletApplicationContext ctx = PortletApplicationContext .getApplicationContext(sess); - /*- TODO store som info somewhere? - PortletInfo pi = ctx.setPortletInfo(request.getContextPath() + "/" - + app + (app.endsWith("/") ? "" : "/"), request - .getPortletMode(), request.getWindowState(), request - .getUserPrincipal(), (Map) request - .getAttribute(PortletRequest.USER_INFO), config); - -*/ - PortletRequestDispatcher dispatcher = sess.getPortletContext() .getRequestDispatcher("/" + app); try { - // TODO height + request.setAttribute(ApplicationServlet.REQUEST_FRAGMENT, + "true"); + if (widgetset != null) { + request.setAttribute(ApplicationServlet.REQUEST_WIDGETSET, + widgetset); + } + if (style != null) { + request.setAttribute(ApplicationServlet.REQUEST_APPSTYLE, + style); + } dispatcher.include(request, response); } catch (PortletException e) { + response.setContentType("text/html"); + PrintWriter out = response.getWriter(); out.print("

Servlet include failed!

"); out.print("
" + e + "
"); ctx.setPortletApplication(this, null); diff --git a/src/com/itmill/toolkit/terminal/gwt/server/ApplicationServlet.java b/src/com/itmill/toolkit/terminal/gwt/server/ApplicationServlet.java index 14d5da3ebf..d0ba830307 100644 --- a/src/com/itmill/toolkit/terminal/gwt/server/ApplicationServlet.java +++ b/src/com/itmill/toolkit/terminal/gwt/server/ApplicationServlet.java @@ -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\n"); } - page.write("
\n"); + String style = null; + reqParam = request.getAttribute(REQUEST_APPSTYLE); + if (reqParam != null) { + style = "style=\"" + reqParam + "\""; + } + page.write("
\n"); if (!fragment) { page.write("\n\n"); } - page.close(); }