Pages

Tuesday, May 10, 2011

JSF 2.1.x on Tomcat 6.0

Why does it need to be so difficult to find the right combinations of voodoo to make enterprise applications work? I don't really want an answer. It is just a rhetorical question.

Cay Horstmann has a really good blog entry on JSF 2.0 and Tomcat. It is from a couple of years ago though.

I thought that I would add a little more information to well of knowledge. I have JSF 2.1.1-b04 running on Tomcat 6.0.32 with the addition of new EL (Expression Language) libraries and a context parameter to the web.xml

pom.xml

        <dependency>
            <groupId>javax.el</groupId>
            <artifactId>el-api</artifactId>
            <version>2.2.1-b04</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.web</groupId>
            <artifactId>el-impl</artifactId>
            <version>2.2.1-b05</version>
        </dependency>

web.xml

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

These minor additions allow you to take full advantage of JSF 2.1.x EL syntax. This includes the capability to include parameters to your EL methods such as the action in the h:commandButton below:

        <h:form id="form1">
            <h:inputText id="inputText1" value="#{indexBean.message}"/>
            <h:commandButton id="commandButton1" type="submit" value="Submit" 
                             action="#{indexBean.someAction(value)}"/>
        </h:form>

3 comments:

  1. Thanks! If using Spring Web Flow + richfaces and attempting to upgrade from jsf 2.0 to 2.1.x on tomcat 6, you might run into this error:
    java.lang.UnsupportedOperationException
    at javax.faces.context.FacesContext.isReleased(FacesContext.java:609)
    at com.sun.faces.context.PartialViewContextImpl.updateFacesContext(PartialViewContextImpl.java:468)
    at com.sun.faces.context.PartialViewContextImpl.isAjaxRequest(PartialViewContextImpl.java:108)
    at javax.faces.context.PartialViewContextWrapper.isAjaxRequest(PartialViewContextWrapper.java:117)
    at org.richfaces.context.ExtendedPartialViewContextImpl.isAjaxRequest(ExtendedPartialViewContextImpl.java:138)

    You can fix it with the info here (swf has it as unresolved presently, but corrected source is attached).

    Thanks to your post & the fix to SWF, I was able to get mojarra 2.1.4 running on tomcat 6.0.33 with SWF 2.3.0 & richfaces 4.0.0 :)

    ReplyDelete
  2. Thank you. Works for me here. It helped me with deploying on CloudBees cloud

    ReplyDelete
  3. Thank you so much. It's nice that there's too many good people sharing knowledge on internet.
    This helped me on deploying at CloudBees. =)

    ReplyDelete