Wednesday, November 9, 2011

EL 2.2 and Weblogic 10.3.5

EL 2.2 has some nice features where in you can pass objects to the methods to perform some actions. This feature has nice advantage when you combine with JSF 2.0 however it will not work with JSF 1.2. If you are using JEE6 server EL 2.2 is supported out of box and for any that do not then you have to copy the el-api-2.2 and el-impl-2.2 jar files to web application class path (WEB-INF/lib) and add below context parameter to web.xml and it should work. For weblogic to support we have to add weblogic.xml file as well.

1. Copy the el-api-2.2 and el-impl-2.2 jar to web application class path (WEB-INF/lib). Below is the POM if you are using maven


 <!-- EL Dependencies -->
        <dependency>
            <groupId>javax.el</groupId>
            <artifactId>el-api</artifactId>
            <version>2.2</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.web</groupId>
            <artifactId>el-impl</artifactId>
            <version>2.2</version>
        </dependency>

2. Add below context param to web.xml


   <context-param>
        <param-name>com.sun.faces.expressionFactory</param-name>
        <param-value>com.sun.el.ExpressionFactoryImpl</param-value>
    </context-param>

3. Add weblogic.xml below WEB-INF

<?xml version='1.0' encoding='UTF-8'?>
<weblogic-web-app xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.0/weblogic-web-app.xsd">
    <weblogic-version>10.3.4</weblogic-version>
    <context-root>demo</context-root>
    <container-descriptor>
        <prefer-application-packages>
            <package-name>com.sun.el.*</package-name>
            <package-name>javax.el.*</package-name>
        </prefer-application-packages>
    </container-descriptor>
</weblogic-web-app>

Now you can pass objects form JSF to actions directly.  Ex is  below


<h:form>
        <h:dataTable value="#{userManager.users}" var="user">
            <h:column>#{user.id}</h:column>
            <h:column>#{user.name}</h:column>
            <h:column>#{user.email}</h:column>
            <h:column><h:commandButton value="Edit" action="#{userManager.edit(user)}" /></h:column>
        </h:dataTable>
    </h:form>

And you Managed bean will have edit method


public void edit(User user) {
        this.user = user;
        this.edit = true;
    }



That's it happy coding :-)


2 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. This solution worked in a EAR file or WAR file?

    ReplyDelete

PF