Skip to content

Commit

Permalink
Merge pull request #4552 from soul2zimate/issue-4551
Browse files Browse the repository at this point in the history
Fix issue 4551, don't compare class name and skip CDIValidator
  • Loading branch information
juneau001 authored Apr 30, 2019
2 parents 39d7be0 + 8072c0f commit e6dacbc
Show file tree
Hide file tree
Showing 7 changed files with 219 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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 "";
}
}
Original file line number Diff line number Diff line change
@@ -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<String> {

@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));
}
}
Original file line number Diff line number Diff line change
@@ -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<String> {

@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));
}
}
17 changes: 17 additions & 0 deletions test/javaee8/cdi/src/main/webapp/issue4551.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!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="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>JAVASERVERFACES-4551 - Integration Test</title>
</h:head>

<h:body>
<h:form id="form">
<h:inputText id="inputText" value="#{customBean.value}">
<f:validator validatorId="validator.CustomValidator1" />
<f:validator validatorId="validator.CustomValidator2" />
</h:inputText>
<h:commandButton id="submit" action="#{customBean.submit}" value="Submit"/>
</h:form>
</h:body>
</html>
Original file line number Diff line number Diff line change
@@ -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"));
}
}

0 comments on commit e6dacbc

Please sign in to comment.