diff --git a/impl/src/main/java/com/sun/faces/facelets/tag/jsf/ValidatorTagHandlerDelegateImpl.java b/impl/src/main/java/com/sun/faces/facelets/tag/jsf/ValidatorTagHandlerDelegateImpl.java index 887afef0a1..ab31ff8bd7 100644 --- a/impl/src/main/java/com/sun/faces/facelets/tag/jsf/ValidatorTagHandlerDelegateImpl.java +++ b/impl/src/main/java/com/sun/faces/facelets/tag/jsf/ValidatorTagHandlerDelegateImpl.java @@ -16,6 +16,7 @@ package com.sun.faces.facelets.tag.jsf; +import com.sun.faces.cdi.CdiValidator; import com.sun.faces.component.validator.ComponentValidators; import com.sun.faces.facelets.tag.MetaRulesetImpl; import com.sun.faces.util.Util; @@ -121,7 +122,7 @@ public void applyAttachedObject(FacesContext context, UIComponent parent) { boolean found = false; for (Validator validator : validators) { - if (validator.getClass().equals(v.getClass())) { + if (validator.getClass().equals(v.getClass()) && !(v instanceof CdiValidator)) { found = true; break; } diff --git a/test/javaee8/cdi/src/main/java/com/sun/faces/test/javaee8/cdi/AnnotatedBean.java b/test/javaee8/cdi/src/main/java/com/sun/faces/test/javaee8/cdi/AnnotatedBean.java new file mode 100644 index 0000000000..963b2556d0 --- /dev/null +++ b/test/javaee8/cdi/src/main/java/com/sun/faces/test/javaee8/cdi/AnnotatedBean.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.faces.test.javaee8.cdi; + +import java.io.Serializable; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Named; + +@Named(value = "annotatedBean") +@RequestScoped +public class AnnotatedBean implements Serializable { + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("AnnotatedBean"); + return builder.toString(); + } +} \ No newline at end of file diff --git a/test/javaee8/cdi/src/main/java/com/sun/faces/test/javaee8/cdi/CustomBean.java b/test/javaee8/cdi/src/main/java/com/sun/faces/test/javaee8/cdi/CustomBean.java new file mode 100644 index 0000000000..7578ba0176 --- /dev/null +++ b/test/javaee8/cdi/src/main/java/com/sun/faces/test/javaee8/cdi/CustomBean.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.faces.test.javaee8.cdi; + +import java.io.Serializable; + +import javax.inject.Named; + +@Named(value = "customBean") +public class CustomBean implements Serializable { + + private Long value; + + public Long getValue() { + return value; + } + + public void setValue(Long value) { + this.value = value; + } + + public String submit() { + return ""; + } +} \ No newline at end of file diff --git a/test/javaee8/cdi/src/main/java/com/sun/faces/test/javaee8/cdi/CustomValidator1.java b/test/javaee8/cdi/src/main/java/com/sun/faces/test/javaee8/cdi/CustomValidator1.java new file mode 100644 index 0000000000..abb48f37ca --- /dev/null +++ b/test/javaee8/cdi/src/main/java/com/sun/faces/test/javaee8/cdi/CustomValidator1.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.faces.test.javaee8.cdi; + +import javax.faces.application.FacesMessage; +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.validator.FacesValidator; +import javax.faces.validator.Validator; +import javax.faces.validator.ValidatorException; +import javax.inject.Inject; + +@FacesValidator(value = "validator.CustomValidator1", managed = true) +public class CustomValidator1 implements Validator { + + @Inject + private AnnotatedBean annotatedBean; + + @Override + public void validate(FacesContext context, UIComponent component, String value) throws ValidatorException { + context.addMessage(component.getClientId(context), new FacesMessage("CustomValidator1 was validated with injected " + annotatedBean)); + } +} diff --git a/test/javaee8/cdi/src/main/java/com/sun/faces/test/javaee8/cdi/CustomValidator2.java b/test/javaee8/cdi/src/main/java/com/sun/faces/test/javaee8/cdi/CustomValidator2.java new file mode 100644 index 0000000000..c9d24526f0 --- /dev/null +++ b/test/javaee8/cdi/src/main/java/com/sun/faces/test/javaee8/cdi/CustomValidator2.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.faces.test.javaee8.cdi; + +import javax.faces.application.FacesMessage; +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.validator.FacesValidator; +import javax.faces.validator.Validator; +import javax.faces.validator.ValidatorException; +import javax.inject.Inject; + +@FacesValidator(value = "validator.CustomValidator2", managed = true) +public class CustomValidator2 implements Validator { + + @Inject + private AnnotatedBean annotatedBean; + + @Override + public void validate(FacesContext context, UIComponent component, String value) throws ValidatorException { + context.addMessage(component.getClientId(context), new FacesMessage("CustomValidator2 was validated with injected " + annotatedBean)); + } +} diff --git a/test/javaee8/cdi/src/main/webapp/issue4551.xhtml b/test/javaee8/cdi/src/main/webapp/issue4551.xhtml new file mode 100644 index 0000000000..8e4741ec1e --- /dev/null +++ b/test/javaee8/cdi/src/main/webapp/issue4551.xhtml @@ -0,0 +1,17 @@ + + + + JAVASERVERFACES-4551 - Integration Test + + + + + + + + + + + + \ No newline at end of file diff --git a/test/javaee8/cdi/src/test/java/com/sun/faces/test/javaee8/cdi/Issue4551IT.java b/test/javaee8/cdi/src/test/java/com/sun/faces/test/javaee8/cdi/Issue4551IT.java new file mode 100644 index 0000000000..80e774f868 --- /dev/null +++ b/test/javaee8/cdi/src/test/java/com/sun/faces/test/javaee8/cdi/Issue4551IT.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.faces.test.javaee8.cdi; + +import static org.junit.Assert.assertTrue; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.gargoylesoftware.htmlunit.WebClient; +import com.gargoylesoftware.htmlunit.html.HtmlElement; +import com.gargoylesoftware.htmlunit.html.HtmlPage; + +public class Issue4551IT { + + private String webUrl; + private WebClient webClient; + + @Before + public void setUp() { + webUrl = System.getProperty("integration.url"); + webClient = new WebClient(); + } + + @After + public void tearDown() { + webClient.close(); + } + + @Test + public void testTwoAnnotatedJSFValidatorsInvoked () throws Exception { + HtmlPage page = webClient.getPage(webUrl + "faces/issue4551.xhtml"); + HtmlElement submit = page.getHtmlElementById("form:submit"); + page = submit.click(); + assertTrue(page.asText().contains("CustomValidator1 was validated")); + assertTrue(page.asText().contains("CustomValidator2 was validated")); + } +} \ No newline at end of file