You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ta...@apache.org on 2021/04/06 19:07:49 UTC
[myfaces] branch master updated: MYFACES-4389 template
This is an automated email from the ASF dual-hosted git repository.
tandraschko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces.git
The following commit(s) were added to refs/heads/master by this push:
new f60e854 MYFACES-4389 template
f60e854 is described below
commit f60e8542e06a0ebb8e2000d6309fe8fea290b90c
Author: Thomas Andraschko <ta...@apache.org>
AuthorDate: Tue Apr 6 21:07:44 2021 +0200
MYFACES-4389 template
---
.../faces/component/_UISelectItemGroups.java | 50 ++++++++++
.../java/jakarta/faces/model/SelectItemGroup.java | 32 ++++++-
.../view/facelets/tag/jsf/core/CoreLibrary.java | 2 +
.../tag/jsf/core/SelectItemGroupsHandler.java | 57 +++++++++++
.../facelets/tag/jsf/html/SelectOneItemsTest.java | 68 +++++++++++++
.../tag/jsf/html/SelectOneItemsTestBean.java | 106 +++++++++++++++++++++
.../facelets/tag/jsf/html/selectOneItems.xhtml | 36 +++++++
7 files changed, 349 insertions(+), 2 deletions(-)
diff --git a/api/src/main/java/jakarta/faces/component/_UISelectItemGroups.java b/api/src/main/java/jakarta/faces/component/_UISelectItemGroups.java
new file mode 100644
index 0000000..c33cbb3
--- /dev/null
+++ b/api/src/main/java/jakarta/faces/component/_UISelectItemGroups.java
@@ -0,0 +1,50 @@
+/*
+ * 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 jakarta.faces.component;
+
+import jakarta.faces.model.SelectItem;
+import jakarta.faces.model.SelectItemGroup;
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Consumer;
+import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFComponent;
+import org.apache.myfaces.core.api.shared.SelectItemsIterator;
+
+@JSFComponent(clazz = "jakarta.faces.component.UISelectItemGroups",
+ template = true,
+ name = "f:selectItemGroups",
+ bodyContent = "empty")
+abstract class _UISelectItemGroups extends UISelectItems
+{
+
+ static public final String COMPONENT_FAMILY =
+ "jakarta.faces.SelectItemGroups";
+ static public final String COMPONENT_TYPE =
+ "jakarta.faces.SelectItemGroups";
+
+ @Override
+ public Object getValue() {
+ java.util.List<jakarta.faces.model.SelectItemGroup> groups = new java.util.ArrayList<>();
+
+ return groups;
+ }
+}
diff --git a/api/src/main/java/jakarta/faces/model/SelectItemGroup.java b/api/src/main/java/jakarta/faces/model/SelectItemGroup.java
index e5a3992..5be9a53 100755
--- a/api/src/main/java/jakarta/faces/model/SelectItemGroup.java
+++ b/api/src/main/java/jakarta/faces/model/SelectItemGroup.java
@@ -18,6 +18,8 @@
*/
package jakarta.faces.model;
+import java.util.Collection;
+
/**
* see Javadoc of <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/index.html">JSF Specification</a>
*/
@@ -43,7 +45,7 @@ public class SelectItemGroup extends SelectItem
_selectItems = EMPTY_SELECT_ITEMS;
}
- public SelectItemGroup(String label, String description, boolean disabled, SelectItem[] selectItems)
+ public SelectItemGroup(String label, String description, boolean disabled, SelectItem... selectItems)
{
super("", label, description, disabled);
if (selectItems == null)
@@ -52,6 +54,18 @@ public class SelectItemGroup extends SelectItem
}
_selectItems = selectItems;
}
+
+ public SelectItemGroup(String label, String description, boolean disabled,
+ Collection<? extends SelectItem> selectItems)
+ {
+ super("", label, description, disabled);
+ if (selectItems == null)
+ {
+ throw new NullPointerException("selectItems");
+ }
+ _selectItems = selectItems.toArray(new SelectItem[selectItems.size()]);
+ }
+
// METHODS
public SelectItem[] getSelectItems()
@@ -59,7 +73,7 @@ public class SelectItemGroup extends SelectItem
return _selectItems;
}
- public void setSelectItems(SelectItem[] selectItems)
+ public void setSelectItems(SelectItem... selectItems)
{
if (selectItems == null)
{
@@ -67,4 +81,18 @@ public class SelectItemGroup extends SelectItem
}
_selectItems = selectItems;
}
+
+ /**
+ *
+ * @param selectItems
+ * @since 4.0
+ */
+ public void setSelectItems(Collection<? extends SelectItem> selectItems)
+ {
+ if (selectItems == null)
+ {
+ throw new NullPointerException("selectItems");
+ }
+ setSelectItems(selectItems.toArray(new SelectItem[selectItems.size()]));
+ }
}
diff --git a/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/CoreLibrary.java b/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/CoreLibrary.java
index 9e8c4ae..d7cf1bc 100644
--- a/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/CoreLibrary.java
+++ b/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/CoreLibrary.java
@@ -90,6 +90,8 @@ public final class CoreLibrary extends AbstractTagLibrary
this.addComponent("selectItem", UISelectItem.COMPONENT_TYPE, null, SelectItemHandler.class);
this.addComponent("selectItems", UISelectItems.COMPONENT_TYPE, null, SelectItemsHandler.class);
+
+ this.addComponent("selectItemGroups", UISelectItems.COMPONENT_TYPE, null, SelectItemGroupsHandler.class);
this.addTagHandler("setPropertyActionListener", SetPropertyActionListenerHandler.class);
diff --git a/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/SelectItemGroupsHandler.java b/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/SelectItemGroupsHandler.java
new file mode 100644
index 0000000..a520fe5
--- /dev/null
+++ b/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/SelectItemGroupsHandler.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.view.facelets.tag.jsf.core;
+
+import jakarta.faces.view.facelets.ComponentConfig;
+import jakarta.faces.view.facelets.ComponentHandler;
+
+import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFFaceletAttribute;
+import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFFaceletTag;
+
+@JSFFaceletTag(
+ name = "f:selectItemGroups",
+ bodyContent = "empty",
+ componentClass="jakarta.faces.component.UISelectItemGroups")
+public class SelectItemGroupsHandler extends ComponentHandler
+{
+
+ public SelectItemGroupsHandler(ComponentConfig config)
+ {
+ super(config);
+ }
+
+
+ /**
+ * Is either an EL expression pointing to the element in the value collection
+ * whose value should be marked as a "no selection" item, or a literal string
+ * that exactly matches the value of the item in the collection that must be
+ * marked as the "no selection" item. If the user selects such an item and
+ * the field is marked as required, then it will not pass validation.
+ *
+ * @since 2.0
+ * @return
+ */
+ @JSFFaceletAttribute(name = "noSelectionValue",
+ className = "jakarta.el.ValueExpression",
+ deferredValueType = "java.lang.Boolean")
+ private boolean getNoSelectionValue()
+ {
+ return false;
+ }
+}
diff --git a/impl/src/test/java/org/apache/myfaces/view/facelets/tag/jsf/html/SelectOneItemsTest.java b/impl/src/test/java/org/apache/myfaces/view/facelets/tag/jsf/html/SelectOneItemsTest.java
new file mode 100644
index 0000000..393e56e
--- /dev/null
+++ b/impl/src/test/java/org/apache/myfaces/view/facelets/tag/jsf/html/SelectOneItemsTest.java
@@ -0,0 +1,68 @@
+/*
+ * 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.view.facelets.tag.jsf.html;
+
+import jakarta.el.ExpressionFactory;
+import jakarta.faces.application.StateManager;
+import org.apache.myfaces.test.core.AbstractMyFacesCDIRequestTestCase;
+
+import org.apache.myfaces.config.MyfacesConfig;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class SelectOneItemsTest extends AbstractMyFacesCDIRequestTestCase
+{
+ @Override
+ protected boolean isScanAnnotations()
+ {
+ return true;
+ }
+
+ @Override
+ protected void setUpWebConfigParams() throws Exception
+ {
+ super.setUpWebConfigParams();
+ servletContext.addInitParameter("org.apache.myfaces.annotation.SCAN_PACKAGES","org.apache.myfaces.view.facelets.tag.jsf.html");
+ servletContext.addInitParameter(StateManager.STATE_SAVING_METHOD_PARAM_NAME, StateManager.STATE_SAVING_METHOD_CLIENT);
+ servletContext.addInitParameter("jakarta.faces.PARTIAL_STATE_SAVING", "true");
+ servletContext.addInitParameter(MyfacesConfig.REFRESH_TRANSIENT_BUILD_ON_PSS, "auto");
+ }
+
+ @Override
+ protected ExpressionFactory createExpressionFactory()
+ {
+ return new org.apache.el.ExpressionFactoryImpl();
+ }
+
+ @Test
+ public void testIndex() throws Exception
+ {
+ startViewRequest("/selectOneItems.xhtml");
+ processLifecycleExecuteAndRender();
+
+ String content = getRenderedContent();
+ System.err.println(content);
+ Assert.assertTrue(content.contains("Cars"));
+ Assert.assertTrue(content.contains("Animals"));
+ Assert.assertTrue(content.contains("Audi"));
+ Assert.assertTrue(content.contains("Fish"));
+
+ endRequest();
+ }
+}
\ No newline at end of file
diff --git a/impl/src/test/java/org/apache/myfaces/view/facelets/tag/jsf/html/SelectOneItemsTestBean.java b/impl/src/test/java/org/apache/myfaces/view/facelets/tag/jsf/html/SelectOneItemsTestBean.java
new file mode 100644
index 0000000..34a7c44
--- /dev/null
+++ b/impl/src/test/java/org/apache/myfaces/view/facelets/tag/jsf/html/SelectOneItemsTestBean.java
@@ -0,0 +1,106 @@
+/*
+ * 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.view.facelets.tag.jsf.html;
+
+import jakarta.annotation.PostConstruct;
+import jakarta.enterprise.context.RequestScoped;
+import jakarta.inject.Named;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+@Named
+@RequestScoped
+public class SelectOneItemsTestBean {
+
+ private List<Category> categories = new ArrayList<>();
+ private Long selectedProductId;
+
+ @PostConstruct
+ public void init() {
+ categories.add(new Category("Animals", new Product(1L, "Dog"), new Product(2L, "Cat"), new Product(3L, "Fish")));
+ categories.add(new Category("Cars", new Product(4L, "Alfa"), new Product(5L, "Audi"), new Product(6L, "BMW")));
+ }
+
+ public List<Category> getCategories() {
+ return categories;
+ }
+
+ public Long getSelectedProductId() {
+ return selectedProductId;
+ }
+
+ public void setSelectedProductId(Long selectedProductId) {
+ this.selectedProductId = selectedProductId;
+ }
+
+ public static class Product {
+ private Long id;
+ private String name;
+
+ public Product() {
+ }
+
+ public Product(Long id, String name) {
+ this.id = id;
+ this.name = name;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+ }
+
+ public class Category {
+ private String name;
+ private List<Product> products = new ArrayList<>();
+
+ public Category() {
+ }
+
+ public Category(String name, Product... products) {
+ this.name = name;
+ this.products = Arrays.asList(products);
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public List<Product> getProducts() {
+ return products;
+ }
+ }
+}
diff --git a/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/jsf/html/selectOneItems.xhtml b/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/jsf/html/selectOneItems.xhtml
new file mode 100644
index 0000000..275a6cd
--- /dev/null
+++ b/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/jsf/html/selectOneItems.xhtml
@@ -0,0 +1,36 @@
+
+<!--
+ 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.
+
+ $Id$
+-->
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional" "http://www.w3.org/TR/xhtml1/DTD/xhtml22-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:ui="http://java.sun.com/jsf/facelets"
+ xmlns:h="http://java.sun.com/jsf/html"
+ xmlns:f="http://java.sun.com/jsf/core">
+<body>
+
+<ui:composition>
+<form jsfc="h:form" id="testForm">
+ <h:selectOneMenu id="alignment">
+ <f:selectItemGroups value="#{selectOneItemsTestBean.categories}" var="category" itemValue="#{category.name}" itemLabel="#{category.name}">
+ <f:selectItems value="#{category.products}" var="product" itemValue="#{product.id}" itemLabel="#{product.name}" />
+ </f:selectItemGroups>
+ </h:selectOneMenu>
+</form>
+</ui:composition>
+
+
+</body>
+</html>
\ No newline at end of file