RestoreState Plugin

  • Tags: navigation, development
  • Latest: 1.1
  • Last Updated: 11 March 2009
  • Grails version: 1.1 > *
  • Authors: Marcel Overdijk
1 vote
Dependency:
compile ":restore-state:1.1"

 Documentation

Summary

Description

RestoreState Plugin

This plugin provides convenient methods to controller classes for remembering state. With the default Grails scaffolding each time you navigate away from a list page (e.g. going to the show page) the state of the list is lost when you return. This can be annoying when you paged to a certain page within the list. A typical use case for this plugin is restoring the pagination state (like offset and sorting) of list pages.

Installation

To install the restore state plugin type this command from your project's root folder:

grails install-plugin restore-state

Usage

To use the restore state plugin to restore the state of list pages change your controller as below:

def list = {
    restoreState([max: 10, offset: 0, sort: "title", order: "asc"])
    [ bookList: Book.list( params ) ]
}

That's it. Your list page now remebers it's state.

How it works

When calling the restoreList method the passed in stateParams map will be stored in both the request params and the session. The following logic is used to determine the actual values stored: (1) use params (2) or use session (3) otherwise use default value

This example will clarify it:

restoreState([max: 10])

(1) if request params object contains "max" param, store it in the session (2) if session contains "max" param, store in the request params object (3) otherwise, store the default value (in this case 10) in both the request params obect and the session.

Plugin version history

1.1 (March 11, 2008)

  • Upgrade to Grails 1.1
  • Minor improvements

1.0 (November 21, 2008)

  • Initial release