Skip to content
This repository was archived by the owner on Mar 20, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/bin/
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
import javax.faces.validator.Validator;

import com.sun.faces.RIConstants;
import com.sun.faces.cdi.CdiExtension;
import com.sun.faces.cdi.CdiUtils;
import com.sun.faces.component.search.CompositeSearchKeywordResolver;
import com.sun.faces.component.search.SearchKeywordResolverImplAll;
Expand All @@ -105,8 +106,14 @@
import com.sun.faces.component.search.SearchKeywordResolverImplThis;
import com.sun.faces.config.WebConfiguration;
import com.sun.faces.config.WebConfiguration.WebContextInitParameter;

import static com.sun.faces.cdi.CdiUtils.getBeanReference;
import static com.sun.faces.config.WebConfiguration.BooleanWebContextInitParameter.DateTimeConverterUsesSystemTimezone;
import static com.sun.faces.config.WebConfiguration.BooleanWebContextInitParameter.RegisterConverterPropertyEditors;
import static com.sun.faces.util.Util.getCdiBeanManager;
import static com.sun.faces.util.Util.getFacesConfigXmlVersion;
import static com.sun.faces.util.Util.getWebXmlVersion;

import com.sun.faces.el.ELUtils;
import com.sun.faces.el.FacesCompositeELResolver;
import com.sun.faces.el.PropertyResolverImpl;
Expand Down Expand Up @@ -543,12 +550,10 @@ public void addELResolver(ELResolver resolver) {
MessageUtils.ILLEGAL_ATTEMPT_SETTING_APPLICATION_ARTIFACT_ID, "ELResolver"));
}

FacesContext facesContext = FacesContext.getCurrentInstance();
if (Util.getFacesConfigXmlVersion(facesContext).equals("2.3") ||
Util.getWebXmlVersion(facesContext).equals("4.0")) {
if (isJsf23()) {

javax.enterprise.inject.spi.BeanManager beanManager =
Util.getCdiBeanManager(facesContext);
getCdiBeanManager(FacesContext.getCurrentInstance());

if (beanManager != null && !resolver.equals(beanManager.getELResolver())) {
elResolvers.add(resolver);
Expand Down Expand Up @@ -2700,10 +2705,25 @@ private String getFacesConfigXmlVersion(FacesContext facesContext) {
* @return true if we are, false otherwise.
*/
private boolean isJsf23() {

if (isJsf23 == null) {

FacesContext facesContext = FacesContext.getCurrentInstance();
isJsf23 = getFacesConfigXmlVersion(facesContext).equals("2.3");

BeanManager beanManager = getCdiBeanManager(facesContext);

if (beanManager == null) {
// TODO: use version enum and >=
if (getFacesConfigXmlVersion(facesContext).equals("2.3") || getWebXmlVersion(facesContext).equals("4.0")) {
throw new FacesException("Unable to find CDI BeanManager");
}
isJsf23 = false;
} else {
isJsf23 = getBeanReference(beanManager, CdiExtension.class).isAddBeansForJSFImplicitObjects();
}

}

return isJsf23;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ public class InjectInitParameterMapBean {
private Map<String, String> initParameterMap;

public String getInitParameterValue() {
// javax.faces.ENABLE_CDI_RESOLVER_CHAIN set in web.xml, should be true
// otherwise injection will not resolve
return initParameterMap.get("javax.faces.ENABLE_CDI_RESOLVER_CHAIN");
// MY_TEST_PARAMETER set in web.xml, should be available
return initParameterMap.get("MY_TEST_PARAMETER");
}

}
7 changes: 0 additions & 7 deletions test/javaee8/cdi/src/main/webapp/WEB-INF/faces-config.xml

This file was deleted.

8 changes: 1 addition & 7 deletions test/javaee8/cdi/src/main/webapp/WEB-INF/glassfish-web.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app error-url="">
<glassfish-web-app>
<context-root>/test-javaee8-cdi</context-root>
<class-loader delegate="true"/>
<jsp-config>
<property name="keepgenerated" value="true">
<description>Keep a copy of the generated servlet class' java code.</description>
</property>
</jsp-config>
</glassfish-web-app>
27 changes: 8 additions & 19 deletions test/javaee8/cdi/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@

-->

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee web-app_3_0.xsd"
version="3.0">
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee web-app_3_0.xsd"
version="3.0">

<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>${webapp.projectStage}</param-value>
Expand All @@ -66,21 +66,10 @@
<param-name>javax.faces.FACELETS_LIBRARIES</param-name>
<param-value>/WEB-INF/injectBehavior.taglib.xml</param-value>
</context-param>

<context-param>
<param-name>javax.faces.ENABLE_CDI_RESOLVER_CHAIN</param-name>
<param-value>true</param-value>
<param-name>MY_TEST_PARAMETER</param-name>
<param-value>IS_THERE</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>

</web-app>
4 changes: 2 additions & 2 deletions test/javaee8/cdi/src/main/webapp/injectInitParameterMap.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<h:head>
<title>Init parameter Map test</title>
</h:head>

<h:body>
ENABLE_CDI_RESOLVER_CHAIN:#{injectInitParameterMapBean.initParameterValue}
MY_TEST_PARAMETER:#{injectInitParameterMapBean.initParameterValue}
</h:body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ public void setUp() {

@After
public void tearDown() {
webClient.closeAllWindows();
webClient.close();
}

@Test
@JsfTest(value = JsfVersion.JSF_2_3_0_M01,
excludes = {WEBLOGIC_12_1_4, WEBLOGIC_12_2_1})
@JsfTest(value = JsfVersion.JSF_2_3_0_M01, excludes = { WEBLOGIC_12_1_4, WEBLOGIC_12_2_1 })
public void testFacesConfig23() throws Exception {
HtmlPage page = webClient.getPage(webUrl + "faces/mojarraFacesConfigVersion.xhtml");
assertTrue(page.asXml().contains("2.3"));

assertTrue(!page.asXml().contains("2.3"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ public void tearDown() {
public void testInjectInitParameterMap() throws Exception {

HtmlPage page = webClient.getPage(webUrl + "injectInitParameterMap.xhtml");

// Init parameter value should be printed on the page
assertTrue(page.asXml().contains("ENABLE_CDI_RESOLVER_CHAIN:true"));
assertTrue(page.asXml().contains("MY_TEST_PARAMETER:IS_THERE"));
}

}