Monday, January 18, 2010

Grails Hello World

When I started learning this new technology, I really surprised. I remember how much I struggled when I created my fist web application using Tomcat and JSP. In Grails everything is pretty easy and simple.

I know the application that I am going to explain here is very simple. But I want to share my joy, that’s the only reason I am putting it here. Since it is my first application I won’t like use an IDE.

I wanted to create a web application which can do the CRUD operations on Album details. The Album details include name, artist, release, and copies.

  1. I downloaded the binary ZIP from http://www.grails.org/Download
  2. Extracted the zip to C:
  3. Appended C:\grails-1.1.2\bin" to path variable
  4. Created GRAILS_HOME C:\grails-1.1.2
  5. I have created a new workspace C:\grails for putting all my Grails application.


Now the platform is ready for me. I have to do only the coding.

  1. I have created an application inside C:\grails directory. The command is grails create-app AlbumService
  2. Then moved inside AlbumService app. cd AlbumService
  3. I have created a controller for my Album Services grails create-controller Album. It created the a controller named AlbumController.groovy inside C:\grails\AlbumService\grails-app\controllers



    class AlbumController {

    def index = {
    render "

    Grails Hello World

    "
    }
    }


  4. Next I wanted to know whether my service is up or not. So I edited the AlbumController.I put a Grails Hello World inside the controller.
  5. Now to run the application I executed the command grails run-app from C:\grails\AlbumService
  6. When I tried the url: http://localhost:8080/AlbumService/album yes the welcome page is ready.
  7. Now I wanted to create my Album domain class. grails create-domain-class album
  8. After that I have edited the file Album.groovy inside C:\grails\AlbumService\grails-app\domain as below. Also I have changed the AlbumController groovy to make def scaffold = true

    class AlbumController {
    def scaffold = true
    def index = {
    render "

    Grails Hello World

    "
    }
    }


    class Album {
    String name
    String artist
    Date release
    Integer copies
    static constraints = {
    }
    }

  9. I have executed the grials run-app again and opened the url: http://localhost:8080/AlbumService/album/list. I could see the application there I was able to perform all the CRUD operations!!!



0 comments:

Post a Comment