-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Changes client side value binding logic so that if the user modifies the value during server round-trip, the value earlier sent to the server no longer overwrites user's changes once the round-trip finishes. Instead, user's changes are preserved. However, if the server-side value change handling logic actually changes the value and returns the new value to the client, that value will override any user input during round-trip. Fixes #20365 Co-authored-by: Teppo Kurki <[email protected]>
- Loading branch information
1 parent
b489b21
commit 98b8761
Showing
4 changed files
with
178 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
.../test-root-context/src/main/java/com/vaadin/flow/uitest/ui/ClientSideValueChangeView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright 2000-2024 Vaadin Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package com.vaadin.flow.uitest.ui; | ||
|
||
import com.vaadin.flow.component.html.Input; | ||
import com.vaadin.flow.component.html.Span; | ||
import com.vaadin.flow.router.Route; | ||
import com.vaadin.flow.uitest.servlet.ViewTestLayout; | ||
|
||
@Route(value = "com.vaadin.flow.uitest.ui.ClientSideValueChangeView", layout = ViewTestLayout.class) | ||
public class ClientSideValueChangeView extends AbstractDivView { | ||
|
||
@Override | ||
protected void onShow() { | ||
Input input = new Input(); | ||
input.setId("inputfield"); | ||
|
||
input.addValueChangeListener(e -> { | ||
try { | ||
Thread.sleep(1000); | ||
} catch (InterruptedException ex) { | ||
throw new RuntimeException(ex); | ||
} | ||
Span span = new Span("done"); | ||
span.setId("status"); | ||
add(span); | ||
}); | ||
|
||
add(input); | ||
|
||
Input input2 = new Input(); | ||
input2.setId("inputfieldserversetsvalue"); | ||
|
||
input2.addValueChangeListener(e -> { | ||
try { | ||
Thread.sleep(1000); | ||
} catch (InterruptedException ex) { | ||
throw new RuntimeException(ex); | ||
} | ||
input2.setValue("fromserver"); | ||
Span span = new Span("done"); | ||
span.setId("statusserversetsvalue"); | ||
add(span); | ||
}); | ||
|
||
add(input2); | ||
} | ||
|
||
} |
65 changes: 65 additions & 0 deletions
65
...ts/test-root-context/src/test/java/com/vaadin/flow/uitest/ui/ClientSideValueChangeIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright 2000-2024 Vaadin Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package com.vaadin.flow.uitest.ui; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.openqa.selenium.By; | ||
import org.openqa.selenium.support.ui.ExpectedConditions; | ||
|
||
import com.vaadin.flow.component.html.testbench.InputTextElement; | ||
import com.vaadin.flow.testutil.ChromeBrowserTest; | ||
|
||
public class ClientSideValueChangeIT extends ChromeBrowserTest { | ||
|
||
@Test | ||
public void clientSideValueEntryDuringRoundTrip_enteredValueShouldNotBeOverridden() { | ||
open(); | ||
|
||
getCommandExecutor().disableWaitForVaadin(); | ||
|
||
InputTextElement input = $(InputTextElement.class).id("inputfield"); | ||
input.setValue("abc"); | ||
input.sendKeys("123"); | ||
|
||
waitUntil(ExpectedConditions.presenceOfElementLocated(By.id("status"))); | ||
|
||
Assert.assertEquals( | ||
"User input during round-trip was unexpectedly overridden", | ||
"abc123", | ||
$(InputTextElement.class).id("inputfield").getValue()); | ||
} | ||
|
||
@Test | ||
public void clientSideValueEntryDuringRoundTrip_serverChangesValue_serverValueShouldBeUsed() { | ||
open(); | ||
|
||
getCommandExecutor().disableWaitForVaadin(); | ||
|
||
InputTextElement input = $(InputTextElement.class) | ||
.id("inputfieldserversetsvalue"); | ||
input.setValue("abc"); | ||
input.sendKeys("123"); | ||
|
||
waitUntil(ExpectedConditions | ||
.presenceOfElementLocated(By.id("statusserversetsvalue"))); | ||
|
||
Assert.assertEquals( | ||
"Value set by server during round-trip was unexpectedly overridden", | ||
"fromserver", $(InputTextElement.class) | ||
.id("inputfieldserversetsvalue").getValue()); | ||
} | ||
} |