Thứ Hai, 7 tháng 5, 2012

How to Enable EL 2.2 on Tomcat 6

EL 2.2 allows you to pass in parameters in your method expression (i.e. actions and action listeners). See example below:

<h:commandButton id="testButton" value="Test Button"
    actionListener="#{testBean.someMethod('someString')}" />
Inside your bean, you could in turn get your passed in parameters as follows:
public void someMethod(String param) {
System.out.println("param: " + param);
}
Here’s the console output:

param: someString

The following stack has been used for testing:
Apache Tomcat 6.0.26
MyFaces 2.0.2
jdk1.6.0_18

Tomcat 6 doesn’t come with EL (Expression Language) 2.2 and to enable it, follow these steps:
Replace el-api.jar with GlassFish EL 2.2 implementation (el-api-2.2.jar and el-impl-2.2.jar) in the Tomcat “lib” folder. These could be downloaded from the following links:
http://download.java.net/maven/2/org/glassfish/web/el-impl/2.2/el-impl-2.2.jar

http://download.java.net/maven/2/javax/el/el-api/2.2/el-api-2.2.jar

In the web.xml, add the following depending on the implementation:
For MyFaces using Sun’s (GlassFish) EL 2.2, add:


<context-param>
    <param-name>org.apache.myfaces.EXPRESSION_FACTORY</param-name>
    <param-value>com.sun.el.ExpressionFactoryImpl</param-value>
</context-param>

For Mojarra, add:
<context-param>
    <param-name>com.sun.faces.expressionFactory</param-name>
    <param-value>com.sun.el.ExpressionFactoryImpl</param-value>
</context-param>


Basically, if you use Sun’s (GlassFish) EL 2.2 implementation, add this to the param-value: com.sun.el.ExpressionFactoryImpl
If you use Apache’s EL 2.2 implementation, add this to the param-value: org.apache.el.ExpressionFactoryImpl
References:
http://wiki.apache.org/myfaces/HowToEnableEl22
Source: http://code2inspire.wordpress.com/2010/11/05/how-to-enable-el-2-2-on-tomcat-6/

Không có nhận xét nào:

Đăng nhận xét