aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/main/java/com
diff options
context:
space:
mode:
authorDenis Anisimov <denis@vaadin.com>2016-09-19 16:26:32 +0300
committerHenri Sara <hesara@vaadin.com>2016-11-25 08:36:02 +0200
commit24b43d902c71ea469e2105f3a1c8be2f84610f04 (patch)
tree89ec5aa0c72433443b7ac5664d2ba293ba41e431 /server/src/main/java/com
parent4e8eb29c548128a50a000699f60259243e4695ed (diff)
downloadvaadin-framework-24b43d902c71ea469e2105f3a1c8be2f84610f04.tar.gz
vaadin-framework-24b43d902c71ea469e2105f3a1c8be2f84610f04.zip
Data should be updated when it's set for disabled components.
Fixes vaadin/framework8-issues#286 Change-Id: I0d6cf49addfd558d43671ad2953dee54529392cd
Diffstat (limited to 'server/src/main/java/com')
-rw-r--r--server/src/main/java/com/vaadin/server/communication/ServerRpcHandler.java14
-rw-r--r--server/src/main/java/com/vaadin/server/data/DataCommunicator.java53
2 files changed, 64 insertions, 3 deletions
diff --git a/server/src/main/java/com/vaadin/server/communication/ServerRpcHandler.java b/server/src/main/java/com/vaadin/server/communication/ServerRpcHandler.java
index 5e5fd8a81e..134fd569ff 100644
--- a/server/src/main/java/com/vaadin/server/communication/ServerRpcHandler.java
+++ b/server/src/main/java/com/vaadin/server/communication/ServerRpcHandler.java
@@ -46,6 +46,7 @@ import com.vaadin.shared.communication.LegacyChangeVariablesInvocation;
import com.vaadin.shared.communication.MethodInvocation;
import com.vaadin.shared.communication.ServerRpc;
import com.vaadin.shared.communication.UidlValue;
+import com.vaadin.shared.data.DataRequestRpc;
import com.vaadin.ui.Component;
import com.vaadin.ui.ConnectorTracker;
import com.vaadin.ui.UI;
@@ -354,9 +355,9 @@ public class ServerRpcHandler implements Serializable {
if (connector == null) {
getLogger().log(Level.WARNING,
"Received RPC call for unknown connector with id {0} (tried to invoke {1}.{2})",
- new Object[]{invocation.getConnectorId(),
+ new Object[] { invocation.getConnectorId(),
invocation.getInterfaceName(),
- invocation.getMethodName()});
+ invocation.getMethodName() });
continue;
}
@@ -377,6 +378,15 @@ public class ServerRpcHandler implements Serializable {
// Silently ignore this
continue;
}
+ } else if (invocation instanceof ServerRpcMethodInvocation) {
+ ServerRpcMethodInvocation rpc = (ServerRpcMethodInvocation) invocation;
+ // special case for data communicator requesting more
+ // data
+ if (DataRequestRpc.class.getName()
+ .equals(rpc.getInterfaceClass().getName())) {
+ handleInvocation(ui, connector, rpc);
+ }
+ continue;
}
// Connector is disabled, log a warning and move to the next
diff --git a/server/src/main/java/com/vaadin/server/data/DataCommunicator.java b/server/src/main/java/com/vaadin/server/data/DataCommunicator.java
index 4709230d82..fbafff6845 100644
--- a/server/src/main/java/com/vaadin/server/data/DataCommunicator.java
+++ b/server/src/main/java/com/vaadin/server/data/DataCommunicator.java
@@ -184,7 +184,8 @@ public class DataCommunicator<T> extends AbstractExtension {
private boolean reset = false;
private final Set<T> updatedData = new HashSet<>();
- private Range pushRows = Range.withLength(0, 40);
+ private int minPushSize = 40;
+ private Range pushRows = Range.withLength(0, minPushSize);
private Comparator<T> inMemorySorting;
private SerializablePredicate<T> inMemoryFilter;
@@ -473,12 +474,62 @@ public class DataCommunicator<T> extends AbstractExtension {
Objects.requireNonNull(dataProvider, "data provider cannot be null");
this.dataProvider = dataProvider;
detachDataProviderListener();
+ /*
+ * This introduces behavior which influence on the client-server
+ * communication: now the very first response to the client will always
+ * contain some data. If data provider has been set already then {@code
+ * pushRows} is empty at this point. So without the next line the very
+ * first response will be without data. And the client will request more
+ * data in the next request after the response. The next line allows to
+ * send some data (in the {@code pushRows} range) to the client even in
+ * the very first response. This is necessary for disabled component
+ * (and theoretically allows to the client doesn't request more data in
+ * a happy path).
+ */
+ pushRows = Range.between(0, getMinPushSize());
if (isAttached()) {
attachDataProviderListener();
}
reset();
}
+ /**
+ * Set minimum size of data which will be sent to the client when data
+ * source is set.
+ * <p>
+ * Server doesn't send all data from data source to the client. It sends
+ * some initial chunk of data (whose size is determined as minimum between
+ * {@code size} parameter of this method and data size). Client decides
+ * whether it is able to show more data and request server to send more data
+ * (next chunk).
+ * <p>
+ * When component is disabled then client cannot communicate to the server
+ * side (by design, because of security reasons). It means that client will
+ * get <b>only</b> initial chunk of data whose size is set here.
+ *
+ * @param size
+ * the size of initial data to send to the client
+ */
+ public void setMinPushSize(int size) {
+ if (size < 0) {
+ throw new IllegalArgumentException("Value cannot be negative");
+ }
+ minPushSize = size;
+ }
+
+ /**
+ * Get minimum size of data which will be sent to the client when data
+ * source is set.
+ *
+ * @see #setMinPushSize(int)
+ *
+ * @return current minimum push size of initial data chunk which is sent to
+ * the client when data source is set
+ */
+ public int getMinPushSize() {
+ return minPushSize;
+ }
+
private void attachDataProviderListener() {
dataProviderUpdateRegistration = getDataProvider()
.addDataProviderListener(