Browse Source

Do not send value change to server for non-immediate CheckBox (#18102)

Change-Id: I60a58af72d7166869d8bdc8930e16440e02d2ac5
tags/7.5.0.rc1
Teppo Kurki 9 years ago
parent
commit
69f66c8b28

+ 3
- 0
client/src/com/vaadin/client/ui/checkbox/CheckBoxConnector.java View File

@@ -158,6 +158,9 @@ public class CheckBoxConnector extends AbstractFieldConnector implements
.getElement());
getRpcProxy(CheckBoxServerRpc.class).setChecked(getState().checked,
details);
if (getState().immediate) {
getConnection().sendPendingVariableChanges();
}
}
}
}

+ 2
- 0
shared/src/com/vaadin/shared/ui/checkbox/CheckBoxServerRpc.java View File

@@ -16,8 +16,10 @@
package com.vaadin.shared.ui.checkbox;

import com.vaadin.shared.MouseEventDetails;
import com.vaadin.shared.annotations.Delayed;
import com.vaadin.shared.communication.ServerRpc;

public interface CheckBoxServerRpc extends ServerRpc {
@Delayed
public void setChecked(boolean checked, MouseEventDetails mouseEventDetails);
}

+ 62
- 0
uitest/src/com/vaadin/tests/components/checkbox/CheckBoxImmediate.java View File

@@ -0,0 +1,62 @@
/*
* Copyright 2000-2014 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.data.Property.ValueChangeEvent;
import com.vaadin.data.Property.ValueChangeListener;
import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractTestUI;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.Label;

public class CheckBoxImmediate extends AbstractTestUI {
private int count = 0;

@Override
protected void setup(VaadinRequest request) {
final Label status = new Label("Events received: " + count);
status.setId("count");
addComponent(status);

CheckBox cb = new CheckBox("Non-immediate");
ValueChangeListener listener = new ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
count++;
status.setValue("Events received: " + count);
}
};
cb.addValueChangeListener(listener);
cb.setImmediate(false);
addComponent(cb);

cb = new CheckBox("Immediate");
cb.addValueChangeListener(listener);
cb.setImmediate(true);
addComponent(cb);
}

@Override
protected String getTestDescription() {
return "Test for verifying that a non-immediate CheckBox does not send value change to server immediately.";
}

@Override
protected Integer getTicketNumber() {
return 18102;
}

}

+ 53
- 0
uitest/src/com/vaadin/tests/components/checkbox/CheckBoxImmediateTest.java View File

@@ -0,0 +1,53 @@
/*
* Copyright 2000-2014 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 static org.junit.Assert.assertEquals;

import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import com.vaadin.testbench.elements.CheckBoxElement;
import com.vaadin.testbench.elements.LabelElement;
import com.vaadin.tests.tb3.MultiBrowserTest;

public class CheckBoxImmediateTest extends MultiBrowserTest {

@Test
public void testNonImmediateCheckBox() {
openTestURL();

CheckBoxElement checkBoxElement = $(CheckBoxElement.class).first();
WebElement inputElem = checkBoxElement.findElement(By.tagName("input"));
final WebElement countElem = $(LabelElement.class).id("count");

inputElem.click();
assertEquals("Events received: 0", countElem.getText());
}

@Test
public void testImmediateCheckBox() {
openTestURL();

CheckBoxElement checkBoxElement = $(CheckBoxElement.class).get(1);
WebElement inputElem = checkBoxElement.findElement(By.tagName("input"));
final WebElement countElem = $(LabelElement.class).id("count");

inputElem.click();
assertEquals("Events received: 1", countElem.getText());
}
}

+ 10
- 0
uitest/src/com/vaadin/tests/components/checkbox/CheckBoxRpcCount.java View File

@@ -15,6 +15,8 @@
*/
package com.vaadin.tests.components.checkbox;

import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.Property.ValueChangeListener;
import com.vaadin.server.VaadinRequest;
import com.vaadin.shared.MouseEventDetails;
import com.vaadin.shared.ui.checkbox.CheckBoxServerRpc;
@@ -46,6 +48,14 @@ public class CheckBoxRpcCount extends AbstractTestUI {
});
}
};
cb.addValueChangeListener(new ValueChangeListener() {

@Override
public void valueChange(ValueChangeEvent event) {
// Adding an empty ValueChangeListener just to ensure that
// immediate mode is set to true
}
});
addComponent(cb);
}


Loading…
Cancel
Save