RestoreState Plugin

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:

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.