Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect to the last visited page in Grails app?

I am a newbie in Grails and I am struggling with many simple issues.

For instance, I haven't managed to find a proper way to go back to the last visited page when I login/logout from a template view that is displayed on the top layout of the page.

My last attempt at solving this problem was to save the ${params.controller} and ${params.action} in the parameters sent to the logout action and redirect thereafter. Well...even this failed. Here is the gsp snippet:

<g:link controller="user" action="logout" params="[currentController: ${params.controller}, currentAction: ${params.action}]">Logout</g:link> 

This last code line throws the following exception:

ERROR errors.GrailsExceptionResolver  - Error evaluating expression [[currentController: ${params.controller}, currentAction: ${params.action}]] 

So my questions are:

1 - How can I reload the last visited page after a login/logout action ?

2 - Why do I have an exception from my code above?

Thank You

EDIT : Concerning question #2, it seems that the following code is working:

<g:link controller="user" action="logout" params="[currentController: params.controller, currentAction: params.action]">Logout</g:link> 

But I don't really understand the reason...

EDIT2 : I have also found out a solution for redirecting to the last visited page:

redirect(url: request.header('referer')) 

But unfortunately when doing this after login, the contents rendered in my page are duplicated. Any idea or any other safe solution?

like image 939
fabien7474 Avatar asked Sep 20 '09 15:09

fabien7474


People also ask

What is controller in grails?

In Grails a controller is a class with a name that ends in the convention "Controller" and lives in the grails-app/controllers directory. A controller can be created with the create-controller command: grails create-controller org.bookstore.hello. or with your favourite IDE or text editor. package org.


1 Answers

I'm using this controller-side:

    redirect(uri: request.getHeader('referer') ) 
like image 117
nclu Avatar answered Sep 19 '22 11:09

nclu