Best way to pass objects between controller actions in grails

前端 未结 3 1135
旧时难觅i
旧时难觅i 2020-12-21 10:02

I want a link to open up another view in my webapp to display information about the specified object. What is the best way to pass objects between controllers actions in gra

3条回答
  •  失恋的感觉
    2020-12-21 10:08

    (Late to the party, but...) I'm using Grails 2.4.4, which allows me to do the below:

    def usernameLogin() {
      SecurityToken securityToken = authService.loginWithUserPass(params.user, params.pass)
      chain action: 'afterLogin', model: [securityToken: securityToken]
    }
    
    def ssoLogin() {
      SecurityToken securityToken = authService.ssoLogin(params.remoteUser, params.key)
      chain action: 'afterLogin', model: [securityToken: securityToken]
    }
    
    def afterLogin() {
      SecurityToken securityToken = (SecurityToken) chainModel['securityToken']
      if (securityToken.valid) {
        forward action: 'loggedInRedirect'
      }
      else {
        forward action: 'loginFailed'
      }
    }
    
    • SecurityToken is an object that contains string and enum
    • The key is 1) using "chain action" in source action, 2) using chainModel in target action

    Hope this helps.

提交回复
热议问题