Friday, March 30, 2007

Grails & Seam

Some of you might have read "Are Rails and Grails scalable?" from Michael Yuan and "Grails on the Radar: Now Seam" from Stephen (sorry can't find your complete name). I think it could be nice to know the existence of each other.

Before I learn and use grails, I used to learn seam first. Seam is a nice framework. Here's what I can say from my short learning (3 weeks), If you're into JSF, seam could help you a lot. No need to write a lot of manage beans that JSF requires. It also integrates JSF and EJB3(JPA) nicely, which I believe is powered by hibernate, and by doing that it hides the complexity of hibernate for a newbie like me. I also like the idea of conversation model (but I don't quite understand well). Seam also provide a good validation feature, just provide some annotation on your entity beans then seam will handle the rest. Being able to use Icefaces in seam is a great plus for this framework.

I am happy to found out seam and what it can do, while I having a hard time to use JSF, Spring, Hibernate combination since I have to learn all of them and it's not easy for a newbie. It was painful and time consuming, and seam really makes things easier. But I am just out of luck. I am just a newbie, just learn a little of java last year(2006), then rushing to learn web application development on Java platform (JSF, Spring, Hibernate). For me, I don't think I am ready to use seam, as I don't know anything about EJB. I am confuse with the stateful and session stuff which I try to seek help in the forum but no one has help me out.

Since rails was so popular, I take a look at it and found out to be great and easy. During the time of studying rails, I discover grails also which is similar to rails at the first look. That's where my grails adventure begins.

I found grails to be much easier for a newbie like me. At first I doubt grails, since it was so easy I doubt that there might be a catch like not flexible and powerful enough as a manual JSF, Spring, Hibernate combination or seam could provide. But until now grails handle everything that I need. Thanks for it's nice concept without the complexity. Since my using grails now listing all the things I like would be a long list.

But I miss some nice features from seam, that I wish grails could have some of it in the future. I agree on what Graeme says that "choose what is best for you". Referring to my first paragraph again, knowing the existence of each other could be very helpful for all of us, to improve our preferred framework.

Cheers!

Thursday, March 15, 2007

Grails : calling a stored procedure

My experience with grails is getting richer the longer I use it for web application developing. It's very nice that grails is built on top of spring framework which we can take advantage of. I am not a spring user before but with a help from the nice people at the grails forum I was able to achieve what I want to do.

Calling a stored procedure from a MySQL database or any other database is simple. First we need a datasource which spring could provide for us. I have the following code place in the resources.xml found in the spring folder in your grails folder.


<bean id="dataSource" class=" org.apache.commons.dbcp.BasicDataSource ">
<property name="driverClassName">
<value&rt;org.hsqldb.jdbcDriver</value>
</property>
<property name="url">
<value&rt;jdbc:hsqldb:hsql://localhost</value>
</property>
<property name="username">
<value&rt;sa</value>
</property>
<property name="password">
<value&rt;</value>
</property>
</bean>



I use connection pooling for better performance. In my controller here is how I use the datasource to call a store procedure.


class MainController {

def dataSource // using the datasource we define in the spring's resources.xml

def index = {
Sql sql = new Sql(dataSource)
def row = sql.execute("call create_daily_hours(${new Date()+1})")
}
}


That's it! Notice that I am using Groovy SQL instead of Spring JDBCTemplate. It's a lot more friendlier for a beginner.

Grails really makes everything easy here and provides a lot of flexibility thanks to it's nice integration with spring. From here everything is possible.


Tuesday, March 13, 2007

Re: Grails popularity surges

If you are following grails you might have read Graeme Rocher's blog on grails popularity. I just want to add something into it. Before GroovyBlogs.org, I was using the Google Alert for searching new blogs and news for Grails. Not long ago, I have also create a Google Alert to watch for the other web framework which also new before I got to know Grails.

For the past two weeks, Google Alert has been sending me emails daily for Grails, while it is every other day for the other framework. This shows many people are using Grails, and writing articles that contributes on showing how to use Grails in real life web application development.

I am expecting more to come from Grails and Groovy.