简体   繁体   中英

how to set value in Config.groovy and get different value for same parameter according to environment on gsp in Grails?

I have a situation. I want to set one value to some parameter in Config.groovy in my Grails project. This parameter should have different value for each environment, ie for dev environment it is like abc = "devValue", for test environment like abc="testValue" and for production environment like abc="prodValue". and then I want to set that value as a hidden field value on gsp page according to running environment.

There's already an example of this in the Config.groovy that's generated for you:

environments {
   development {
      grails.logging.jul.usebridge = true
   }
   production {
      grails.logging.jul.usebridge = false
   }
}

so you can just add your setting there:

environments {
   development {
      grails.logging.jul.usebridge = true
      abc = "devValue"
   }
   test {
      abc = "testValue"
   }
   production {
      grails.logging.jul.usebridge = false
      abc = "prodValue"
   }
}

Thanks Igor Artamonov,

I found the solution below.

I added code below in Config.groovy

environments {
development {
          abc="devValue"
}

test {
          abc="testValue"
}

production {
          abc="prodValue"
 }
}

And then in gsp i set the hidden field as below.

<input id="oid" type="hidden" name="oid" value="${grailsApplication.config.abc}">

Thank you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM