@Override public void setChecked(boolean checked, MouseEventDetails mouseEventDetails) { if (isReadOnly()) { 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. */ getUI().getConnectorTracker().getDiffState(CheckBox.this) .put("checked", checked); final Boolean oldValue = getValue(); final Boolean newValue = checked; if (!newValue.equals(oldValue)) { // The event is only sent if the switch state is changed setValue(newValue); } } };
@Test public void setReadOnlyDefaultValue() throws Exception { // GIVEN baseItem = new JcrNewNodeAdapter(baseNode, baseNode.getPrimaryNodeType().getName()); checkBoxField = new CheckBoxFieldFactory(definition, baseItem, uiContext, i18NAuthoringSupport); checkBoxField.setComponentProvider(componentProvider); definition.setDefaultValue("true"); definition.setReadOnly(true); // WHEN Field<Boolean> field = checkBoxField.createField(); // THEN assertEquals(true, field.getValue()); assertTrue(field.isReadOnly()); CheckBox checkBox = (CheckBox) ((CheckBoxField) field).iterator().next(); assertEquals(true, checkBox.getValue()); assertTrue(checkBox.isReadOnly()); }