Grails in Action
eBook - ePub

Grails in Action

Peter Ledbrook, Glen Smith

Share book
  1. 576 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Grails in Action

Peter Ledbrook, Glen Smith

Book details
Book preview
Table of contents
Citations

About This Book

Summary Grails in Action, Second Edition is a comprehensive introduction to Grails 2 focused on making you super-productive fast. In this totally revised new edition, you'll master Grails 2.3 core skills as you apply TDD techniques to developing a full-scale Twitter clone. Along the way you'll learn the latest single-page web app UI techniques, work with NoSQL backends, integrate with enterprise messaging, and implement a complete RESTful API for your services. Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications. About the Technology It may be time for you to stop reconfiguring, rewriting, and recompiling your Java web apps. Grails, a Groovy-powered web framework, hides all that busy work so you can concentrate on what your applications do, not how they're built. In addition to its famously intuitive dev environment and seamless integration with Spring and Hibernate, the new Grails 2.3 adds improved REST support, better protection against attacks from the web, and better dependency resolution. About the Book Grails in Action, Second Edition is a comprehensive introduction to Grails 2. In this totally revised edition you'll master Grails as you apply TDD techniques to a full-scale example (a Twitter clone). Along the way you'll learn single-page web app techniques, work with NoSQL back ends, integrate with enterprise messaging, implement a RESTful API... and more.No Java or Groovy knowledge is required. Some web development and OOP experience is helpful. What's Inside

  • Covers Grails 2.3 from the ground up
  • Agile delivery and testing using Spock
  • How to use and manage plugins
  • Tips and tricks from the trenches


About the Authors There's no substitute for experience: Glen Smith and Peter Ledbrook have been fixtures in the Grails community, contributing code, blogging, and speaking at conferences worldwide, since Grails 0.2. Table of Contents
PART 1 INTRODUCING GRAILS

  • Grails in a hurry
  • The Groovy essentials
  • PART 2 CORE GRAILS
  • Modeling the domain 63
  • Creating the initial UI
  • Retrieving the data you need
  • Controlling application flow
  • Services and data binding
  • Developing tasty forms, views, and layouts
  • PART 3 EVERYDAY GRAILS
  • Building reliable applications
  • Using plugins: just add water
  • Protecting your application
  • Exposing your app to other programs
  • Single-page web applications (and other UI stuff)
  • Understanding Spring and transactions
  • PART 4 ADVANCED GRAILS
  • Understanding events, messaging, and scheduling
  • NoSQL and Grails
  • Beyond compile, test, run
  • Grails in the cloud
  • BONUS ONLINE CHAPTERS
  • Advanced GORM kung fu
  • Developing plugins

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is Grails in Action an online PDF/ePUB?
Yes, you can access Grails in Action by Peter Ledbrook, Glen Smith in PDF and/or ePUB format, as well as other popular books in Computer Science & Programming in Java. We have over one million books available in our catalogue for you to explore.

Information

Publisher
Manning
Year
2014
ISBN
9781638355311

Part 1. Introducing Grails

The field of Java-based web application frameworks has made great strides in usability, but creating an application with them is still hard work. Grails’s core strength is developing web applications quickly, so you’ll jump into writing your first application right away.
In chapter 1, we expose you to the core parts of Grails by developing a simple Quote of the Day (QOTD) application from scratch. You’ll store to and query from the database, develop business logic, write tests, and add Ajax functionality. By the end of it, you’ll have a feel for the parts of Grails.
To develop serious Grails applications, you need a firm grasp of Groovy—the underlying dynamic language that makes Grails tick. In chapter 2, we take you on a whirlwind tour of core Groovy concepts and introduce the syntax.
By the end of part 1, you’ll understand the power of Groovy and Grails and be ready to take on the world. Feel free to do so—Grails encourages experimentation. But you might want to stick around for part 2, where we take you deeper into the core parts of Grails.

Chapter 1. Grails in a hurry . . .

This chapter covers
  • What is Grails?
  • Core Grails philosophy
  • Grails installation
  • Key components of a Grails application
  • Your first Grails application—developing and deploying it
“Help, I’ve lost my Mojo!” That statement is a concise summary of what developers feel when working with any of the plethora of Java web frameworks. Each change requires time spent editing configuration files, customizing web.xml files, writing injection definitions, tweaking build scripts, modifying page layouts, and restarting apps. Aaaahhhh! “Where has all the fun gone? Why is everything so tedious? I wanted to whip up a quick app to track our customer signups! There must be a better way . . .” We hear you.
Grails is a next-generation Java web development framework that draws on best-of-breed web development tooling, techniques, and technologies from existing Java frameworks, and combines them with the power and innovation of dynamic language development. The result is a framework that offers the stability of technologies you know and love, but shields you from the noisy configuration, design complexity, and boilerplate code that make existing Java web development tedious. Grails allows you to spend your time implementing features, not editing XML.
But Grails isn’t the first player to make such claims. You’re thinking, “Please don’t let this be YAJWF (Yet Another Java Web Framework)!” Because if the Java development world is famous for one thing, it’s having an unbelievably large number of web frameworks. Struts, WebWork, JavaServer Faces (JSF), Spring MVC, Seam, Wicket, Tapestry, Stripes, Google Web Toolkit (GWT), and the list goes on and on—all with their own config files, idioms, templating languages, and gotchas. And now we’re introducing a new one?
The good news is that this ain’t your grandma’s web framework. We’re about to take you on a journey to a whole new level of getting stuff done—and getting it done painlessly. We’re excited about Grails because we think it’s time that Java web app development was fun again! It’s time for you to sit down for an afternoon and crank out something you’d be happy demoing to your boss, client, or the rest of the internet. Grails is that good.
In this chapter, we take you through developing your first Grails app. Not a toy, either. Something you can deploy and show your friends. An app that’s data-driven and Ajax-powered that has full CRUD (create, read, update, delete) implementation, a template-driven layout, and even unit tests. All in the time it takes to eat your lunch, with less than 100 lines of code. Seriously.
But before you fire up your IDE and get your hands dirty writing code, you may need more convincing about why Grails is such a game-changer and should be on your radar.

1.1. Introducing Grails

Grails is a next-generation Java web development framework that generates developer productivity gains through the confluence of a dynamic language, a convention over configuration philosophy, powerfully pragmatic supporting tools, and an agile perspective drawn from the best emerging web development paradigms.

1.1.1. Why Grails changed the game

Grails entered the Java Web Application landscape in 2006 and has grown steadily in adoption since. Taking full advantage of Groovy as the underlying dynamic language, Grails made it possible to create a Book object and query it with dynamic methods such as Book.findByTitle("Grails in Action") or Book.findAllBy-DatePublished-GreaterThanAndTitleLike(myDate, "Grails"), even though none of those methods existed on the Book object.
Even better, you could access any Java code or libraries you were already using, and the language syntax was similar enough to Java to make the learning curve painless. But best of all, at the end of the day you had a WAR file to deploy to your existing Java app server—no special infrastructure required, and no management awareness needed.
The icing on the cake was that Grails was built on Spring, Hibernate, and other libraries already popular and used by enterprise Java developers. It was like turbocharging existing development practices without sacrificing reliability or proven technologies.
Grails’s popularity exploded. Finally, Java web developers had a way to take all the cool ideas that Rails had brought to the table and apply them to robust enterprise-strength web application development, without leaving behind any of their existing skills, libraries, or infrastructure.

1.1.2. Seven big ideas

That’s enough history about how Grails came to be such a popular Java web framework. But if you (or your manager) need further convincing that Grails is an outstanding option for your next big web app project, the following subsections discuss seven of the big ideas (shown in figure 1.1) that drove Grails to such a dominant position in the emerging next-gen Java web frameworks market.
Figure 1.1. The Grails ecosystem is a powerful confluence of people, ideas, and technology.
Big idea #1: convention over configuration
One of the things you’ll notice about developing with Grails is how few configuration files exist. Grails makes most of its decisions based on sensible defaults drawn from your source code:
  • Add a controller class called ShopController with an action called order, and Grails will expose it as a URL of /yourapp/shop/order.
  • Place your view files in a directory called /views/shop/order, and Grails will link everything for you without a single line of configuration.
  • Create a new domain class called Customer, and Grails will automatically create a table called customer in your database.
  • Add fields to your Customer object, and Grails will automatically create the necessary fields in your customer table on the fly (including the right data types based...

Table of contents