Showing posts with label groovy. Show all posts
Showing posts with label groovy. Show all posts

Wednesday, February 18, 2009

Driving a Ferrari and getting Screwy with Groovy!!!

For the last few days, I have been trying to clean up and write new functionality for an existing e-commerce web site which has been written in Groovy on Grails. When I first played with Groovy on Grails, I was amazed at the simplicity at how straight forward web application are amazed. It like getting into a Ferrari, starting the ignition, release the hand brake, hit the gas pedal and let it fly. As you are driving the Ferrari, you realize that you don't know how to turn the Ferrari at 120 mph or do a donut in the snow in it. You then slow down the car and slowly get to know the car. You appreciate the contours of the car, the neat blue tooth capability and the simple ease on how the car handles. As you are appreciating and getting to know the Ferrari, you realize that you are loosing time and wonder if it is really worth it. In the end, mastering on how to drive the Ferrari is your greatest asset as far as going to new destinations.
You must be wondering how is Groovy on Grails and an expensive Ferrari are connected. The answer is that they are connected. To fully appreciate the neat features of Groovy on Grails, you have to sit with the language and get to know it over via your handy dandy IDE. Groovy on Grails may sound wonderful in the beginning however you realize that it is not that easy when you want to build custom functionality. I struggled with building form validation for fields which appear on web form but the data in these fields is not reflected in the database. Groovy on Grails may be a great language however it is like the dark ages in terms of documentation.
Anyway I figured all of my issues for this release and I also found a bug in the Groovy on Grails and a quick work around:
  1. I have a UserAccount class which looks like this:


    class UserAccount implemments Serializable {

    String username
    String firstName
    Address address = new Address()

    static def constraints = {

    }
    }
  2. I have a Address class which looks like this:


    class Address implements Serializable {
    static belongs =[user:UserAccount]

    String streetAddress
    String city

    static def constraints = {

    }

    }
  3. I have a gsp file



I noticed that the textboxes for streetAddress and city didn't highlight in red when the textboxes had invalid data. To get around this issue, I wrote a simple JavaScript function which manually highlighted the textbox if the error message for the textbox is generated. This how ever didn't work (this is the bug). Here is what I had for highlighting the city textbox:
${hasErrors(bean: person?.address, field: 'city', 'errors')}'

This didn't work on its own and the Javascript didn't work. After spending some time with this bug, here is how I resolved:
${hasErrors(bean: person, field: 'city', 'errors')}'
This made the JavaScript to work properly. Hope it helps

Sunday, October 26, 2008

It's cool like that!

For the last few days, I have been playing with Ruby and Groovy. I have to say it very exciting to play with these technologies. Like typical Java applications once you figure out how to configure the application, the development of these applications is very straightforward. I don't have have worry about compiling the files, generating a Web Application Archive (WAR), and deploying the WAR file on the servlet container. Ruby and Groovy for most part take care of this issue. From a software architecture perspective, these two technologies promote software best practices by having built in capabilities to design pattern.

The core philosophy is that it saves time by simply customizing a baselined web application rather than build each class, jsp and configuration file. I was amazed when I built a simple prototype in Ruby and Groovy. It is also takes less time to learn the technology because folks learn alot more when they plan with the code rather than reading a O'reilly book or a Recipe book. It's exciting!

The downsize is that it takes alot more time to understand how the code actually works since the inner working have been abstracted out. I also notice that I would use a standardized approach in naming methods, pages, and classes.

To increase my learning, I have been doing Groovy on JetBrains IntelliJ. It's great and it's better than eclipse. Enjoy!