You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by bo...@apache.org on 2021/01/13 07:39:14 UTC
[myfaces-tobago] branch master updated: fix: duplicated IDs for
SelectBooleanCheckbox/Toggle
This is an automated email from the ASF dual-hosted git repository.
bommel pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git
The following commit(s) were added to refs/heads/master by this push:
new f5ea67e fix: duplicated IDs for SelectBooleanCheckbox/Toggle
f5ea67e is described below
commit f5ea67e59c01cb5dee9dde181a3a7f96a831dd6c
Author: Henning Noeth <hn...@apache.org>
AuthorDate: Wed Jan 13 08:31:58 2021 +0100
fix: duplicated IDs for SelectBooleanCheckbox/Toggle
* fix duplicated ids
* add tests
* add SelectBooleanToggle to TestBase
---
.../renderer/SelectBooleanRendererBase.java | 11 +++--
.../internal/config/AbstractTobagoTestBase.java | 6 +++
.../SelectBooleanCheckboxRendererUnitTest.java | 57 ++++++++++++++++++++++
.../SelectBooleanToggleRendererUnitTest.java | 57 ++++++++++++++++++++++
.../selectBooleanCheckboxItemLabel.html | 23 +++++++++
.../selectBooleanCheckboxLabel.html | 24 +++++++++
.../selectBooleanToggleItemLabel.html | 23 +++++++++
.../selectBooleanToggleLabel.html | 24 +++++++++
8 files changed, 222 insertions(+), 3 deletions(-)
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/SelectBooleanRendererBase.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/SelectBooleanRendererBase.java
index 3247163..6b0a20a 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/SelectBooleanRendererBase.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/SelectBooleanRendererBase.java
@@ -80,9 +80,13 @@ public abstract class SelectBooleanRendererBase<T extends AbstractUISelectBoolea
final String itemLabel = component.getItemLabel();
final String itemImage = component.getItemImage();
final Markup markup = component.getMarkup();
+ final boolean insideCommand = isInside(facesContext, HtmlElements.COMMAND);
+
+ writer.startElement(insideCommand ? getComponentTag() : HtmlElements.DIV);
+ if (insideCommand) {
+ writer.writeIdAttribute(clientId);
+ }
- writer.startElement(HtmlElements.TOBAGO_SELECT_BOOLEAN_CHECKBOX);
- writer.writeIdAttribute(clientId);
writer.writeClassAttribute(
BootstrapClass.FORM_CHECK,
getOuterCssItems(facesContext, component),
@@ -133,8 +137,9 @@ public abstract class SelectBooleanRendererBase<T extends AbstractUISelectBoolea
@Override
protected void encodeEndField(final FacesContext facesContext, final T component) throws IOException {
final TobagoResponseWriter writer = getResponseWriter(facesContext);
+ final boolean insideCommand = isInside(facesContext, HtmlElements.COMMAND);
- writer.endElement(HtmlElements.TOBAGO_SELECT_BOOLEAN_CHECKBOX);
+ writer.endElement(insideCommand ? getComponentTag() : HtmlElements.DIV);
encodeBehavior(writer, facesContext, component);
}
diff --git a/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/config/AbstractTobagoTestBase.java b/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/config/AbstractTobagoTestBase.java
index 35d60c6..5fb5346 100644
--- a/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/config/AbstractTobagoTestBase.java
+++ b/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/config/AbstractTobagoTestBase.java
@@ -41,6 +41,7 @@ import org.apache.myfaces.tobago.component.UIPopup;
import org.apache.myfaces.tobago.component.UISection;
import org.apache.myfaces.tobago.component.UISegmentLayout;
import org.apache.myfaces.tobago.component.UISelectBooleanCheckbox;
+import org.apache.myfaces.tobago.component.UISelectBooleanToggle;
import org.apache.myfaces.tobago.component.UISelectItem;
import org.apache.myfaces.tobago.component.UISelectManyCheckbox;
import org.apache.myfaces.tobago.component.UISelectManyListbox;
@@ -68,6 +69,7 @@ import org.apache.myfaces.tobago.internal.renderkit.renderer.PopupRenderer;
import org.apache.myfaces.tobago.internal.renderkit.renderer.SectionRenderer;
import org.apache.myfaces.tobago.internal.renderkit.renderer.SegmentLayoutRenderer;
import org.apache.myfaces.tobago.internal.renderkit.renderer.SelectBooleanCheckboxRenderer;
+import org.apache.myfaces.tobago.internal.renderkit.renderer.SelectBooleanToggleRenderer;
import org.apache.myfaces.tobago.internal.renderkit.renderer.SelectManyCheckboxRenderer;
import org.apache.myfaces.tobago.internal.renderkit.renderer.SelectManyListboxRenderer;
import org.apache.myfaces.tobago.internal.renderkit.renderer.SelectOneChoiceRenderer;
@@ -147,6 +149,7 @@ public abstract class AbstractTobagoTestBase extends AbstractJsfTestCase {
application.addComponent(Tags.segmentLayout.componentType(), UISegmentLayout.class.getName());
application.addComponent(Tags.selectItem.componentType(), UISelectItem.class.getName());
application.addComponent(Tags.selectBooleanCheckbox.componentType(), UISelectBooleanCheckbox.class.getName());
+ application.addComponent(Tags.selectBooleanToggle.componentType(), UISelectBooleanToggle.class.getName());
application.addComponent(Tags.selectManyCheckbox.componentType(), UISelectManyCheckbox.class.getName());
application.addComponent(Tags.selectManyListbox.componentType(), UISelectManyListbox.class.getName());
application.addComponent(Tags.selectOneRadio.componentType(), UISelectOneRadio.class.getName());
@@ -178,6 +181,9 @@ public abstract class AbstractTobagoTestBase extends AbstractJsfTestCase {
UISelectBooleanCheckbox.COMPONENT_FAMILY, RendererTypes.SELECT_BOOLEAN_CHECKBOX,
new SelectBooleanCheckboxRenderer());
renderKit.addRenderer(
+ UISelectBooleanCheckbox.COMPONENT_FAMILY, RendererTypes.SELECT_BOOLEAN_TOGGLE,
+ new SelectBooleanToggleRenderer());
+ renderKit.addRenderer(
UISelectManyCheckbox.COMPONENT_FAMILY, RendererTypes.SELECT_MANY_CHECKBOX, new SelectManyCheckboxRenderer());
renderKit.addRenderer(
UISelectManyListbox.COMPONENT_FAMILY, RendererTypes.SELECT_MANY_LISTBOX, new SelectManyListboxRenderer());
diff --git a/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/renderkit/renderer/SelectBooleanCheckboxRendererUnitTest.java b/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/renderkit/renderer/SelectBooleanCheckboxRendererUnitTest.java
new file mode 100644
index 0000000..22b9541
--- /dev/null
+++ b/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/renderkit/renderer/SelectBooleanCheckboxRendererUnitTest.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.myfaces.tobago.internal.renderkit.renderer;
+
+import org.apache.myfaces.tobago.component.RendererTypes;
+import org.apache.myfaces.tobago.component.Tags;
+import org.apache.myfaces.tobago.component.UISelectBooleanCheckbox;
+import org.apache.myfaces.tobago.util.ComponentUtils;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+
+public class SelectBooleanCheckboxRendererUnitTest extends RendererTestBase {
+
+
+ @Test
+ public void label() throws IOException {
+ final UISelectBooleanCheckbox c = (UISelectBooleanCheckbox) ComponentUtils.createComponent(
+ facesContext, Tags.selectBooleanCheckbox.componentType(), RendererTypes.SelectBooleanCheckbox, "id");
+ c.setLabel("label");
+
+ c.encodeAll(facesContext);
+
+ Assertions.assertEquals(loadHtml("renderer/selectBooleanCheckbox/selectBooleanCheckboxLabel.html"),
+ formattedResult());
+ }
+
+ @Test
+ public void itemLabel() throws IOException {
+ final UISelectBooleanCheckbox c = (UISelectBooleanCheckbox) ComponentUtils.createComponent(
+ facesContext, Tags.selectBooleanCheckbox.componentType(), RendererTypes.SelectBooleanCheckbox, "id");
+ c.setItemLabel("label");
+
+ c.encodeAll(facesContext);
+
+ Assertions.assertEquals(loadHtml("renderer/selectBooleanCheckbox/selectBooleanCheckboxItemLabel.html"),
+ formattedResult());
+ }
+}
diff --git a/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/renderkit/renderer/SelectBooleanToggleRendererUnitTest.java b/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/renderkit/renderer/SelectBooleanToggleRendererUnitTest.java
new file mode 100644
index 0000000..390048e
--- /dev/null
+++ b/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/renderkit/renderer/SelectBooleanToggleRendererUnitTest.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.myfaces.tobago.internal.renderkit.renderer;
+
+import org.apache.myfaces.tobago.component.RendererTypes;
+import org.apache.myfaces.tobago.component.Tags;
+import org.apache.myfaces.tobago.component.UISelectBooleanToggle;
+import org.apache.myfaces.tobago.util.ComponentUtils;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+
+public class SelectBooleanToggleRendererUnitTest extends RendererTestBase {
+
+
+ @Test
+ public void label() throws IOException {
+ final UISelectBooleanToggle c = (UISelectBooleanToggle) ComponentUtils.createComponent(
+ facesContext, Tags.selectBooleanToggle.componentType(), RendererTypes.SelectBooleanToggle, "id");
+ c.setLabel("label");
+
+ c.encodeAll(facesContext);
+
+ Assertions.assertEquals(loadHtml("renderer/selectBooleanToggle/selectBooleanToggleLabel.html"),
+ formattedResult());
+ }
+
+ @Test
+ public void itemLabel() throws IOException {
+ final UISelectBooleanToggle c = (UISelectBooleanToggle) ComponentUtils.createComponent(
+ facesContext, Tags.selectBooleanToggle.componentType(), RendererTypes.SelectBooleanToggle, "id");
+ c.setItemLabel("label");
+
+ c.encodeAll(facesContext);
+
+ Assertions.assertEquals(loadHtml("renderer/selectBooleanToggle/selectBooleanToggleItemLabel.html"),
+ formattedResult());
+ }
+}
diff --git a/tobago-core/src/test/resources/renderer/selectBooleanCheckbox/selectBooleanCheckboxItemLabel.html b/tobago-core/src/test/resources/renderer/selectBooleanCheckbox/selectBooleanCheckboxItemLabel.html
new file mode 100644
index 0000000..75f7cd0
--- /dev/null
+++ b/tobago-core/src/test/resources/renderer/selectBooleanCheckbox/selectBooleanCheckboxItemLabel.html
@@ -0,0 +1,23 @@
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+-->
+
+<tobago-select-boolean-checkbox id='id' class='tobago-margin-bottom'>
+ <div class='form-check col-form-label'>
+ <input class='form-check-input' type='checkbox' value='true' name='id' id='id::field'>
+ <label class='form-check-label' for='id::field'>label</label>
+ </div>
+</tobago-select-boolean-checkbox>
diff --git a/tobago-core/src/test/resources/renderer/selectBooleanCheckbox/selectBooleanCheckboxLabel.html b/tobago-core/src/test/resources/renderer/selectBooleanCheckbox/selectBooleanCheckboxLabel.html
new file mode 100644
index 0000000..aecae62
--- /dev/null
+++ b/tobago-core/src/test/resources/renderer/selectBooleanCheckbox/selectBooleanCheckboxLabel.html
@@ -0,0 +1,24 @@
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+-->
+
+<tobago-select-boolean-checkbox id='id' class='tobago-label-container tobago-margin-bottom'>
+ <label for='id::field' class='col-form-label'>label</label>
+ <div class='form-check col-form-label'>
+ <input class='form-check-input' type='checkbox' value='true' name='id' id='id::field'>
+ <label class='form-check-label' for='id::field'></label>
+ </div>
+</tobago-select-boolean-checkbox>
diff --git a/tobago-core/src/test/resources/renderer/selectBooleanToggle/selectBooleanToggleItemLabel.html b/tobago-core/src/test/resources/renderer/selectBooleanToggle/selectBooleanToggleItemLabel.html
new file mode 100644
index 0000000..1800254
--- /dev/null
+++ b/tobago-core/src/test/resources/renderer/selectBooleanToggle/selectBooleanToggleItemLabel.html
@@ -0,0 +1,23 @@
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+-->
+
+<tobago-select-boolean-toggle id='id' class='tobago-margin-bottom'>
+ <div class='form-check col-form-label form-switch'>
+ <input class='form-check-input' type='checkbox' value='true' name='id' id='id::field'>
+ <label class='form-check-label' for='id::field'>label</label>
+ </div>
+</tobago-select-boolean-toggle>
diff --git a/tobago-core/src/test/resources/renderer/selectBooleanToggle/selectBooleanToggleLabel.html b/tobago-core/src/test/resources/renderer/selectBooleanToggle/selectBooleanToggleLabel.html
new file mode 100644
index 0000000..83b3837
--- /dev/null
+++ b/tobago-core/src/test/resources/renderer/selectBooleanToggle/selectBooleanToggleLabel.html
@@ -0,0 +1,24 @@
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+-->
+
+<tobago-select-boolean-toggle id='id' class='tobago-label-container tobago-margin-bottom'>
+ <label for='id::field' class='col-form-label'>label</label>
+ <div class='form-check col-form-label form-switch'>
+ <input class='form-check-input' type='checkbox' value='true' name='id' id='id::field'>
+ <label class='form-check-label' for='id::field'></label>
+ </div>
+</tobago-select-boolean-toggle>