After a simple Grails application, let's create a CRUDapplication. Such an application allows to perform basic database operations to read table rows from the database, create new rows, and edit and delete existing rows. This blog shows how such an application can be created using Grails, hosted on built-in Jetty servlet engine and use in-memory HSQLDB database for persistence.
A follow-up entry will show how this application can be deployed in production mode on GlassFish and using MySQL database.
- Create a Grails application
- Start the application using built-in Jetty Servlet engine and in-memory HSQLDB database as shown below:
~/testbed/grails-1.0.2/samples/crud >grails run-app
Welcome to Grails 1.0.2 - http://grails.org/
Licensed under Apache Standard License 2.0
Grails home is set to: /Users/arungupta/testbed/grails-1.0.2
Base Directory: /Users/arungupta/testbed/grails-1.0.2/samples/crud
Note: No plugin scripts found
Running script /Users/arungupta/testbed/grails-1.0.2/scripts/RunApp.groovy
Environment set to development
Running Grails application..
2008-04-18 17:26:29.962::INFO: Logging to STDERR via org.mortbay.log.StdErrLog
2008-04-18 17:26:29.075::INFO: jetty-6.1.4
2008-04-18 17:26:29.155::INFO: No Transaction manager found - if your webapp requires one, please configure one.
2008-04-18 17:26:30.886:/crud:INFO: Set web app root system property: 'crud' = [/Users/arungupta/testbed/grails-1.0.2/samples/crud/web-app/]
2008-04-18 17:26:30.886:/crud:INFO: Initializing Log4J from [file:/Users/arungupta/.grails/1.0.2/projects/crud/resources/log4j.properties]
2008-04-18 17:26:30.945:/crud:INFO: Initializing Spring root WebApplicationContext
 spring.GrailsWebApplicationContext Refreshing org.codehaus.groovy.grails.commons.spring.GrailsWebApplicationContext@848dfb: display name [org.codehaus.groovy.grails.commons.spring.GrailsWebApplicationContext@848dfb]; startup date [Fri Apr 18 17:26:32 PDT 2008]; parent: org.springframework.web.context.support.XmlWebApplicationContext@cddcc3
 spring.GrailsWebApplicationContext Bean factory for application context [org.codehaus.groovy.grails.commons.spring.GrailsWebApplicationContext@848dfb]: org.springframework.beans.factory.support.DefaultListableBeanFactory@11f136
2008-04-18 17:26:34.655:/crud:INFO: Initializing Spring FrameworkServlet 'grails'
2008-04-18 17:26:35.716::INFO: Started SelectChannelConnector@0.0.0.0:8080
Server running. Browse to http://localhost:8080/crud
The application is now accessible at "http://localhost:8080/crud" and looks like:
- READ - Click on "StateController" and the following page is shown:
- CREATE - Click on "New State" and enter the values as shown below:
and click on "Create" to see the following page:
- UPDATE & DELETE - You can click on "Edit" or "Delete" to perform U or D of CRUD or click on "State List" to view the updated list as shown below:
Please leave suggestions on other TOTD that you'd like to see. A complete archive is available here.Technorati: groovy grails glassfish jetty hsqldb scripting crud