You are previewing Groovy and Grails Recipes.
O'Reilly logo
Groovy and Grails Recipes

Book Description

Groovy and Grails Recipes is the busy developer's guide to developing applications in Groovy and Grails. Rather than boring you with theoretical knowledge of "yet another language/framework," this book delves straight into solving real-life problems in Groovy and Grails using easy-to-understand, well-explained code snippets. Through learning by example, you will be able to pick up on Groovy and Grails quickly and use the book as an essential reference when developing applications.

Table of Contents

  1. Title Page
  2. Dedication
  3. Contents at a Glance
  4. Contents
  5. About the Author
  6. About the Technical Reviewer
  7. Acknowledgments
  8. Introduction
    1. Who this Book Is For
    2. How this Book Is Structured
    3. Prerequisites
    4. Downloading the Code
    5. Contacting the author
  9. PART 1: Groovy by Example
    1. CHAPTER 1: Getting Started with Groovy
      1. 1-1. What Is Groovy?
      2. 1-2. What Is Wrong with Java?
      3. 1-3. How Does Groovy Address the Shortcomings of Java?
      4. 1-4. How Do I Download and Install Groovy?
      5. 1-5. What Tools Come with Groovy?
      6. 1-6. How Do I Use the Groovy Shell?
      7. 1-7. How Do I Use the Groovy Console?
      8. 1-8. How Do I Use groovyc and groovy?
      9. 1-9. Is There IDE Support for Groovy?
      10. 1-10. How Do I Integrate Groovy with Eclipse?
      11. 1-11. How Do I Integrate Groovy with IntelliJ IDEA?
      12. Summary
    2. CHAPTER 2: From Java to Groovy
      1. 2-1. What Are the Similarities Between Java and Groovy?
      2. 2-2. What Are the Differences Between Java and Groovy?
      3. 2-3. How Do I Integrate Groovy with Java?
      4. Summary
    3. CHAPTER 3: Groovy Data Types and Control Structures
      1. 3-1. What Are the Different Kinds of Strings in Groovy and How Do I Use Them?
      2. 3-2. How Do I Use Regular Expressions in Groovy?
      3. 3-3. How Are Numbers in Groovy Different from Those in Java?
      4. 3-4. How Do I Use Lists in Groovy?
      5. 3-5. How Do I Implement a Merge Sort in Groovy?
      6. 3-6. How Do I Use Maps in Groovy?
      7. 3-7. What Are Ranges and How Do I Use Them in Groovy?
      8. 3-8. What Is the Groovy Truth?
      9. 3-9. How Is the switch Statement in Groovy Different from Java?
      10. 3-10. How Do I Perform Looping in Groovy?
      11. Summary
    4. CHAPTER 4: Object-Oriented Groovy
      1. 4-1. What Are the Differences Between Classes and Scripts?
      2. 4-2. How Do I Use Packages?
      3. 4-3. What Is Type Aliasing and How Do I Use It?
      4. 4-4. How Do I Use Inheritance in Groovy?
      5. 4-5. How Do I Use Interfaces in Groovy?
      6. 4-6. What Are Multimethods and How Do I Use Them?
      7. 4-7. What Are Categories and How Do I Use Them?
      8. 4-8. How Are Groovy Fields and Local Variables Different from Those in Java?
      9. 4-9. How Are Groovy Methods Different from Java Methods?
      10. 4-10. How Are Groovy Constructors Different from Those in Java?
      11. 4-11. What Are GroovyBeans?
      12. 4-12. What Are GPaths?
      13. 4-13. How Do I Use the Expando Class?
      14. 4-14. What Is Metaclass and How Do I Use It?
      15. 4-15. How Do I Intercept All Method Calls on an Object?
      16. 4-16. How Do I Intercept Methods That Don't Exist on a Class?
      17. 4-17. How Do I Add Additional Behavior to a Class by Using ExpandoMetaClass?
      18. Summary
    5. CHAPTER 5: Closures
      1. 5-1. What Is a Closure?
      2. 5-2. Why Do I Need Closures?
      3. 5-3. How Do Closures Compare with Anonymous Inner Classes?
      4. 5-4. How Do I Create a Closure?
      5. 5-5. How Do I Call a Closure?
      6. 5-6. How Do I Return a Value from a Closure?
      7. 5-7. How Do I Reuse a Method as a Closure?
      8. 5-8. How Do I Pass a Closure as an Argument to Another Method?
      9. 5-9. What Is the Scope of a Closure?
      10. 5-10. What Do this, owner, and delegate Mean Inside a Closure?
      11. 5-11. How Can I Return from a Closure?
      12. 5-12. What Does It Mean to Curry Closures?
      13. 5-13. How Do I Use a Closure Inside a switch Statement?
      14. 5-14. How Do I Get More Information About the Parameters Passed to a Closure?
      15. 5-15. How Do I Use Closures Inside a Map?
      16. 5-16. How Do I Use Closures with Files?
      17. Summary
    6. CHAPTER 6: Builders
      1. 6-1. What Are Builders?
      2. 6-2. Why Do I Need Builders?
      3. 6-3. How Do I Use MarkupBuilder to Build XML?
      4. 6-4. How Do I Use MarkupBuilder to Build HTML?
      5. 6-5. How Do I Use NodeBuilder to Build a Tree of Objects?
      6. 6-6. How Do I Use ObjectGraphBuilder to Build a Tree of Objects?
      7. 6-7. How Do I Use AntBuilder to Write Ant Tasks?
      8. 6-8. How Do I Use SwingBuilder to Create Swing Widgets?
      9. 6-9. How Do I Use Layout Managers with SwingBuilder?
      10. 6-10. How Do I Add an Action to a Swing Widget?
      11. 6-11. How Do I Share Actions Among Widgets?
      12. 6-12. How Do I Use Swing Models?
      13. 6-13. How Do I Create My Own Builder?
      14. Summary
    7. CHAPTER 7: Working with Databases
      1. 7-1. How Do I Connect to a Database?
      2. 7-2. How Do I Use Connection Pooling?
      3. 7-3. How Do I Create a New Table?
      4. 7-4. How Do I Insert, Update, and Delete Data?
      5. 7-5. How Do I Read Data from My Tables?
      6. 7-6. How Do I Retrieve a Table's Metadata?
      7. 7-7. How Do I Use DataSet?
      8. 7-8. How Do I Use DataSet with Joined Tables?
      9. Summary
    8. CHAPTER 8: Testing with Groovy
      1. 8-1. How Do I Write an Inline Test in Groovy?
      2. 8-2. How Do I Write a Test Class in Groovy?
      3. 8-3. How Do I Use Groovy to Test Java Code?
      4. 8-4. How Do I Organize Tests into Suites and Run Them from My IDE?
      5. 8-5. How Do I Use Ant to Run My Tests?
      6. 8-6. How Do I Use Maven to Run My Tests?
      7. 8-7. What Are the Advanced Testing Techniques Offered by Groovy?
      8. 8-8. How Do I Use Maps to Test My Code?
      9. 8-9. How Do I Use an Expando Object to Test My Code?
      10. 8-10. How Do I Use Stubs and Mocks in Groovy?
      11. 8-11. How Do I Use GroovyLogTestCase?
      12. 8-12. How Can I Measure My Code Coverage by Using Cobertura?
      13. Summary
    9. CHAPTER 9: Miscellaneous Recipes
      1. 9-1. How Do I Use Groovy Templates to Generate Dynamic and Reusable Content?
      2. 9-2. How Do I Use Groovlets to Generate Dynamic Web Content?
      3. 9-3. How Do I Read and Process XML with XmlParser?
      4. 9-4. How Do I Read and Process XML with XmlSlurper?
      5. 9-5. How Do I Use XPath?
      6. 9-6. How Do I Read an XML RSS Feed?
      7. 9-7. How Do I Use Groovy on the Command Line?
      8. 9-8. How Do I Use ConfigSlurper to Write Configuration Files?
      9. 9-9. How Do I Use Groovy to Run External Processes?
      10. 9-10. How Do I Download a File in Groovy?
      11. 9-11. How Do I Process All Files in a Directory?
      12. 9-12. How Do I Count All Occurrences of a Word in a String?
      13. Summary
  10. PART 2: Grails by Example
    1. CHAPTER 10: Getting Started with Grails
      1. 10-1. What Is Grails?
      2. 10-2. Why Another Framework?
      3. 10-3. How Do I Download and Install Grails?
      4. 10-4. How Do I Create My First Application in Grails?
      5. 10-5. How Do I Use Grails with Eclipse?
      6. 10-6. How Do I Use Grails with IntelliJ IDEA?
      7. 10-7. What Are the Different Grails Commands?
      8. Summary
    2. CHAPTER 11: The Web Layer
      1. 11-1. How Do I Create a Controller?
      2. 11-2. What Are Groovy Server Pages?
      3. 11-3. What Is the Relationship Between Controllers and GSPs?
      4. 11-4. How Can I Pass Variables from a Controller to a GSP?
      5. 11-5. How Do I Use Tags as Method Calls?
      6. 11-6. How Can I Have Multiple Actions Inside a Controller?
      7. 11-7. What Are the Available Implicit Objects Inside a Controller and a GSP?
      8. 11-8. How Can I Render a Different View for the User?
      9. 11-9. How Do I Chain Actions?
      10. 11-10. How Do I Intercept Actions in a Controller?
      11. 11-11. How Do I Bind Incoming Parameters?
      12. 11-12. How Do I Output JSON?
      13. 11-13. How Do I Render Domain Classes as XML or JSON (Marshalling)?
      14. 11-14. How Do I Upload and Download Files?
      15. 11-15. What Are Templates and How Do I Use Them?
      16. 11-16. How Do I Change the Application's Layout and Look?
      17. 11-17. How Do I Write My Own Custom Tags?
      18. 11-18. How Do I Use Filters?
      19. 11-19. How Do I Use Ajax?
      20. Summary
    3. CHAPTER 12: The Data Layer
      1. 12-1. How Do I Configure My Application to Use a Database?
      2. 12-2. How Do I Create a Domain Class?
      3. 12-3. How Do I Model Relationships?
      4. 12-4. How Do I Use Composition?
      5. 12-5. How Do I Perform CRUD Operations on My Domain Classes?
      6. 12-6. How Do I Query with GORM?
      7. 12-7. How Do I Use Dynamic Finders?
      8. 12-8. How Do I Use Criteria?
      9. 12-9. How Do I Use HQL?
      10. 12-10. How Do I Use Inheritance?
      11. 12-11. What is Optimistic and Pessimistic Locking?
      12. 12-12. How Do I Use Events?
      13. 12-13. How Do I Use Timestamps?
      14. 12-14. How Do I Use Caching?
      15. 12-15. How Do I Use a Custom Database Identifier?
      16. 12-16. How Do I Use a Composite Primary Key?
      17. 12-17. How Do I Add an Index to a Column?
      18. Summary
    4. CHAPTER 13: Scaffolding
      1. 13-1. How Do I Use Dynamic Scaffolding?
      2. 13-2. How Do I Dynamically Scaffold Relationships?
      3. 13-3. How Do I Customize the Generated Views?
      4. 13-4. What Are the Built-in Constraints in Grails?
      5. 13-5. How Do I Override Scaffolded Actions and Views?
      6. 13-6. How Do I Use Static Scaffolding?
      7. 13-7. How Do I Change the Scaffolding Templates?
      8. 13-8. How Do I Add My Own Property Editor?
      9. 13-9. How Do I Use Scaffolding with Hibernate Mapped Classes?
      10. Summary
    5. CHAPTER 14: Security
      1. 14-1. How Do I Protect My Application from SQL Injection Attacks?
      2. 14-2. How Do I Protect My Application from Cross-Site Scripting (XSS)?
      3. 14-3. How Do I Use Codecs?
      4. 14-4. How Do I Restrict the HTTP Request Methods That Can Call an Action?
      5. 14-5. How Do I Implement Authentication in My Application?
      6. 14-6. How Do I Use the AcegiSecurity Plug-In?
      7. 14-7. How Do I Use OpenID?
      8. Summary
    6. CHAPTER 15: Testing
      1. 15-1. How Do I Unit-Test My Application?
      2. 15-2. How Do I Create Integration Tests?
      3. 15-3. How Do I Test render and redirect Methods?
      4. 15-4. How Do I Test Tag Libraries?
      5. 15-5. How Do I Test Domain Classes?
      6. 15-6. How Do I Create a Functional Test with Canoo WebTest?
      7. Summary
    7. CHAPTER 16: Miscellaneous Recipes
      1. 16-1. What About the Service Layer?
      2. 16-2. How Can I Use Some of Spring's Advanced Features with Grails?
      3. 16-3. How Do I Configure My Application by Using External Files?
      4. 16-4. How Do I Configure Logging in My Application?
      5. 16-5. How Do I Use Grails with Maven 2?
      6. 16-6. How Do I Use Grails with REST?
      7. 16-7. How Do I Write SOAP Web Services in Grails with CXF?
      8. Summary
  11. Index