You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by hn...@apache.org on 2022/10/26 15:02:52 UTC

[myfaces-tobago] 01/01: feat: selectMany

This is an automated email from the ASF dual-hosted git repository.

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

commit 35da332d978a747b75546a6e92243edffa8de536
Author: Henning Noeth <hn...@apache.org>
AuthorDate: Wed Oct 26 17:02:27 2022 +0200

    feat: selectMany
    
    * new component selectMany
    
    Issue: TOBAGO-2159
---
 .../myfaces/tobago/component/RendererTypes.java    |  2 +
 .../org/apache/myfaces/tobago/component/Tags.java  |  2 +
 .../internal/component/AbstractUISelectMany.java   | 79 +++++++++++++++++++
 .../renderkit/renderer/SelectManyRenderer.java     | 48 ++++++++++++
 .../taglib/component/SelectManyTagDeclaration.java | 90 ++++++++++++++++++++++
 5 files changed, 221 insertions(+)

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 0b9f91e1f8..acb7231b48 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
@@ -66,6 +66,7 @@ public enum RendererTypes {
   SegmentLayout,
   SelectBooleanCheckbox,
   SelectBooleanToggle,
+  SelectMany,
   SelectManyCheckbox,
   SelectManyListbox,
   SelectManyShuttle,
@@ -138,6 +139,7 @@ public enum RendererTypes {
   public static final String SEGMENT_LAYOUT = "SegmentLayout";
   public static final String SELECT_BOOLEAN_CHECKBOX = "SelectBooleanCheckbox";
   public static final String SELECT_BOOLEAN_TOGGLE = "SelectBooleanToggle";
+  public static final String SELECT_MANY = "SelectMany";
   public static final String SELECT_MANY_CHECKBOX = "SelectManyCheckbox";
   public static final String SELECT_MANY_LISTBOX = "SelectManyListbox";
   public static final String SELECT_MANY_SHUTTLE = "SelectManyShuttle";
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Tags.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Tags.java
index 14e270a511..750b3c4e7c 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Tags.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Tags.java
@@ -72,6 +72,7 @@ public enum Tags {
   selectBooleanToggle,
   selectItem,
   selectItems,
+  selectMany,
   selectManyCheckbox,
   selectManyListbox,
   selectManyShuttle,
@@ -143,6 +144,7 @@ public enum Tags {
   public static final String SELECT_BOOLEAN_TOGGLE = "selectBooleanToggle";
   public static final String SELECT_ITEM = "selectItem";
   public static final String SELECT_ITEMS = "selectItems";
+  public static final String SELECT_MANY = "selectMany";
   public static final String SELECT_MANY_CHECKBOX = "selectManyCheckbox";
   public static final String SELECT_MANY_LISTBOX = "selectManyListbox";
   public static final String SELECT_MANY_SHUTTLE = "selectManyShuttle";
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUISelectMany.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUISelectMany.java
new file mode 100644
index 0000000000..ab0b95ae12
--- /dev/null
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUISelectMany.java
@@ -0,0 +1,79 @@
+/*
+ * 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.component;
+
+import org.apache.myfaces.tobago.component.SupportFieldId;
+import org.apache.myfaces.tobago.component.SupportsAutoSpacing;
+import org.apache.myfaces.tobago.component.SupportsHelp;
+import org.apache.myfaces.tobago.component.SupportsLabelLayout;
+import org.apache.myfaces.tobago.component.Visual;
+import org.apache.myfaces.tobago.util.ComponentUtils;
+
+import javax.faces.component.behavior.ClientBehaviorHolder;
+import javax.faces.context.FacesContext;
+import java.util.Collection;
+
+/**
+ * {@link org.apache.myfaces.tobago.internal.taglib.component.SelectManyTagDeclaration}
+ */
+public abstract class AbstractUISelectMany extends AbstractUISelectManyBase
+  implements SupportsAutoSpacing, Visual, SupportsLabelLayout, ClientBehaviorHolder, SupportsHelp, SupportFieldId {
+
+  private transient boolean nextToRenderIsLabel;
+
+  @Override
+  public Object[] getSelectedValues() {
+    final Object value = getValue();
+    if (value instanceof Collection) {
+      return ((Collection) value).toArray();
+    } else {
+      return (Object[]) value;
+    }
+  }
+
+  @Override
+  public String getFieldId(final FacesContext facesContext) {
+    return getClientId(facesContext) + ComponentUtils.SUB_SEPARATOR + "field";
+  }
+
+  public abstract Integer getTabIndex();
+
+  public abstract boolean isDisabled();
+
+  public abstract boolean isReadonly();
+
+  public boolean isError() {
+    final FacesContext facesContext = FacesContext.getCurrentInstance();
+    return !isValid()
+      || !facesContext.getMessageList(getClientId(facesContext)).isEmpty();
+  }
+
+  public abstract boolean isFocus();
+
+  @Override
+  public boolean isNextToRenderIsLabel() {
+    return nextToRenderIsLabel;
+  }
+
+  @Override
+  public void setNextToRenderIsLabel(final boolean nextToRenderIsLabel) {
+    this.nextToRenderIsLabel = nextToRenderIsLabel;
+  }
+}
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/SelectManyRenderer.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/SelectManyRenderer.java
new file mode 100644
index 0000000000..49aabce29e
--- /dev/null
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/SelectManyRenderer.java
@@ -0,0 +1,48 @@
+/*
+ * 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.AbstractUISelectMany;
+import org.apache.myfaces.tobago.renderkit.html.HtmlElements;
+
+import javax.faces.context.FacesContext;
+import java.io.IOException;
+
+public class SelectManyRenderer<T extends AbstractUISelectMany> extends SelectManyRendererBase<T> {
+  @Override
+  public HtmlElements getComponentTag() {
+    return null;
+  }
+
+  @Override
+  protected String getFieldId(FacesContext facesContext, T component) {
+    return null;
+  }
+
+  @Override
+  protected void encodeBeginField(FacesContext facesContext, T component) throws IOException {
+
+  }
+
+  @Override
+  protected void encodeEndField(FacesContext facesContext, T component) throws IOException {
+
+  }
+}
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/SelectManyTagDeclaration.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/SelectManyTagDeclaration.java
new file mode 100644
index 0000000000..6c920f589e
--- /dev/null
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/SelectManyTagDeclaration.java
@@ -0,0 +1,90 @@
+/*
+ * 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.taglib.component;
+
+import org.apache.myfaces.tobago.apt.annotation.Behavior;
+import org.apache.myfaces.tobago.apt.annotation.Tag;
+import org.apache.myfaces.tobago.apt.annotation.TagAttribute;
+import org.apache.myfaces.tobago.apt.annotation.UIComponentTag;
+import org.apache.myfaces.tobago.apt.annotation.UIComponentTagAttribute;
+import org.apache.myfaces.tobago.component.ClientBehaviors;
+import org.apache.myfaces.tobago.component.RendererTypes;
+import org.apache.myfaces.tobago.internal.taglib.declaration.HasAutoSpacing;
+import org.apache.myfaces.tobago.internal.taglib.declaration.HasBinding;
+import org.apache.myfaces.tobago.internal.taglib.declaration.HasConverter;
+import org.apache.myfaces.tobago.internal.taglib.declaration.HasConverterMessage;
+import org.apache.myfaces.tobago.internal.taglib.declaration.HasHelp;
+import org.apache.myfaces.tobago.internal.taglib.declaration.HasId;
+import org.apache.myfaces.tobago.internal.taglib.declaration.HasLabel;
+import org.apache.myfaces.tobago.internal.taglib.declaration.HasLabelLayout;
+import org.apache.myfaces.tobago.internal.taglib.declaration.HasRequiredMessageForSelect;
+import org.apache.myfaces.tobago.internal.taglib.declaration.HasTabIndex;
+import org.apache.myfaces.tobago.internal.taglib.declaration.HasTip;
+import org.apache.myfaces.tobago.internal.taglib.declaration.HasValidator;
+import org.apache.myfaces.tobago.internal.taglib.declaration.HasValidatorMessage;
+import org.apache.myfaces.tobago.internal.taglib.declaration.HasValueChangeListener;
+import org.apache.myfaces.tobago.internal.taglib.declaration.IsDisabled;
+import org.apache.myfaces.tobago.internal.taglib.declaration.IsFocus;
+import org.apache.myfaces.tobago.internal.taglib.declaration.IsReadonly;
+import org.apache.myfaces.tobago.internal.taglib.declaration.IsRendered;
+import org.apache.myfaces.tobago.internal.taglib.declaration.IsRequiredForSelect;
+import org.apache.myfaces.tobago.internal.taglib.declaration.IsVisual;
+
+import javax.faces.component.UISelectMany;
+
+/**
+ * Render a multi selection option listbox.
+ */
+@Tag(name = "selectMany")
+@UIComponentTag(
+  uiComponent = "org.apache.myfaces.tobago.component.UISelectMany",
+  uiComponentFacesClass = "javax.faces.component.UISelectMany",
+  componentFamily = UISelectMany.COMPONENT_FAMILY,
+  rendererType = RendererTypes.SELECT_MANY,
+  allowedChildComponenents = {"javax.faces.SelectItem", "javax.faces.SelectItems"},
+  behaviors = {
+    @Behavior(
+      name = ClientBehaviors.CHANGE,
+      isDefault = true),
+    @Behavior(
+      name = ClientBehaviors.INPUT),
+    @Behavior(
+      name = ClientBehaviors.CLICK),
+    @Behavior(
+      name = ClientBehaviors.DBLCLICK),
+    @Behavior(
+      name = ClientBehaviors.FOCUS),
+    @Behavior(
+      name = ClientBehaviors.BLUR)
+  })
+
+public interface SelectManyTagDeclaration
+  extends HasId, IsDisabled, IsRendered, HasBinding, HasTip, HasHelp,
+  IsReadonly, HasConverter, IsRequiredForSelect, HasLabel, HasValidator, HasValueChangeListener, HasLabelLayout,
+  HasValidatorMessage, HasConverterMessage, HasRequiredMessageForSelect, HasTabIndex, IsFocus, IsVisual,
+  HasAutoSpacing {
+
+  /**
+   * The value of the multi select.
+   */
+  @TagAttribute
+  @UIComponentTagAttribute(type = {"java.lang.Object[]", "java.util.List"})
+  void setValue(String value);
+}