Chapter 5. Controlling application flow

 

This chapter covers

  • How controllers, models, and views interact
  • Implementing custom URLs and permalinks
  • Writing filter code to reroute requests
  • Using services for more maintainable architecture
  • Data binding and error handling
  • Using Command objects for tricky form validations
  • Uploading and rendering images

In chapters 3 and 4, we spent plenty of time looking at how Grails handles domain objects. Along the way, we’ve used controllers and implemented a few GSP views to host our forms, but we’ve largely ignored how controllers work. It’s time to set that right.

In this chapter, we’ll focus on controllers. We’ll learn more advanced binding techniques for passing variables between forms and controllers, get some insight into how redirects work, implement file uploads, open the lid on filters, and even render custom content types. Along the way, we’ll beef up Hubbub to handle uploading and display profile photos, and we’ll implement the core business of creating Users and Posts. By the end of the chapter, you’ll be ready to implement the common controller use cases in your own applications, and quite a few of the edge cases.

We’ll get the chapter underway by pulling together all you’ve learned so far about controllers, forms, and domain classes. We’ll modify Hubbub to add and display user posts on a Twitter-style timeline.

5.1. Controller essentials

5.2. Services: making things robust and maintainable

5.3. Data binding

5.4. Command objects

5.5. Working with images

5.6. Intercepting requests with filters

5.7. Creating custom URL mappings

5.8. Summary and best practices

sitemap