From: Artur Signell Date: Thu, 22 May 2014 13:05:47 +0000 (+0300) Subject: Helpers for retrieving the current PortletRequest (#13806) X-Git-Tag: 7.4.0.alpha2~10^2~2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=660d17bff945a7b9b65735b23b4057769d07388b;p=vaadin-framework.git Helpers for retrieving the current PortletRequest (#13806) Change-Id: I5d400a05071844729d68abb1ba0c31c33e32e9c7 --- diff --git a/server/src/com/vaadin/server/VaadinPortletRequest.java b/server/src/com/vaadin/server/VaadinPortletRequest.java index 47cbebffe4..e1b521d57f 100644 --- a/server/src/com/vaadin/server/VaadinPortletRequest.java +++ b/server/src/com/vaadin/server/VaadinPortletRequest.java @@ -239,4 +239,32 @@ public class VaadinPortletRequest extends PortletRequestWrapper implements return null; } + /** + * Gets the currently processed portlet request. The current portlet request + * is automatically defined when the request is started. The current portlet + * request can not be used in e.g. background threads because of the way + * server implementations reuse request instances. + * + * @return the current portlet request instance if available, otherwise + * null + * + */ + public static PortletRequest getCurrentPortletRequest() { + return VaadinPortletService.getCurrentPortletRequest(); + + } + + /** + * Gets the currently processed Vaadin portlet request. The current request + * is automatically defined when the request is started. The current request + * can not be used in e.g. background threads because of the way server + * implementations reuse request instances. + * + * @return the current Vaadin portlet request instance if available, + * otherwise null + * + */ + public static VaadinPortletRequest getCurrent() { + return VaadinPortletService.getCurrentRequest(); + } } diff --git a/server/src/com/vaadin/server/VaadinPortletService.java b/server/src/com/vaadin/server/VaadinPortletService.java index 3666853253..2b290b4cc4 100644 --- a/server/src/com/vaadin/server/VaadinPortletService.java +++ b/server/src/com/vaadin/server/VaadinPortletService.java @@ -248,15 +248,49 @@ public class VaadinPortletService extends VaadinService { return type; } + /** + * Gets the currently processed portlet request. The current portlet request + * is automatically defined when the request is started. The current portlet + * request can not be used in e.g. background threads because of the way + * server implementations reuse request instances. + * + * @return the current portlet request instance if available, otherwise + * null + * + */ public static PortletRequest getCurrentPortletRequest() { - VaadinRequest currentRequest = VaadinService.getCurrentRequest(); - if (currentRequest instanceof VaadinPortletRequest) { - return ((VaadinPortletRequest) currentRequest).getPortletRequest(); + VaadinPortletRequest currentRequest = getCurrentRequest(); + if (currentRequest != null) { + return currentRequest.getPortletRequest(); } else { return null; } } + /** + * Gets the currently processed Vaadin portlet request. The current request + * is automatically defined when the request is started. The current request + * can not be used in e.g. background threads because of the way server + * implementations reuse request instances. + * + * @return the current Vaadin portlet request instance if available, + * otherwise null + * + */ + public static VaadinPortletRequest getCurrentRequest() { + return (VaadinPortletRequest) VaadinService.getCurrentRequest(); + } + + /** + * Gets the currently processed Vaadin portlet response. The current + * response is automatically defined when the request is started. The + * current response can not be used in e.g. background threads because of + * the way server implementations reuse response instances. + * + * @return the current Vaadin portlet response instance if available, + * otherwise null + * + */ public static VaadinPortletResponse getCurrentResponse() { return (VaadinPortletResponse) VaadinService.getCurrentResponse(); }