concept timeline in category grails

appears as: timeline, A timeline, timeline, timelines
Grails in Action, Second Edition

This is an excerpt from Manning's book Grails in Action, Second Edition.

Imagine that you want to display a timeline of a user’s recent posts. You’d need to implement a controller action (perhaps timeline in the Post controller) to retrieve the posts for a user, then pass them to a view (/views/post/timeline.gsp) to display them in the browser. As you discovered in chapter 1, Grails exposes controller actions as URLs using conventions. Here’s how Grails translates controller action names into URLs:

When the user points the browser at http://localhost:8080/hubbub/post/timeline/chuck_norris, Grails will fire the timeline action on the Post controller, passing chuck_norris as the id. Typically, that action will retrieve data from the database and pass it to the view to display. Under Grails conventions, the view name matches the action name (but with a .gsp extension), so the timeline action will retrieve the data and pass it to /views/post/timeline.gsp to be rendered. Figure 6.1 demonstrates this flow.

Figure 6.1. From URL to controller to view

You saw this flow in action in chapter 1 and in the search form examples in chapter 4. Let’s apply our knowledge of controllers to add a timeline to Hubbub.

If your controller has only one action on it, that will be interpreted as the default action. In listing 6.5, if timeline were the only action in the controller, you could have omitted the index action and the controller would handle requests for /hubbub/post.

6.2. Implementing a timeline for Hubbub

A timeline for a user should display a list of posts for the user mixed with posts by everyone they follow. But let’s start small and implement the capability to display all the posts for one user.

Listing 9.12. Submitting a new post
... def "Submitting a new post"() { given: "I log in and start at my timeline page" login "frankie", "testing" to TimelinePage, "phil" when: "I enter a new message and post it" newPostContent.value("This is a test post from Geb") submitPostButton.click() then: "I see the new post in the timeline" waitFor { !posts("This is a test post from Geb").empty } } private login(String username, String password) { to LoginPage loginIdField = username passwordField = password signInButton.click() } ...