advertisement
Premier Club Log In/Registration
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   SKILLBUILDING  |   TIP BANK  |   SOURCEBANK  |   FORUMS  |   NEWSLETTERS
Browse DevX
Download the Code!
Sidebar 1. The Render Method
Partners & Affiliates
advertisement
advertisement
Average Rating: 4/5 | Rate this item | 1 user has rated this item.
 Print Print
 
Build Your First Grails Project: A Grails-Powered Blog
Need to clear out the clutter of your Java web development? Say hello to coding by convention with Grails. 

advertisement
xperienced web developers know well how many layers of conversion they have to go through to present persistent information to the user:
  1. Mapping web requests to executing code
  2. Converting objects to relational data
  3. Rendering markup from their object structures


Open source frameworks (particularly Spring and Hibernate) have become extremely good at easing the pain of these conversions, but that ease has come at a price: reams of XML configuration. On a typical web project using Spring and Hibernate, I spend a great deal of my time writing, updating, and debugging configuration files rather than implementing the valuable business logic I am paid to write.

Just imagine how much easier life would be if Spring knew where all your controllers were and Hibernate could find your domain objects all by themselves. Well, it turns out they can thanks to coding by convention, a development paradigm introduced by Ruby on Rails.

Coding by convention is at the heart of Grails, a rapid application development framework implemented in Groovy, a dynamic language that is syntactically similar to Java and runs in the Java Virtual Machine (JVM). Grails is implemented through a series of plugins. Each of these plugins is executed during application initialization and is able to register beans in the Spring ApplicationContext. There is a plugin to configure Hibernate, another plugin to tell Spring and Hibernate that all classes in the domain directory can be persisted to the database, another plugin to register all classes under the controllers directory as Spring controllers, and so on.

This article shows the power of Grails through the practical example of building a blog application. It does not cover Groovy in any depth, rather, it providing explanations only of the particular Groovy syntax that is used in the example. Simply put, Groovy can make calls to Java classes directly, so if you put your Groovy code in the right place, Grails does the rest.

Getting Started
Go to your development workspace and run this in the command prompt:


grails create-app groovypublish

This will create a folder called groovypublish and a grails-app directory under that, which contains the following directories:

  • conf
  • controllers
  • domain
  • i18n
  • services
  • taglib
  • utils
  • views

This article concentrates on the controllers, domain, and views folders. If you are familiar with the Model View Controller (MVC) pattern, you can figure out what goes in each of these directories, but they will be introduced in more detail as the example progresses.

Page 1 of 5


advertisement
  Next Page: Building the Blog, Domain First
Page 1: IntroductionPage 4: Let the Users In
Page 2: Building the Blog, Domain FirstPage 5: Add Comments
Page 3: Validate the Domain 
advertisement
Advertising Info  |   Member Services  |   Permissions  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About


JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Microsoft Article: Will Hyper-V Make VMware This Decade's Netscape?
Microsoft Article: 7.0, Microsoft's Lucky Version?
Microsoft Article: Hyper-V--The Killer Feature in Windows Server 2008
Avaya Article: How to Feed Data into the Avaya Event Processor
Microsoft Article: Install What You Need with Windows Server 2008
HP eBook: Putting the Green into IT
Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
Avaya Article: Setting Up a SIP A/S Development Environment
IBM Article: How Cool Is Your Data Center?
Microsoft Article: Managing Virtual Machines with Microsoft System Center
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Video: Are Multi-core Processors Here to Stay?
On-Demand Webcast: Five Virtualization Trends to Watch
HP Video: Page Cost Calculator
Intel Video: APIs for Parallel Programming
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Sun Download: Solaris 8 Migration Assistant
Sybase Download: SQL Anywhere Developer Edition
Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
Red Gate Download: SQL Compare Pro 6
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
IBM Article: Collaborating in the High-Performance Workplace
HP Demo: StorageWorks EVA4400
Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES