Change-Id: I1bac8e8a746bcc97b3ce929e76cf3476ad793bf6tags/7.0.3
@@ -16,6 +16,8 @@ | |||
package com.vaadin.ui; | |||
import org.json.JSONException; | |||
import com.vaadin.data.Property; | |||
import com.vaadin.event.FieldEvents.BlurEvent; | |||
import com.vaadin.event.FieldEvents.BlurListener; | |||
@@ -37,6 +39,21 @@ public class CheckBox extends AbstractField<Boolean> { | |||
return; | |||
} | |||
/* | |||
* Client side updates the state before sending the event so we need | |||
* to make sure the cached state is updated to match the client. If | |||
* we do not do this, a reverting setValue() call in a listener will | |||
* not cause the new state to be sent to the client. | |||
* | |||
* See #11028, #10030. | |||
*/ | |||
try { | |||
getUI().getConnectorTracker().getDiffState(CheckBox.this) | |||
.put("checked", checked); | |||
} catch (JSONException e) { | |||
throw new RuntimeException(e); | |||
} | |||
final Boolean oldValue = getValue(); | |||
final Boolean newValue = checked; | |||
@@ -0,0 +1,36 @@ | |||
/* | |||
* Copyright 2000-2013 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.tests.components; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.tests.util.Log; | |||
import com.vaadin.ui.VerticalLayout; | |||
public abstract class AbstractTestUIWithLog extends AbstractTestUI { | |||
protected Log log = new Log(5); | |||
@Override | |||
public void init(VaadinRequest request) { | |||
super.init(request); | |||
((VerticalLayout) getContent()).addComponent(log, 0); | |||
} | |||
protected void log(String message) { | |||
log.log(message); | |||
} | |||
} |
@@ -0,0 +1,82 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | |||
<head profile="http://selenium-ide.openqa.org/profiles/test-case"> | |||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | |||
<link rel="selenium.base" href="http://localhost:8888/" /> | |||
<title>New Test</title> | |||
</head> | |||
<body> | |||
<table cellpadding="1" cellspacing="1" border="1"> | |||
<thead> | |||
<tr><td rowspan="1" colspan="3">New Test</td></tr> | |||
</thead><tbody> | |||
<tr> | |||
<td>open</td> | |||
<td>/run/com.vaadin.tests.components.checkbox.CheckBoxRevertValueChange?restartApplication</td> | |||
<td></td> | |||
</tr> | |||
<tr> | |||
<td>mouseClick</td> | |||
<td>vaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[0]/VCheckBox[0]/domChild[0]</td> | |||
<td>10,5</td> | |||
</tr> | |||
<tr> | |||
<td>assertText</td> | |||
<td>vaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::PID_SLog_row_0</td> | |||
<td>1. I said no checking!</td> | |||
</tr> | |||
<tr> | |||
<td>assertValue</td> | |||
<td>vaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[0]/VCheckBox[0]/domChild[0]</td> | |||
<td>off</td> | |||
</tr> | |||
<tr> | |||
<td>mouseClick</td> | |||
<td>vaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[0]/VCheckBox[0]/domChild[1]</td> | |||
<td>93,10</td> | |||
</tr> | |||
<tr> | |||
<td>assertText</td> | |||
<td>vaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::PID_SLog_row_0</td> | |||
<td>2. I said no checking!</td> | |||
</tr> | |||
<tr> | |||
<td>assertValue</td> | |||
<td>vaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[0]/VCheckBox[0]/domChild[0]</td> | |||
<td>off</td> | |||
</tr> | |||
<tr> | |||
<td>mouseClick</td> | |||
<td>vaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[1]/VCheckBox[0]/domChild[0]</td> | |||
<td>5,8</td> | |||
</tr> | |||
<tr> | |||
<td>assertText</td> | |||
<td>vaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::PID_SLog_row_0</td> | |||
<td>3. I said no unchecking!</td> | |||
</tr> | |||
<tr> | |||
<td>assertValue</td> | |||
<td>vaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[1]/VCheckBox[0]/domChild[0]</td> | |||
<td>on</td> | |||
</tr> | |||
<tr> | |||
<td>mouseClick</td> | |||
<td>vaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[1]/VCheckBox[0]/domChild[1]</td> | |||
<td>78,12</td> | |||
</tr> | |||
<tr> | |||
<td>assertText</td> | |||
<td>vaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::PID_SLog_row_0</td> | |||
<td>4. I said no unchecking!</td> | |||
</tr> | |||
<tr> | |||
<td>assertValue</td> | |||
<td>vaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[1]/VCheckBox[0]/domChild[0]</td> | |||
<td>on</td> | |||
</tr> | |||
</tbody></table> | |||
</body> | |||
</html> |
@@ -0,0 +1,65 @@ | |||
/* | |||
* Copyright 2000-2013 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.tests.components.checkbox; | |||
import com.vaadin.annotations.PreserveOnRefresh; | |||
import com.vaadin.data.Property; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.tests.components.AbstractTestUIWithLog; | |||
import com.vaadin.ui.CheckBox; | |||
@PreserveOnRefresh | |||
public class CheckBoxRevertValueChange extends AbstractTestUIWithLog { | |||
@Override | |||
protected void setup(VaadinRequest request) { | |||
final CheckBox alwaysUnchecked = new CheckBox("You may not check me"); | |||
alwaysUnchecked | |||
.addValueChangeListener(new Property.ValueChangeListener() { | |||
public void valueChange(Property.ValueChangeEvent event) { | |||
if (alwaysUnchecked.getValue()) { | |||
log("I said no checking!"); | |||
alwaysUnchecked.setValue(false); | |||
} | |||
} | |||
}); | |||
final CheckBox alwaysChecked = new CheckBox("You may not uncheck me"); | |||
alwaysChecked.setValue(true); | |||
alwaysChecked | |||
.addValueChangeListener(new Property.ValueChangeListener() { | |||
public void valueChange(Property.ValueChangeEvent event) { | |||
if (!alwaysChecked.getValue()) { | |||
log("I said no unchecking!"); | |||
alwaysChecked.setValue(true); | |||
} | |||
} | |||
}); | |||
addComponent(alwaysUnchecked); | |||
addComponent(alwaysChecked); | |||
} | |||
@Override | |||
protected String getTestDescription() { | |||
return "Ensure checking of a checkbox can be reverted on the server side without making the client go out of sync"; | |||
} | |||
@Override | |||
protected Integer getTicketNumber() { | |||
return 11028; | |||
} | |||
} |