myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lof...@apache.org
Subject [myfaces-tobago] 11/13: TOBAGO-1633: Use TypeScript instead of JavaScript. Simplify Renderers: remove "inside": selectOneChoiceInsideIn
Date Fri, 23 Oct 2020 18:39:37 GMT
This is an automated email from the ASF dual-hosted git repository.

lofwyr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git

commit 4ce389096ec616eb74a4775f97c036d5f4109d17
Author: Udo Schnurpfeil <udo.schnurpfeil@irian.eu>
AuthorDate: Fri Oct 23 16:46:23 2020 +0200

    TOBAGO-1633: Use TypeScript instead of JavaScript.
    Simplify Renderers: remove "inside": selectOneChoiceInsideIn
---
 .../myfaces/tobago/component/RendererTypes.java    |  2 -
 .../internal/renderkit/renderer/InRenderer.java    | 24 ++++-------
 .../renderer/SelectOneChoiceInsideInRenderer.java  | 50 ----------------------
 .../renderer/SelectOneChoiceRenderer.java          | 29 ++++++++++---
 .../component/SelectOneChoiceTagDeclaration.java   |  2 +-
 .../internal/config/AbstractTobagoTestBase.java    | 12 ++++++
 .../renderkit/renderer/InRendererUnitTest.java     | 25 +++++++++++
 .../renderer/in/input-group-choice-after.html      | 29 +++++++++++++
 8 files changed, 98 insertions(+), 75 deletions(-)

diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/component/RendererTypes.java
b/tobago-core/src/main/java/org/apache/myfaces/tobago/component/RendererTypes.java
index bb72fd0..837cce5 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/component/RendererTypes.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/component/RendererTypes.java
@@ -74,7 +74,6 @@ public enum RendererTypes {
   SelectManyListbox,
   SelectManyShuttle,
   SelectOneChoice,
-  SelectOneChoiceInsideIn,
   SelectOneRadio,
   SelectOneRadioInsideCommand,
   SelectOneListbox,
@@ -152,7 +151,6 @@ public enum RendererTypes {
   public static final String SELECT_MANY_LISTBOX = "SelectManyListbox";
   public static final String SELECT_MANY_SHUTTLE = "SelectManyShuttle";
   public static final String SELECT_ONE_CHOICE = "SelectOneChoice";
-  public static final String SELECT_ONE_CHOICE_INSIDE_IN = "SelectOneChoiceInsideIn";
   public static final String SELECT_ONE_RADIO = "SelectOneRadio";
   public static final String SELECT_ONE_RADIO_INSIDE_COMMAND = "SelectOneRadioInsideCommand";
   public static final String SELECT_ONE_LISTBOX = "SelectOneListbox";
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/InRenderer.java
b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/InRenderer.java
index d4ecc0c..5add983 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/InRenderer.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/InRenderer.java
@@ -21,7 +21,6 @@ package org.apache.myfaces.tobago.internal.renderkit.renderer;
 
 import org.apache.myfaces.tobago.component.Attributes;
 import org.apache.myfaces.tobago.component.Facets;
-import org.apache.myfaces.tobago.component.RendererTypes;
 import org.apache.myfaces.tobago.internal.component.AbstractUIButton;
 import org.apache.myfaces.tobago.internal.component.AbstractUIIn;
 import org.apache.myfaces.tobago.internal.component.AbstractUIInput;
@@ -179,22 +178,17 @@ public class InRenderer<T extends AbstractUIIn> extends MessageLayoutRendererBas
       final FacesContext facesContext, final TobagoResponseWriter writer, final UIComponent
addon) throws IOException {
     if (addon != null) {
       for (final UIComponent child : RenderUtils.getFacetChildren(addon)) {
-        if (child instanceof AbstractUIButton && ((AbstractUIButton) child).isParentOfCommands())
{
+        if (child instanceof AbstractUIButton) {
+          child.encodeAll(facesContext);
+        } else if (child instanceof AbstractUIOut) {
+          child.encodeAll(facesContext);
+        } else if (child instanceof AbstractUISelectOneChoice) {
           child.encodeAll(facesContext);
         } else {
-          if (child instanceof AbstractUIButton) {
-            child.encodeAll(facesContext);
-          } else if (child instanceof AbstractUIOut) {
-            child.encodeAll(facesContext);
-          } else if (child instanceof AbstractUISelectOneChoice) {
-            child.setRendererType(RendererTypes.SelectOneChoiceInsideIn.name());
-            child.encodeAll(facesContext);
-          } else {
-            writer.startElement(HtmlElements.SPAN);
-            writer.writeClassAttribute(BootstrapClass.INPUT_GROUP_TEXT);
-            child.encodeAll(facesContext);
-            writer.endElement(HtmlElements.SPAN);
-          }
+          writer.startElement(HtmlElements.SPAN);
+          writer.writeClassAttribute(BootstrapClass.INPUT_GROUP_TEXT);
+          child.encodeAll(facesContext);
+          writer.endElement(HtmlElements.SPAN);
         }
       }
     }
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/SelectOneChoiceInsideInRenderer.java
b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/SelectOneChoiceInsideInRenderer.java
deleted file mode 100644
index c482410..0000000
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/SelectOneChoiceInsideInRenderer.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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.internal.component.AbstractUISelectOneChoice;
-import org.apache.myfaces.tobago.renderkit.css.BootstrapClass;
-import org.apache.myfaces.tobago.renderkit.css.CssItem;
-
-import javax.faces.context.FacesContext;
-import java.io.IOException;
-
-public class SelectOneChoiceInsideInRenderer<T extends AbstractUISelectOneChoice> extends
SelectOneChoiceRenderer<T> {
-
-  @Override
-  public void encodeBeginInternal(final FacesContext facesContext, final T component) throws
IOException {
-    encodeBeginField(facesContext, component);
-  }
-
-  @Override
-  public void encodeEndInternal(final FacesContext facesContext, final T component) throws
IOException {
-    encodeEndField(facesContext, component);
-  }
-
-  @Override
-  protected CssItem[] getCssItems(final FacesContext facesContext, final AbstractUISelectOneChoice
select) {
-    return new CssItem[]{BootstrapClass.FORM_SELECT};
-  }
-
-  @Override
-  protected String getFieldId(final FacesContext facesContext, final T component) {
-    return component.getClientId(facesContext);
-  }
-}
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/SelectOneChoiceRenderer.java
b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/SelectOneChoiceRenderer.java
index 3a2cd06..d968a55 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/SelectOneChoiceRenderer.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/SelectOneChoiceRenderer.java
@@ -24,7 +24,6 @@ import org.apache.myfaces.tobago.internal.component.AbstractUISelectOneChoice;
 import org.apache.myfaces.tobago.internal.util.HtmlRendererUtils;
 import org.apache.myfaces.tobago.internal.util.SelectItemUtils;
 import org.apache.myfaces.tobago.renderkit.css.BootstrapClass;
-import org.apache.myfaces.tobago.renderkit.css.CssItem;
 import org.apache.myfaces.tobago.renderkit.css.TobagoClass;
 import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
 import org.apache.myfaces.tobago.renderkit.html.HtmlElements;
@@ -43,6 +42,24 @@ public class SelectOneChoiceRenderer<T extends AbstractUISelectOneChoice>
extend
   }
 
   @Override
+  public void encodeBeginInternal(final FacesContext facesContext, final T component) throws
IOException {
+    if (isInside(facesContext, HtmlElements.TOBAGO_IN)) {
+      encodeBeginField(facesContext, component);
+    } else {
+      super.encodeBeginInternal(facesContext, component);
+    }
+  }
+
+  @Override
+  public void encodeEndInternal(final FacesContext facesContext, final T component) throws
IOException {
+    if (isInside(facesContext, HtmlElements.TOBAGO_IN)) {
+      encodeEndField(facesContext, component);
+    } else {
+      super.encodeEndInternal(facesContext, component);
+    }
+  }
+
+  @Override
   public boolean getRendersChildren() {
     return true;
   }
@@ -68,7 +85,7 @@ public class SelectOneChoiceRenderer<T extends AbstractUISelectOneChoice>
extend
     writer.writeClassAttribute(
         TobagoClass.SELECT_ONE_CHOICE,
         TobagoClass.SELECT_ONE_CHOICE.createMarkup(markup),
-        getCssItems(facesContext, component),
+        isInside(facesContext, HtmlElements.TOBAGO_IN) ? BootstrapClass.FORM_SELECT : BootstrapClass.FORM_CONTROL,
         BootstrapClass.borderColor(ComponentUtils.getMaximumSeverity(component)),
         component.getCustomClass());
     if (title != null) {
@@ -91,10 +108,8 @@ public class SelectOneChoiceRenderer<T extends AbstractUISelectOneChoice>
extend
 
   @Override
   protected String getFieldId(final FacesContext facesContext, final T component) {
-    return component.getFieldId(facesContext);
-  }
-
-  protected CssItem[] getCssItems(final FacesContext facesContext, final AbstractUISelectOneChoice
select) {
-    return new CssItem[]{BootstrapClass.FORM_CONTROL};
+    return isInside(facesContext, HtmlElements.TOBAGO_IN)
+        ? component.getFieldId(facesContext)
+        : component.getClientId(facesContext);
   }
 }
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/SelectOneChoiceTagDeclaration.java
b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/SelectOneChoiceTagDeclaration.java
index 14f27c3..6ff1cc1 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/SelectOneChoiceTagDeclaration.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/SelectOneChoiceTagDeclaration.java
@@ -58,7 +58,7 @@ import javax.faces.component.UISelectOne;
     uiComponent = "org.apache.myfaces.tobago.component.UISelectOneChoice",
     uiComponentFacesClass = "javax.faces.component.UISelectOne",
     componentFamily = UISelectOne.COMPONENT_FAMILY,
-    rendererType = {RendererTypes.SELECT_ONE_CHOICE, RendererTypes.SELECT_ONE_CHOICE_INSIDE_IN},
+    rendererType = {RendererTypes.SELECT_ONE_CHOICE},
     allowedChildComponenents = {
         "javax.faces.SelectItem",
         "javax.faces.SelectItems"
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 3e34049..4e2b8e4 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
@@ -36,6 +36,9 @@ import org.apache.myfaces.tobago.component.UIOut;
 import org.apache.myfaces.tobago.component.UIPanel;
 import org.apache.myfaces.tobago.component.UIPopup;
 import org.apache.myfaces.tobago.component.UISegmentLayout;
+import org.apache.myfaces.tobago.component.UISelectItem;
+import org.apache.myfaces.tobago.component.UISelectOneChoice;
+import org.apache.myfaces.tobago.component.UISelectOneRadio;
 import org.apache.myfaces.tobago.component.UISeparator;
 import org.apache.myfaces.tobago.component.UIStyle;
 import org.apache.myfaces.tobago.context.TobagoContext;
@@ -51,6 +54,8 @@ import org.apache.myfaces.tobago.internal.renderkit.renderer.OutRenderer;
 import org.apache.myfaces.tobago.internal.renderkit.renderer.PanelRenderer;
 import org.apache.myfaces.tobago.internal.renderkit.renderer.PopupRenderer;
 import org.apache.myfaces.tobago.internal.renderkit.renderer.SegmentLayoutRenderer;
+import org.apache.myfaces.tobago.internal.renderkit.renderer.SelectOneChoiceRenderer;
+import org.apache.myfaces.tobago.internal.renderkit.renderer.SelectOneRadioRenderer;
 import org.apache.myfaces.tobago.internal.renderkit.renderer.SeparatorRenderer;
 import org.apache.myfaces.tobago.internal.renderkit.renderer.StyleRenderer;
 import org.apache.myfaces.tobago.internal.webapp.HtmlResponseWriter;
@@ -115,6 +120,9 @@ public abstract class AbstractTobagoTestBase extends AbstractJsfTestCase
{
     application.addComponent(Tags.popup.componentType(), UIPopup.class.getName());
     application.addComponent(Tags.separator.componentType(), UISeparator.class.getName());
     application.addComponent(Tags.style.componentType(), UIStyle.class.getName());
+    application.addComponent(Tags.selectItem.componentType(), UISelectItem.class.getName());
+    application.addComponent(Tags.selectOneRadio.componentType(), UISelectOneRadio.class.getName());
+    application.addComponent(Tags.selectOneChoice.componentType(), UISelectOneChoice.class.getName());
     application.addComponent(Tags.gridLayout.componentType(), UIGridLayout.class.getName());
     application.addComponent(Tags.segmentLayout.componentType(), UISegmentLayout.class.getName());
     application.addComponent(Tags.badge.componentType(), UIBadge.class.getName());
@@ -131,6 +139,10 @@ public abstract class AbstractTobagoTestBase extends AbstractJsfTestCase
{
     renderKit.addRenderer(UIPopup.COMPONENT_FAMILY, RendererTypes.POPUP, new PopupRenderer());
     renderKit.addRenderer(UISeparator.COMPONENT_FAMILY, RendererTypes.SEPARATOR, new SeparatorRenderer());
     renderKit.addRenderer(UIStyle.COMPONENT_FAMILY, RendererTypes.STYLE, new StyleRenderer());
+    renderKit.addRenderer(
+        UISelectOneRadio.COMPONENT_FAMILY, RendererTypes.SELECT_ONE_RADIO, new SelectOneRadioRenderer());
+    renderKit.addRenderer(
+        UISelectOneChoice.COMPONENT_FAMILY, RendererTypes.SELECT_ONE_CHOICE, new SelectOneChoiceRenderer());
     renderKit.addRenderer(UIGridLayout.COMPONENT_FAMILY, RendererTypes.GRID_LAYOUT, new GridLayoutRenderer());
     renderKit.addRenderer(UISegmentLayout.COMPONENT_FAMILY, RendererTypes.SEGMENT_LAYOUT,
new SegmentLayoutRenderer());
     renderKit.addRenderer(UIBadge.COMPONENT_FAMILY, RendererTypes.BADGE, new BadgeRenderer());
diff --git a/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/renderkit/renderer/InRendererUnitTest.java
b/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/renderkit/renderer/InRendererUnitTest.java
index a2fabdf..81b0b06 100644
--- a/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/renderkit/renderer/InRendererUnitTest.java
+++ b/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/renderkit/renderer/InRendererUnitTest.java
@@ -27,6 +27,8 @@ import org.apache.myfaces.tobago.component.UIIn;
 import org.apache.myfaces.tobago.component.UILink;
 import org.apache.myfaces.tobago.component.UIOut;
 import org.apache.myfaces.tobago.component.UISegmentLayout;
+import org.apache.myfaces.tobago.component.UISelectItem;
+import org.apache.myfaces.tobago.component.UISelectOneChoice;
 import org.apache.myfaces.tobago.layout.SegmentMeasureList;
 import org.apache.myfaces.tobago.util.ComponentUtils;
 import org.junit.Assert;
@@ -67,6 +69,29 @@ public class InRendererUnitTest extends RendererTestBase {
   }
 
   @Test
+  public void inputGroupChoiceAfter() throws IOException {
+    final UIIn c = (UIIn) ComponentUtils.createComponent(
+        facesContext, Tags.in.componentType(), RendererTypes.In, "id");
+
+    final UISelectOneChoice choice = (UISelectOneChoice) ComponentUtils.createComponent(
+        facesContext, Tags.selectOneChoice.componentType(), RendererTypes.SelectOneChoice,
"choice");
+    c.getFacets().put("after", choice);
+
+    final UISelectItem i1 = (UISelectItem) ComponentUtils.createComponent(
+        facesContext, Tags.selectItem.componentType(), null, "i1");
+    i1.setItemLabel("Stratocaster");
+    choice.getChildren().add(i1);
+    final UISelectItem i2 = (UISelectItem) ComponentUtils.createComponent(
+        facesContext, Tags.selectItem.componentType(), null, "i2");
+    i2.setItemLabel("Telecaster");
+    choice.getChildren().add(i2);
+
+    c.encodeAll(facesContext);
+
+    Assert.assertEquals(loadHtml("renderer/in/input-group-choice-after.html"), formattedResult());
+  }
+
+  @Test
   public void inputGroupDropdownAfter() throws IOException {
     final UIIn c = (UIIn) ComponentUtils.createComponent(
         facesContext, Tags.in.componentType(), RendererTypes.In, "id");
diff --git a/tobago-core/src/test/resources/renderer/in/input-group-choice-after.html b/tobago-core/src/test/resources/renderer/in/input-group-choice-after.html
new file mode 100644
index 0000000..6d655cd
--- /dev/null
+++ b/tobago-core/src/test/resources/renderer/in/input-group-choice-after.html
@@ -0,0 +1,29 @@
+<!--
+ * 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-in id='id' class='mb-3'>
+  <div class='tobago-input-group-outer'>
+    <div class='input-group'>
+      <input type='text' name='id' id='id::field' class='tobago-in form-control'>
+      <select id='choice::field' name='choice' class='tobago-selectOneChoice form-select'>
+        <option value='' class='tobago-selectOneChoice-option'>Stratocaster
+        </option>
+        <option value='' class='tobago-selectOneChoice-option'>Telecaster
+        </option></select>
+    </div>
+  </div>
+</tobago-in>
\ No newline at end of file


Mime
View raw message