redirect in Grails controller

12,779

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
    }
}
Share:
12,779
SShehab
Author by

SShehab

Updated on June 27, 2022

Comments

  • SShehab
    SShehab almost 2 years

    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 ?