Showing posts with label grails. Show all posts
Showing posts with label grails. Show all posts

Tuesday, July 31, 2007

Django or Rails for Grails user

I had a wonderful experience with Grails after finishing two projects. If you are a new Java programmer who's looking for a good web frameworks, Grails will be your savior just like what it was to me.

Here's what I like about Grails

  • Relatively easy to learn compared to other Java web frameworks.
  • Provides the basic things that one need, it's all there and there's not much
    to configure (ex. No XML).
  • It's agile!
  • Good ORM built on top of Hibernate.
  • Grails was developed mostly in Java so it's enterprise-ready and it scales well.
  • Uses groovy. Easy to learn Java scripting language
  • Although it's not really Java, it does take advantage of the massive amount of Java libraries available, including ones I use like the Java Excel API and JFreeChart.
  • I like database stored procedure programming, and calling stored procedure
    from Grails is easy as well as executing complex sql queries.
  • Integrate my choice of Javascript framework easily. I use jQuery.
  • Grails helps me code properly because of its MVC pattern and services
    concept.
  • Grails plug-in are so cool like Quartz and Searchable

One of the requirements of my next project is that it be hosted on the internet. My client doesn't care what technology I use but wants the hosting fee to be as low as possible. And as we all know, Java web hosting is not cheap compared to others.

I hope to use a non-Java web framework, Django or Ruby on Rails, that I could be comfortable with because of the knowledge and experience I have with Grails. I'd like to see the things that I like in Grails on them. Right now, I'm gearing towards Django because I know a little of Python.

Comments & Suggestions?

Thursday, July 5, 2007

My Grails Practices

After learning Grails and finish 2 small project with it in 4 months time, here are a number of the practices I do to develop faster and comfortable for me. As I am new to Grails as well as to java web development, the practices here may not be wrong and your comments are very much welcome.

A controller's action performing post and get.

I have a lot of that in my project, where it really helps me organize my code to be more readable and maintainable and less confusing. This is not against to be CRUD pattern that grails generate, but somehow I feel not comfortable with it, because I have to think two action's name instead of one. For example, I have view employee profile page where you can extends the the employee's contract or terminate the employee's contract. Here's how I code it

def extendEmployeeContract {
if (request.method == 'GET') {
// preparing the page for extending the employee's contract
}
else if (request.method == 'POST') {
// performing the employee's contract extension
}
}

instead of

def createEmployeeContractExtension {
// preparing the page for extending the employee's contract
}

def saveEmployeeContractEntersion {
// performing the employee's contract extension
}


Restricting an action to post only if applicable

Here's how grails make it easy for you, just define it in the allowedMethods attributes.

def allowedMethods = [checkEmployee:'POST']

This makes your application much more secure.

Do you manual assignment after object.properties = params

Sometimes I need to do some manual assignment when an attribute is your domain class, and be able to validate the object that we want to assign to an object's attribute. Doing so we avoid a hibernate error saying that a object's identifier is alter from 1 to 2 which are the id of the object.

Use java.sql.date for date attribute

Using java.sql.date could result into a date field on your database while java.util.date could give you a datetime field in your database which give me a problem when I perform a query with the dynamic find method. This gives me additional work to do because the object.properties = params won't work here but this bug is fix and will be on the next release.

Another reason I use java.sql.date is because of how I implement my user interface. I am not using the gsp datepicker tag, instead I use a regular text field which is much faster to input in for the user and you can use any javascript datepicker solution. For the date format I use yyyy-M-d and it suit very well to java.sql.date, use the java.sql.date.valueOf() static method. Here's how I implement it.

employee.birthday = params.birthday =~ /\d{4}-\d{1,2}-\d{1,2}/ ? java.sql.date.valueOf(params.birthday):null

This validates the user's input and if it's a invalid format, a null will assign to the date attribute which trigger the null constraints I define.

More will be from you, I be glad to hear it.

Friday, June 22, 2007

Grails, Java(JSF/JPA), ROR comparison from Java One

I came across a very interesting web framework comparison between Grails, Java(JSF/JPA), Ruby on Rails from Java One. At the end of the day, the framework of choice still depend on the needs of your projects and available resources. Here are the links:

Ruby’s easy but Java is quicker

Comparing the Developer Experience of Java EE 5.0, Ruby on Rails, and Grails: Lessons Learned from Developing One Application


Things could get more interesting when we could see ROR with JRuby and Grails version 1 to be release hopefully on October.

Tuesday, April 10, 2007

Are you groovy?

Cellphone for groovy people ...


Car for groovy people ...


T-shirt for groovy people ...

Web framework for groovy people ...


Programming language for groovy people ...

So ... are you groovy? :-)

Thanks to Sven Haiges for the permission in using the groovy t-shirt image.

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.