diff options
author | Artur Signell <artur@vaadin.com> | 2015-01-14 10:18:39 +0200 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2015-01-14 10:18:39 +0200 |
commit | 032bcef30f5ada7dc1ca6eade07ee596afa25bb3 (patch) | |
tree | a036581c2b7ae7e82fdd60ba92b2fe392b85df7a /server/src | |
parent | 8a544b5a6e78337b24a5e56bcde1a21ff6087fae (diff) | |
parent | b356e7e3bba9b08ad9d1ecdfb4d628b8179ef20a (diff) | |
download | vaadin-framework-032bcef30f5ada7dc1ca6eade07ee596afa25bb3.tar.gz vaadin-framework-032bcef30f5ada7dc1ca6eade07ee596afa25bb3.zip |
Merge remote-tracking branch 'origin/master' into grid
Conflicts:
client/src/com/vaadin/client/communication/AtmospherePushConnection.java
server/tests/src/com/vaadin/data/fieldgroup/FieldGroupTests.java
shared/src/com/vaadin/shared/util/SharedUtil.java
Change-Id: I300b5a92bde562390a56b720adf9a37b795c9513
Diffstat (limited to 'server/src')
9 files changed, 165 insertions, 18 deletions
diff --git a/server/src/com/vaadin/data/fieldgroup/FieldGroup.java b/server/src/com/vaadin/data/fieldgroup/FieldGroup.java index 1b598ef720..069cb2e153 100644 --- a/server/src/com/vaadin/data/fieldgroup/FieldGroup.java +++ b/server/src/com/vaadin/data/fieldgroup/FieldGroup.java @@ -266,6 +266,14 @@ public class FieldGroup implements Serializable { configureField(field); } + /** + * Wrap property to transactional property. + */ + protected <T> Property.Transactional<T> wrapInTransactionalProperty( + Property<T> itemProperty) { + return new TransactionalPropertyWrapper<T>(itemProperty); + } + private void throwIfFieldIsNull(Field<?> field, Object propertyId) { if (field == null) { throw new BindException( @@ -283,11 +291,6 @@ public class FieldGroup implements Serializable { } } - private <T> Property.Transactional<T> wrapInTransactionalProperty( - Property<T> itemProperty) { - return new TransactionalPropertyWrapper<T>(itemProperty); - } - /** * Gets the property with the given property id from the item. * diff --git a/server/src/com/vaadin/server/BootstrapHandler.java b/server/src/com/vaadin/server/BootstrapHandler.java index c45e2b70e0..a9343a7e03 100644 --- a/server/src/com/vaadin/server/BootstrapHandler.java +++ b/server/src/com/vaadin/server/BootstrapHandler.java @@ -37,10 +37,14 @@ import org.jsoup.nodes.Element; import org.jsoup.nodes.Node; import org.jsoup.parser.Tag; +import com.google.gwt.thirdparty.guava.common.net.UrlEscapers; +import com.vaadin.annotations.JavaScript; +import com.vaadin.annotations.StyleSheet; import com.vaadin.annotations.Viewport; import com.vaadin.annotations.ViewportGeneratorClass; import com.vaadin.server.communication.AtmospherePushConnection; import com.vaadin.shared.ApplicationConstants; +import com.vaadin.shared.VaadinUriResolver; import com.vaadin.shared.Version; import com.vaadin.shared.communication.PushMode; import com.vaadin.ui.UI; @@ -76,6 +80,8 @@ public abstract class BootstrapHandler extends SynchronizedRequestHandler { private String themeName; private String appId; private PushMode pushMode; + private JsonObject applicationParameters; + private VaadinUriResolver uriResolver; public BootstrapContext(VaadinResponse response, BootstrapFragmentResponse bootstrapResponse) { @@ -149,6 +155,71 @@ public abstract class BootstrapHandler extends SynchronizedRequestHandler { return bootstrapResponse; } + public JsonObject getApplicationParameters() { + if (applicationParameters == null) { + applicationParameters = BootstrapHandler.this + .getApplicationParameters(this); + } + + return applicationParameters; + } + + public VaadinUriResolver getUriResolver() { + if (uriResolver == null) { + uriResolver = new BootstrapUriResolver(this); + } + + return uriResolver; + } + } + + private class BootstrapUriResolver extends VaadinUriResolver { + private final BootstrapContext context; + + public BootstrapUriResolver(BootstrapContext bootstrapContext) { + context = bootstrapContext; + } + + @Override + protected String getVaadinDirUrl() { + return context.getApplicationParameters().getString( + ApplicationConstants.VAADIN_DIR_URL); + } + + @Override + protected String getThemeUri() { + return getVaadinDirUrl() + "themes/" + context.getThemeName(); + } + + @Override + protected String getServiceUrlParameterName() { + return getConfigOrNull(ApplicationConstants.SERVICE_URL_PARAMETER_NAME); + } + + @Override + protected String getServiceUrl() { + String serviceUrl = getConfigOrNull(ApplicationConstants.SERVICE_URL); + if (serviceUrl == null) { + return "./"; + } else if (!serviceUrl.endsWith("/")) { + serviceUrl += "/"; + } + return serviceUrl; + } + + private String getConfigOrNull(String name) { + JsonObject parameters = context.getApplicationParameters(); + if (parameters.hasKey(name)) { + return parameters.getString(name); + } else { + return null; + } + } + + @Override + protected String encodeQueryStringParameterValue(String queryString) { + return UrlEscapers.urlFormParameterEscaper().escape(queryString); + } } @Override @@ -345,11 +416,41 @@ public abstract class BootstrapHandler extends SynchronizedRequestHandler { .attr("href", themeUri + "/favicon.ico"); } + JavaScript javaScript = uiClass.getAnnotation(JavaScript.class); + if (javaScript != null) { + String[] resources = javaScript.value(); + for (String resource : resources) { + String url = registerDependency(context, uiClass, resource); + head.appendElement("script").attr("type", "text/javascript") + .attr("src", url); + } + } + + StyleSheet styleSheet = uiClass.getAnnotation(StyleSheet.class); + if (styleSheet != null) { + String[] resources = styleSheet.value(); + for (String resource : resources) { + String url = registerDependency(context, uiClass, resource); + head.appendElement("link").attr("rel", "stylesheet") + .attr("type", "text/css").attr("href", url); + } + } + Element body = document.body(); body.attr("scroll", "auto"); body.addClass(ApplicationConstants.GENERATED_BODY_CLASSNAME); } + private String registerDependency(BootstrapContext context, + Class<? extends UI> uiClass, String resource) { + String url = context.getSession().getCommunicationManager() + .registerDependency(resource, uiClass); + + url = context.getUriResolver().resolveVaadinUri(url); + + return url; + } + protected String getMainDivStyle(BootstrapContext context) { return null; } @@ -457,7 +558,7 @@ public abstract class BootstrapHandler extends SynchronizedRequestHandler { protected void appendMainScriptTagContents(BootstrapContext context, StringBuilder builder) throws IOException { - JsonObject appConfig = getApplicationParameters(context); + JsonObject appConfig = context.getApplicationParameters(); boolean isDebug = !context.getSession().getConfiguration() .isProductionMode(); @@ -490,8 +591,7 @@ public abstract class BootstrapHandler extends SynchronizedRequestHandler { } } - protected JsonObject getApplicationParameters(BootstrapContext context) - throws PaintException { + protected JsonObject getApplicationParameters(BootstrapContext context) { VaadinRequest request = context.getRequest(); VaadinSession session = context.getSession(); VaadinService vaadinService = request.getService(); @@ -581,6 +681,12 @@ public abstract class BootstrapHandler extends SynchronizedRequestHandler { appConfig.put(ApplicationConstants.SERVICE_URL, serviceUrl); } + boolean sendUrlsAsParameters = vaadinService + .getDeploymentConfiguration().isSendUrlsAsParameters(); + if (!sendUrlsAsParameters) { + appConfig.put("sendUrlsAsParameters", false); + } + return appConfig; } diff --git a/server/src/com/vaadin/server/Constants.java b/server/src/com/vaadin/server/Constants.java index 02a992a882..8036490333 100644 --- a/server/src/com/vaadin/server/Constants.java +++ b/server/src/com/vaadin/server/Constants.java @@ -136,6 +136,7 @@ public interface Constants { static final String SERVLET_PARAMETER_UI_PROVIDER = "UIProvider"; static final String SERVLET_PARAMETER_LEGACY_PROPERTY_TOSTRING = "legacyPropertyToString"; static final String SERVLET_PARAMETER_SYNC_ID_CHECK = "syncIdCheck"; + static final String SERVLET_PARAMETER_SENDURLSASPARAMETERS = "sendUrlsAsParameters"; // Configurable parameter names static final String PARAMETER_VAADIN_RESOURCES = "Resources"; diff --git a/server/src/com/vaadin/server/DefaultDeploymentConfiguration.java b/server/src/com/vaadin/server/DefaultDeploymentConfiguration.java index 22d5210eaa..b26e048431 100644 --- a/server/src/com/vaadin/server/DefaultDeploymentConfiguration.java +++ b/server/src/com/vaadin/server/DefaultDeploymentConfiguration.java @@ -59,6 +59,8 @@ public class DefaultDeploymentConfiguration extends */ public static final boolean DEFAULT_SYNC_ID_CHECK = true; + public static final boolean DEFAULT_SEND_URLS_AS_PARAMETERS = true; + private final Properties initParameters; private boolean productionMode; private boolean xsrfProtectionEnabled; @@ -69,6 +71,7 @@ public class DefaultDeploymentConfiguration extends private final Class<?> systemPropertyBaseClass; private LegacyProperyToStringMode legacyPropertyToStringMode; private boolean syncIdCheck; + private boolean sendUrlsAsParameters; /** * Create a new deployment configuration instance. @@ -93,6 +96,7 @@ public class DefaultDeploymentConfiguration extends checkPushMode(); checkLegacyPropertyToString(); checkSyncIdCheck(); + checkSendUrlsAsParameters(); } private void checkLegacyPropertyToString() { @@ -258,6 +262,16 @@ public class DefaultDeploymentConfiguration extends /** * {@inheritDoc} * <p> + * The default value is <code>true</code>. + */ + @Override + public boolean isSendUrlsAsParameters() { + return sendUrlsAsParameters; + } + + /** + * {@inheritDoc} + * <p> * The default mode is {@link PushMode#DISABLED}. */ @Override @@ -347,6 +361,13 @@ public class DefaultDeploymentConfiguration extends Boolean.toString(DEFAULT_SYNC_ID_CHECK)).equals("true"); } + private void checkSendUrlsAsParameters() { + sendUrlsAsParameters = getApplicationOrSystemProperty( + Constants.SERVLET_PARAMETER_SENDURLSASPARAMETERS, + Boolean.toString(DEFAULT_SEND_URLS_AS_PARAMETERS)).equals( + "true"); + } + private Logger getLogger() { return Logger.getLogger(getClass().getName()); } diff --git a/server/src/com/vaadin/server/DeploymentConfiguration.java b/server/src/com/vaadin/server/DeploymentConfiguration.java index 3c20518c39..968ec7c0c3 100644 --- a/server/src/com/vaadin/server/DeploymentConfiguration.java +++ b/server/src/com/vaadin/server/DeploymentConfiguration.java @@ -111,6 +111,15 @@ public interface DeploymentConfiguration extends Serializable { public int getHeartbeatInterval(); /** + * Returns whether the sending of URL's as GET and POST parameters in + * requests with content-type <code>application/x-www-form-urlencoded</code> + * is enabled or not. + * + * @return <code>false</code> if set to false or <code>true</code> otherwise + */ + public boolean isSendUrlsAsParameters(); + + /** * Returns whether a session should be closed when all its open UIs have * been idle for longer than its configured maximum inactivity time. * <p> diff --git a/server/src/com/vaadin/server/Page.java b/server/src/com/vaadin/server/Page.java index 3ddf4862b2..74d79ade50 100644 --- a/server/src/com/vaadin/server/Page.java +++ b/server/src/com/vaadin/server/Page.java @@ -939,6 +939,12 @@ public class Page implements Serializable { * @return The browser location URI. */ public URI getLocation() { + if (location == null + && !uI.getSession().getConfiguration().isSendUrlsAsParameters()) { + throw new IllegalStateException("Location is not available as the " + + Constants.SERVLET_PARAMETER_SENDURLSASPARAMETERS + + " parameter is configured as false"); + } return location; } diff --git a/server/src/com/vaadin/server/VaadinRequest.java b/server/src/com/vaadin/server/VaadinRequest.java index 538e0af598..5b7e16ac46 100644 --- a/server/src/com/vaadin/server/VaadinRequest.java +++ b/server/src/com/vaadin/server/VaadinRequest.java @@ -123,7 +123,7 @@ public interface VaadinRequest extends Serializable { /** * Gets the path of the requested resource relative to the application. The - * path be <code>null</code> if no path information is available. Does + * path is <code>null</code> if no path information is available. Does * always start with / if the path isn't <code>null</code>. * * @return a string with the path relative to the application. diff --git a/server/src/com/vaadin/server/communication/PortletBootstrapHandler.java b/server/src/com/vaadin/server/communication/PortletBootstrapHandler.java index 1d1a300cd1..289309b631 100644 --- a/server/src/com/vaadin/server/communication/PortletBootstrapHandler.java +++ b/server/src/com/vaadin/server/communication/PortletBootstrapHandler.java @@ -26,7 +26,6 @@ import javax.portlet.RenderResponse; import javax.portlet.ResourceURL; import com.vaadin.server.BootstrapHandler; -import com.vaadin.server.PaintException; import com.vaadin.server.VaadinPortlet; import com.vaadin.server.VaadinPortlet.VaadinLiferayRequest; import com.vaadin.server.VaadinPortletRequest; @@ -36,6 +35,7 @@ import com.vaadin.server.VaadinResponse; import com.vaadin.server.VaadinService; import com.vaadin.server.VaadinSession; import com.vaadin.shared.ApplicationConstants; + import elemental.json.JsonObject; public class PortletBootstrapHandler extends BootstrapHandler { @@ -92,8 +92,7 @@ public class PortletBootstrapHandler extends BootstrapHandler { } @Override - protected JsonObject getApplicationParameters(BootstrapContext context) - throws PaintException { + protected JsonObject getApplicationParameters(BootstrapContext context) { JsonObject parameters = super.getApplicationParameters(context); VaadinPortletResponse response = (VaadinPortletResponse) context .getResponse(); @@ -105,17 +104,16 @@ public class PortletBootstrapHandler extends BootstrapHandler { resourceURL.setResourceID("v-browserDetails"); parameters.put("browserDetailsUrl", resourceURL.toString()); - // Always send path info as a query parameter - parameters - .put(ApplicationConstants.SERVICE_URL_PATH_AS_PARAMETER, true); + String serviceUrlParameterName = ApplicationConstants.V_RESOURCE_PATH; // If we are running in Liferay then we need to prefix all parameters // with the portlet namespace if (request instanceof VaadinLiferayRequest) { - parameters.put( - ApplicationConstants.SERVICE_URL_PARAMETER_NAMESPACE, - response.getPortletResponse().getNamespace()); + serviceUrlParameterName = response.getPortletResponse() + .getNamespace() + serviceUrlParameterName; } + parameters.put(ApplicationConstants.SERVICE_URL_PARAMETER_NAME, + serviceUrlParameterName); return parameters; } diff --git a/server/src/com/vaadin/ui/NativeSelect.java b/server/src/com/vaadin/ui/NativeSelect.java index ee7bfc3e5c..137d57f677 100644 --- a/server/src/com/vaadin/ui/NativeSelect.java +++ b/server/src/com/vaadin/ui/NativeSelect.java @@ -56,14 +56,17 @@ public class NativeSelect extends AbstractSelect implements public NativeSelect(String caption, Collection<?> options) { super(caption, options); + registerRpc(focusBlurRpc); } public NativeSelect(String caption, Container dataSource) { super(caption, dataSource); + registerRpc(focusBlurRpc); } public NativeSelect(String caption) { super(caption); + registerRpc(focusBlurRpc); } /** |