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 2024/03/19 16:44:36 UTC
(myfaces) branch main updated: Test for MYFACES-4656
This is an automated email from the ASF dual-hosted git repository.
tandraschko pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/myfaces.git
The following commit(s) were added to refs/heads/main by this push:
new e0c61414f Test for MYFACES-4656
e0c61414f is described below
commit e0c61414fa5449be4126736321ae7421aebbb636
Author: Thomas Andraschko <ta...@apache.org>
AuthorDate: Tue Mar 19 17:44:25 2024 +0100
Test for MYFACES-4656
---
.../CompositeComponentDefinitionTagHandler.java | 2 +-
.../composite/NotOverwriteRequiredComposite.java | 52 +++++++++++++
.../tag/composite/OverwriteRequiredComposite.java | 57 ++++++++++++++
.../composite/OverwriteRequiredCompositeBean.java | 71 ++++++++++++++++++
.../composite/OverwriteRequiredCompositeTest.java | 87 ++++++++++++++++++++++
.../tag/composite/overwriteRequiredComposite.xhtml | 61 +++++++++++++++
.../notOverwriteRequiredComposite.xhtml | 36 +++++++++
.../testComposite/overwriteRequiredComposite.xhtml | 36 +++++++++
8 files changed, 401 insertions(+), 1 deletion(-)
diff --git a/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/CompositeComponentDefinitionTagHandler.java b/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/CompositeComponentDefinitionTagHandler.java
index f231d374c..aebefbe0f 100644
--- a/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/CompositeComponentDefinitionTagHandler.java
+++ b/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/CompositeComponentDefinitionTagHandler.java
@@ -131,7 +131,7 @@ public final class CompositeComponentDefinitionTagHandler implements FaceletHand
// Only apply if we are building composite component metadata,
// in other words we are calling ViewDeclarationLanguage.getComponentMetadata
- if ( actx.isBuildingCompositeComponentMetadata() )
+ if (actx.isBuildingCompositeComponentMetadata())
{
CompositeComponentBeanInfo tempBeanInfo =
(CompositeComponentBeanInfo) compositeBaseParent.getAttributes()
diff --git a/impl/src/test/java/org/apache/myfaces/view/facelets/tag/composite/NotOverwriteRequiredComposite.java b/impl/src/test/java/org/apache/myfaces/view/facelets/tag/composite/NotOverwriteRequiredComposite.java
new file mode 100644
index 000000000..244cbcade
--- /dev/null
+++ b/impl/src/test/java/org/apache/myfaces/view/facelets/tag/composite/NotOverwriteRequiredComposite.java
@@ -0,0 +1,52 @@
+/*
+ * 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.composite;
+
+import jakarta.faces.component.FacesComponent;
+import jakarta.faces.component.NamingContainer;
+import jakarta.faces.component.UIInput;
+import jakarta.faces.component.UINamingContainer;
+import jakarta.faces.context.FacesContext;
+
+import java.io.Serializable;
+
+@FacesComponent("NotOverwriteRequiredComposite")
+public class NotOverwriteRequiredComposite extends UIInput implements NamingContainer, Serializable {
+
+ public NotOverwriteRequiredComposite() {
+ super();
+ }
+
+ @Override
+ public String getFamily() {
+ return UINamingContainer.COMPONENT_FAMILY;
+ }
+
+ @Override
+ public void decode(FacesContext context) {
+ var submittedValue = getValue();
+ if (submittedValue == null) {
+ submittedValue = "";
+ }
+
+ setSubmittedValue(submittedValue);
+ super.decode(context);
+ }
+
+}
diff --git a/impl/src/test/java/org/apache/myfaces/view/facelets/tag/composite/OverwriteRequiredComposite.java b/impl/src/test/java/org/apache/myfaces/view/facelets/tag/composite/OverwriteRequiredComposite.java
new file mode 100644
index 000000000..7c9c806cd
--- /dev/null
+++ b/impl/src/test/java/org/apache/myfaces/view/facelets/tag/composite/OverwriteRequiredComposite.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.composite;
+
+import jakarta.faces.component.FacesComponent;
+import jakarta.faces.component.NamingContainer;
+import jakarta.faces.component.UIInput;
+import jakarta.faces.component.UINamingContainer;
+import jakarta.faces.context.FacesContext;
+
+import java.io.Serializable;
+
+@FacesComponent("OverwriteRequiredComposite")
+public class OverwriteRequiredComposite extends UIInput implements NamingContainer, Serializable {
+
+ public OverwriteRequiredComposite() {
+ super();
+ }
+
+ @Override
+ public String getFamily() {
+ return UINamingContainer.COMPONENT_FAMILY;
+ }
+
+ @Override
+ public void decode(FacesContext context) {
+ var submittedValue = getValue();
+ if (submittedValue == null) {
+ submittedValue = "";
+ }
+
+ setSubmittedValue(submittedValue);
+ super.decode(context);
+ }
+
+ @Override
+ public boolean isRequired() {
+ return (Boolean) getStateHelper().eval("required", false);
+ }
+
+}
diff --git a/impl/src/test/java/org/apache/myfaces/view/facelets/tag/composite/OverwriteRequiredCompositeBean.java b/impl/src/test/java/org/apache/myfaces/view/facelets/tag/composite/OverwriteRequiredCompositeBean.java
new file mode 100644
index 000000000..a0e0d2cfc
--- /dev/null
+++ b/impl/src/test/java/org/apache/myfaces/view/facelets/tag/composite/OverwriteRequiredCompositeBean.java
@@ -0,0 +1,71 @@
+/*
+ * 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.composite;
+
+import jakarta.faces.view.ViewScoped;
+import jakarta.inject.Named;
+
+import java.io.Serializable;
+
+@Named
+@ViewScoped
+public class OverwriteRequiredCompositeBean implements Serializable
+{
+ private String testString1;
+ private String testString2;
+ private String testString3;
+ private String testString4;
+
+ public String getTestString1() {
+ return testString1;
+ }
+
+ public void setTestString1(String testString1) {
+ this.testString1 = testString1;
+ }
+
+ public String getTestString2() {
+ return testString2;
+ }
+
+ public void setTestString2(String testString2) {
+ this.testString2 = testString2;
+ }
+
+ public String getTestString3() {
+ return testString3;
+ }
+
+ public void setTestString3(String testString3) {
+ this.testString3 = testString3;
+ }
+
+ public String getTestString4() {
+ return testString4;
+ }
+
+ public void setTestString4(String testString4) {
+ this.testString4 = testString4;
+ }
+
+ public boolean isStringRequired() {
+ return true;
+ }
+}
diff --git a/impl/src/test/java/org/apache/myfaces/view/facelets/tag/composite/OverwriteRequiredCompositeTest.java b/impl/src/test/java/org/apache/myfaces/view/facelets/tag/composite/OverwriteRequiredCompositeTest.java
new file mode 100644
index 000000000..8d1415b86
--- /dev/null
+++ b/impl/src/test/java/org/apache/myfaces/view/facelets/tag/composite/OverwriteRequiredCompositeTest.java
@@ -0,0 +1,87 @@
+/*
+ * 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.composite;
+
+import jakarta.el.ExpressionFactory;
+import jakarta.faces.component.UICommand;
+import org.apache.myfaces.test.core.AbstractMyFacesCDIRequestTestCase;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+
+@Disabled
+public class OverwriteRequiredCompositeTest extends AbstractMyFacesCDIRequestTestCase
+{
+ @Override
+ protected boolean isScanAnnotations()
+ {
+ return true;
+ }
+
+ @Override
+ protected void setUpServletObjects() throws Exception
+ {
+ super.setUpServletObjects();
+ servletContext.addInitParameter("org.apache.myfaces.annotation.SCAN_PACKAGES","org.apache.myfaces.view.facelets.tag.composite");
+ servletContext.addInitParameter("jakarta.faces.FACELETS_LIBRARIES", "/test-facelet.taglib.xml");
+ }
+
+ @Test
+ public void testSimpleCompositeComponent() throws Exception
+ {
+ startViewRequest("/overwriteRequiredComposite.xhtml");
+ processLifecycleExecuteAndRender();
+ String content = getRenderedContent(facesContext);
+
+ Assertions.assertTrue(content.contains("form:fifth REQUIRED: false")
+ && content.contains("form:fifth VALID: true"));
+ Assertions.assertTrue(content.contains("form:sixth REQUIRED: true")
+ && content.contains("form:sixth VALID: true"));
+ Assertions.assertTrue(content.contains("form:seventh REQUIRED: true")
+ && content.contains("form:seventh VALID: true"));
+ Assertions.assertTrue(content.contains("form:eight REQUIRED: true")
+ && content.contains("form:eight VALID: true"));
+
+ Assertions.assertTrue(content.contains("form:ninth REQUIRED: false")
+ && content.contains("form:ninth VALID: true"));
+ Assertions.assertTrue(content.contains("form:tenth REQUIRED: true")
+ && content.contains("form:tenth VALID: true"));
+ Assertions.assertTrue(content.contains("form:eleventh REQUIRED: true")
+ && content.contains("form:eleventh VALID: true"));
+ Assertions.assertTrue(content.contains("form:twelvth REQUIRED: true")
+ && content.contains("form:twelvth VALID: true"));
+
+
+
+
+ UICommand button = (UICommand) facesContext.getViewRoot().findComponent("form:process");
+ client.submit(button);
+ processLifecycleExecuteAndRender();
+
+ content = getRenderedContent(facesContext);
+
+ }
+
+ @Override
+ protected ExpressionFactory createExpressionFactory()
+ {
+ return new org.apache.el.ExpressionFactoryImpl();
+ }
+}
diff --git a/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/composite/overwriteRequiredComposite.xhtml b/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/composite/overwriteRequiredComposite.xhtml
new file mode 100644
index 000000000..7acf9ab29
--- /dev/null
+++ b/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/composite/overwriteRequiredComposite.xhtml
@@ -0,0 +1,61 @@
+<!--
+ 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.
+-->
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:ui="jakarta.faces.facelets"
+ xmlns:f="jakarta.faces.core"
+ xmlns:h="jakarta.faces.html"
+ xmlns:pt="jakarta.faces.passthrough"
+ xmlns:cc="jakarta.faces.composite"
+ xmlns:testComposite="jakarta.faces.composite/testComposite">
+<h:head>
+</h:head>
+<h:body>
+
+ <h:form id="form">
+ <testComposite:notOverwriteRequiredComposite id="fifth" value="#{overwriteRequiredCompositeBean.testString1}"
+ label="default optional"/>
+
+ <testComposite:notOverwriteRequiredComposite id="sixth" value="#{overwriteRequiredCompositeBean.testString2}"
+ label="required in curly braces"
+ required="#{true}"/>
+
+ <testComposite:notOverwriteRequiredComposite id="seventh" value="#{overwriteRequiredCompositeBean.testString3}"
+ label="required in string"
+ required="true"/>
+
+ <testComposite:notOverwriteRequiredComposite id="eight" value="#{overwriteRequiredCompositeBean.testString4}"
+ label="required through method"
+ required="#{overwriteRequiredCompositeBean.stringRequired}"/>
+
+ <testComposite:overwriteRequiredComposite id="ninth" value="#{overwriteRequiredCompositeBean.testString1}"
+ label="default optional"/>
+
+ <testComposite:overwriteRequiredComposite id="tenth" value="#{overwriteRequiredCompositeBean.testString2}"
+ label="required in curly braces"
+ required="#{true}"/>
+
+ <testComposite:overwriteRequiredComposite id="eleventh" value="#{overwriteRequiredCompositeBean.testString3}"
+ label="required in string"
+ required="true"/>
+
+ <testComposite:overwriteRequiredComposite id="twelvth" value="#{overwriteRequiredCompositeBean.testString4}"
+ label="required through method"
+ required="#{overwriteRequiredCompositeBean.stringRequired}"/>
+ <h:commandButton id="process" value="process">
+
+ </h:commandButton>
+ </h:form>
+</h:body>
+</html>
\ No newline at end of file
diff --git a/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/composite/resources/testComposite/notOverwriteRequiredComposite.xhtml b/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/composite/resources/testComposite/notOverwriteRequiredComposite.xhtml
new file mode 100644
index 000000000..d0331e37c
--- /dev/null
+++ b/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/composite/resources/testComposite/notOverwriteRequiredComposite.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.
+-->
+<ui:component xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:cc="jakarta.faces.composite"
+ xmlns:ui="jakarta.faces.facelets"
+ xmlns:h="jakarta.faces.html">
+
+ <cc:interface name="NotOverwriteRequiredComposite" componentType="NotOverwriteRequiredComposite">
+ <cc:attribute name="value" required="true"/>
+ <cc:attribute name="label" required="false" type="java.lang.String"/>
+ <cc:attribute name="required" type="java.lang.Boolean" required="false"/>
+ </cc:interface>
+ <cc:implementation>
+ <div class="grid">
+ <div class="col-12">
+ <span>#{cc.clientId} REQUIRED: #{cc.required}</span>
+ <span>#{cc.clientId} VALID: #{cc.valid}</span>
+ </div>
+ <div id="#{cc.clientId}" class="col-12">
+ <h:outputLabel value="#{cc.attrs.label}" for="#{cc.clientId}"/>
+ <h:inputText id="thirdComponentInput" value="#{cc.attrs.value}" label="#{cc.attrs.label}"/>
+ </div>
+ </div>
+ </cc:implementation>
+</ui:component>
\ No newline at end of file
diff --git a/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/composite/resources/testComposite/overwriteRequiredComposite.xhtml b/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/composite/resources/testComposite/overwriteRequiredComposite.xhtml
new file mode 100644
index 000000000..2b1fd9e37
--- /dev/null
+++ b/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/composite/resources/testComposite/overwriteRequiredComposite.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.
+-->
+<ui:component xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:cc="jakarta.faces.composite"
+ xmlns:ui="jakarta.faces.facelets"
+ xmlns:h="jakarta.faces.html">
+
+ <cc:interface name="OverwriteRequiredComposite" componentType="OverwriteRequiredComposite">
+ <cc:attribute name="value" required="true"/>
+ <cc:attribute name="label" required="false" type="java.lang.String"/>
+ <cc:attribute name="required" type="java.lang.Boolean" required="false"/>
+ </cc:interface>
+ <cc:implementation>
+ <div class="grid">
+ <div class="col-12">
+ <span>#{cc.clientId} REQUIRED: #{cc.required}</span>
+ <span>#{cc.clientId} VALID: #{cc.valid}</span>
+ </div>
+ <div id="#{cc.clientId}" class="col-12">
+ <h:outputLabel value="#{cc.attrs.label}" for="#{cc.clientId}"/>
+ <h:inputText id="thirdComponentInput" value="#{cc.attrs.value}" label="#{cc.attrs.label}"/>
+ </div>
+ </div>
+ </cc:implementation>
+</ui:component>
\ No newline at end of file