Gracelets – DSL for JSF Applications

Posted by – September 15, 2008

Sometimes I remeber to visit TSS site to check some news about Java world, one of the threads that catch my attention was the article about use Raven to build Java projects, Raven allows to use your DSLs to write build files on top of Java language, with these DSLs you can do much more than any other build system like Ant but with less code.

You can define your own DSL to solve a specific problem, Raven uses a DSL to write builds scripts, but you can use DSLs to generate XML content, RSS content, HTML pages, SQL statements, create swing applications and to perform unit conversions.

But what about Gracelets? What’s it for?


Gracelets is a view/controller technology that works on top of JSF/Facelets, it allows to use DSLs to write your views, with gracelets you can write your application views with much less code than actual JSF/Facelets pages.

Actually you write a simple JSF/Facelets page using the code below:

1
2
3
4
5
6
7
8
9
10
11
12
13
<?xml version='1.0' encoding='iso-8859-1'?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html">
    <head>
        <title>Hello World Example</title>
    </head>
    <body>
        <h:outputLink value="http://somesite/somepage">
            <h:graphicImage url="someimg.png" border="0"/>
        </h:outputLink>            
    </body>
</html>

With gracelets you only need this:

1
2
3
4
5
6
7
8
xh.html {
     head { title("Hello World Example") }
     body {
         xh.a(href: "http://somesite/somepage") {
             h.graphicImage(url: "someimg.png", style: "border: 0")  
         }
     }
}

Simple, isn’t?

Are you curious about gracelets? Don’t worry! The project is alive and you can check several examples about its usage here.

Share

2 Comments on Gracelets – DSL for JSF Applications

  1. Rafael Ponte says:

    Interesting Rogério, but how does it work with Facelets templates? Is it very simple too?

  2. rogerio says:

    Yes dude, please check an example here.

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>