SShehab
SShehab

Reputation: 1051

redirect in Grails controller

I'm new to Grails , i'm using Grails version 2.3.4 , in my application i have 2 controllers

AppUser

and

ManageLicences

, in the AppUsers there is a method named auth and below its code :

def auth()
{
    if (!params.username.empty)
    {
  redirect  (controller: "manageLicences" , action:"checkLicense")
     }
}

In the checkLicense in the ManageLicense controller i'm doing some redirects depending on some conditions

def checkLicense {
if (someCondition) {
    redirect (controller:'manageLicences' , action:'list')
        }
    else {
        redirect  (controller:'appUsers' , action:'login' )

        }
}

, the problem is that when my application reaches

 redirect  (controller: "manageLicences" , action:"checkLicense")

in the AppUsers controller , rather going to the redirect that in checkLicense , the URL in the browser will be

http://localhost:8080/MyApplication/manageLicences/checkLicense

and blank page , any advice ?

Upvotes: 4

Views: 14218

Answers (2)

Gnt.Lee
Gnt.Lee

Reputation: 11

def checkLicense {
    if (someCondition) {
        redirect (controller:'manageLicences' , action:'list')
        return
    } else {
        redirect  (controller:'appUsers' , action:'login' )
        return
    }
}

Upvotes: 0

Tomasz Janek
Tomasz Janek

Reputation: 1183

Check that you're not doing redirect from a namespaced controller to a controller that is not in a namespace.

According to Grails Documentation:

Redirects the current action to another action, optionally passing parameters and/or errors. When issuing a redirect from a namespaced controller, the namespace for the target controller is implied to be that of the controller initiating the redirect. To issue a redirect from a namespaced controller to a controller that is not in a namespace, the namespace must be explicitly specified with a value of null as shown below.

class SomeController {
    static namespace = 'someNamespace'
    def index() {
        // issue a redirect to PersonController which does not define a namespace
        redirect action: 'list', controller: 'person', namespace: null
    }
}

Upvotes: 4

Related Questions