As Stan Silvert described in his article 'Design of AS7 multi-JSF feature' : Currently, AS7 ships with two JSF implementations, a JSF 2.1 implementation and a JSF 1.2 implementation. But AS7 didn't ship with myfaces jsf implementation.
In this article, I will show you how to hack jboss as 7 (7.2.0.Final) to add myfaces-2.1.12 as default jsf implementation. It works for me. The steps are as follows:
Summary:
hack to add myfaces-2.1 as default jsf implementation --- build/build.xml | 17 ++++++++ .../resources/configuration/subsystems/jsf.xml | 2 +- .../base/com/sun/jsf-impl/myfaces-2.1/module.xml | 47 ++++++++++++++++++++++ .../base/javax/faces/api/myfaces-2.1/module.xml | 37 +++++++++++++++++ .../org/apache/commons/digester/main/module.xml | 40 ++++++++++++++++++ .../jboss/as/jsf-injection/myfaces-2.1/module.xml | 42 +++++++++++++++++++ jsf/injection/pom.xml | 5 +++ .../as/jsf/deployment/JSFModuleIdFactory.java | 8 ++++ .../jboss/as/jsf/deployment/JsfVersionMarker.java | 4 ++ pom.xml | 10 ++++- 11 files changed, 214 insertions(+), 5 deletions(-)
Details:
1. new file build/src/main/resources/modules/system/layers/base/javax/faces/api/myfaces-2.1/module.xml
<?xml version="1.0" encoding="UTF-8"?> <module xmlns="urn:jboss:module:1.1" name="javax.faces.api" slot="myfaces-2.1"> <dependencies> <module name="javax.el.api" export="true"/> <module name="javax.servlet.api" export="true"/> <module name="javax.servlet.jsp.api" export="true"/> <module name="javax.servlet.jstl.api" export="true"/> <module name="javax.validation.api" export="true"/> </dependencies> <resources> <!-- Insert resources here --> </resources> </module>
2. new file build/src/main/resources/modules/system/layers/base/com/sun/jsf-impl/myfaces-2.1/module.xml
<?xml version="1.0" encoding="UTF-8"?> <module xmlns="urn:jboss:module:1.1" name="com.sun.jsf-impl" slot="myfaces-2.1"> <properties> <property name="jboss.api" value="private"/> </properties> <dependencies> <module name="javax.faces.api" slot="myfaces-2.1"/> <module name="javaee.api"/> <module name="javax.servlet.jstl.api"/> <module name="org.apache.xerces" services="import"/> <module name="org.apache.xalan" services="import"/> <!-- extra dependencies for MyFaces --> <module name="org.apache.commons.collections"/> <module name="org.apache.commons.codec"/> <module name="org.apache.commons.beanutils"/> <module name="org.apache.commons.digester"/> </dependencies> <resources> <!-- Insert resources here --> </resources> </module>
3. new file build/src/main/resources/modules/system/layers/base/org/apache/commons/digester/main/module.xml
<?xml version="1.0" encoding="UTF-8"?> <module xmlns="urn:jboss:module:1.1" name="org.apache.commons.digester"> <properties> <property name="jboss.api" value="private"/> </properties> <resources> <!-- Insert resources here --> </resources> <dependencies> <module name="javax.api"/> <module name="org.apache.commons.collections"/> <module name="org.apache.commons.logging"/> <module name="org.apache.commons.beanutils"/> </dependencies> </module>
4. new file build/src/main/resources/modules/system/layers/base/org/jboss/as/jsf-injection/myfaces-2.1/module.xml
<?xml version="1.0" encoding="UTF-8"?> <module xmlns="urn:jboss:module:1.1" name="org.jboss.as.jsf-injection" slot="myfaces-2.1"> <properties> <property name="jboss.api" value="private"/> </properties> <resources> <!-- Insert resources here --> </resources> <dependencies> <module name="com.sun.jsf-impl" slot="myfaces-2.1"/> <module name="javax.api"/> <module name="org.jboss.as.web"/> <module name="javax.servlet.api"/> <module name="org.jboss.logging"/> <module name="javax.faces.api" slot="myfaces-2.1"/> </dependencies> </module>
5. modify build/build.xml to add model-def of myfaces:
<module-def name="javax.faces.api" slot="myfaces-2.1"> <maven-resource group="org.apache.myfaces.core" artifact="myfaces-api"/> </module-def> <module-def name="com.sun.jsf-impl" slot="myfaces-2.1"> <maven-resource group="org.apache.myfaces.core" artifact="myfaces-impl"/> <maven-resource group="org.apache.myfaces.core" artifact="myfaces-bundle"/> </module-def> <module-def name="org.apache.commons.digester"> <maven-resource group="commons-digester" artifact="commons-digester"/> </module-def> <module-def name="org.jboss.as.jsf-injection" slot="myfaces-2.1"> <maven-resource group="org.jboss.as" artifact="jboss-as-jsf-injection" /> </module-def>
6. make myfaces as default: modify build/src/main/resources/configuration/subsystems/jsf.xml to add "default-jsf-impl-slot" attribute. It will be reflected in standalone.xml.
<subsystem xmlns="urn:jboss:domain:jsf:1.0" default-jsf-impl-slot="myfaces-2.1"/>
7. modify code jsf/subsystem/src/main/java/org/jboss/as/jsf/deployment/JsfVersionMarker.java
diff --git a/jsf/subsystem/src/main/java/org/jboss/as/jsf/deployment/JsfVersionMarker.java b/jsf/subsystem/src/main/java/org/jboss/as/jsf/deployment/JsfVers~ index 23823ee..b668e19 100644 --- a/jsf/subsystem/src/main/java/org/jboss/as/jsf/deployment/JsfVersionMarker.java +++ b/jsf/subsystem/src/main/java/org/jboss/as/jsf/deployment/JsfVersionMarker.java @@ -31,6 +31,10 @@ public class JsfVersionMarker { public static final String JSF_1_2 = "Mojarra-1.2"; public static final String JSF_2_0 = "Mojarra-2.0"; + + // Yaguo Zhou + public static final String JSF_2_1 = "myfaces-2.1"; + public static final String WAR_BUNDLES_JSF_IMPL = "WAR_BUNDLES_JSF_IMPL";
8. modify code jsf/subsystem/src/main/java/org/jboss/as/jsf/deployment/JSFModuleIdFactory.java
diff --git a/jsf/subsystem/src/main/java/org/jboss/as/jsf/deployment/JSFModuleIdFactory.java b/jsf/subsystem/src/main/java/org/jboss/as/jsf/deployment/JSFMo~ index 74011b2..fcb337e 100644 --- a/jsf/subsystem/src/main/java/org/jboss/as/jsf/deployment/JSFModuleIdFactory.java +++ b/jsf/subsystem/src/main/java/org/jboss/as/jsf/deployment/JSFModuleIdFactory.java @@ -99,11 +99,17 @@ public class JSFModuleIdFactory { apiIds.put("1.2", ModuleIdentifier.create(API_MODULE, "1.2")); injectionIds.put("1.2", ModuleIdentifier.create(INJECTION_MODULE, "1.2")); + implIds.put("myfaces-2.1", ModuleIdentifier.create(IMPL_MODULE, "myfaces-2.1")); + apiIds.put("myfaces-2.1", ModuleIdentifier.create(API_MODULE, "myfaces-2.1")); + injectionIds.put("myfaces-2.1", ModuleIdentifier.create(INJECTION_MODULE, "myfaces-2.1")); + allVersions.add("main"); allVersions.add("1.2"); + allVersions.add("myfaces-2.1"); activeVersions.add("main"); activeVersions.add("1.2"); + activeVersions.add("myfaces-2.1"); } private void loadIdsFromModulePath(String modulePath) { @@ -169,6 +175,8 @@ public class JSFModuleIdFactory { if (jsfVersion == null) return defaultSlot; if (JsfVersionMarker.JSF_2_0.equals(jsfVersion)) return defaultSlot; if (JsfVersionMarker.JSF_1_2.equals(jsfVersion)) return "1.2"; + // Yaguo Zhou + if (JsfVersionMarker.JSF_2_1.equals(jsfVersion)) return "myfaces-2.1"; return jsfVersion; }
9. modify jsf/injection/pom.xml
diff --git a/jsf/injection/pom.xml b/jsf/injection/pom.xml index c671da4..81f3624 100644 --- a/jsf/injection/pom.xml +++ b/jsf/injection/pom.xml @@ -53,6 +53,11 @@ <groupId>org.apache.myfaces.core</groupId> <artifactId>myfaces-impl</artifactId> </dependency> + + <dependency> + <groupId>org.apache.myfaces.core</groupId> + <artifactId>myfaces-bundle</artifactId> + </dependency> </dependencies>
10. modify pom.xml
diff --git a/pom.xml b/pom.xml index fed62ad..3a1fdbc 100644 --- a/pom.xml +++ b/pom.xml @@ -123,7 +123,7 @@ <version.org.apache.maven>3.0.4</version.org.apache.maven> <version.org.apache.maven.wagon>2.2</version.org.apache.maven.wagon> <version.org.apache.maven.wagon.http-lightweight>2.2</version.org.apache.maven.wagon.http-lightweight> - <version.org.apache.myfaces.core>2.1.8</version.org.apache.myfaces.core> + <version.org.apache.myfaces.core>2.1.12</version.org.apache.myfaces.core> <version.org.apache.neethi>3.0.2</version.org.apache.neethi> <version.org.apache.openjpa>2.1.1</version.org.apache.openjpa> <version.org.apache.santuario>1.5.3</version.org.apache.santuario> @@ -3113,6 +3113,7 @@ <groupId>commons-beanutils</groupId> <artifactId>commons-beanutils</artifactId> </exclusion> + <!-- <exclusion> <groupId>commons-digester</groupId> <artifactId>commons-digester</artifactId> @@ -3121,12 +3122,19 @@ <groupId>org.apache.myfaces.core</groupId> <artifactId>myfaces-api</artifactId> </exclusion> + --> <exclusion> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> </exclusion> </exclusions> </dependency> + + <dependency> + <groupId>org.apache.myfaces.core</groupId> + <artifactId>myfaces-bundle</artifactId> + <version>${version.org.apache.myfaces.core}</version> + </dependency> <dependency> <groupId>org.apache.maven.wagon</groupId>
After hacking, you need build JBoss AS7 by yourself.
Comments