Dynamic languages and JSF

Posted by – March 6, 2008

Yesterday I started to think about how can I use languages like Groovy, JRuby, Jython or Scala with JSF, after some research I found a elegant way to do it, in order to do that, you must add the following jars to your project:

  • antlr-2.7.6.jar
  • aopalliance-1.0.jar
  • asm-2.2.3.jar
  • commons-beanutils-1.7.0.jar
  • commons-codec-1.3.jar
  • commons-collections-3.1.jar
  • commons-digester-1.6.jar
  • commons-el-1.0.jar
  • commons-lang-2.1.jar
  • commons-logging-1.0.4.jar
  • commons-validator-1.2.0.jar
  • groovy-1.5.4.jar
  • myfaces-api-1.1.5-SNAPSHOT.jar
  • myfaces-impl-1.1.5-SNAPSHOT.jar
  • oro-2.0.8.jar
  • spring-aop-2.5.1.jar
  • spring-beans-2.5.1.jar
  • spring-context-2.5.1.jar
  • spring-core-2.5.1.jar
  • spring-web-2.5.1.jar

Now you must create the necessary configuration files:

[code lang="xml"]


contextConfigLocation /WEB-INF/applicationContext.xml

org.springframework.web.context.ContextLoaderListener org.springframework.web.context.request.RequestContextListener

Faces Servlet



Faces Servlet



[code lang="xml"]

"-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"



[code lang="xml"]

http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.5.xsd">



Here’s how your groovy code looks like:

[code lang="groovy"]
package br.eti.faces.groovy.beans

class SayHelloPage {

private String name = "someone"

public String sayHello() {
name = "Hello " + name + "!"
return null

public String getName() {
return name

public void setName(String name) {
this.name = name

You can use this groovy bean in your jsf pages in the same way as any other java bean:

[code lang="html4strict"]
<%@ page session="false"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>


Note: The script-source attribute of <lang:groovy/> or <lang:yourlanguage> tag must point to a absolute path of your classpath where your script file resides.

Please refer to dynamic languages chapter of spring documentation for more details.


1 Comment on Dynamic languages and JSF

  1. Rafael Ponte says:

    Great post Rogerio!!!

    The dynamic languages are very much famous currently, and unites JSF and Groovy is a great idea, congratulations!

    However, in the groovy code i think that you don\’t need to declare the getters and setters methods for its attributes, the groovy generates them dynamically in runtime :) well, i think so.

    Great post!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>