I have an application developed in Grails 2.0.4, I am hard coding some of the values in my domain classes, example as follows
class Training{
String startTime ="09:00"
String endTime ="17:00"
}
But Its not good approach, Making changes is overhead, Like this I have got more than 10 domain classes where the values are hard coded.
So, I am planning to create a separate configuration Domain class, thereby I can input the values through the UI (view) and persist them.
This is my plan, Is there any solution in grails to deal with it.
UPDATED:
import org.grails.plugins.settings.*
class PublicTraining extends Training{
Date startDate = Setting.valueFor("startDate")
}
I have created a setting ‘startDate’. I am able to access setting using Setting.valueFor(“startDate”) method in controllers but not in domain classes
The error I am getting is below
*Caused by: org.hibernate.InstantiationException: could not instantiate test objectcom.springpeople.tms.PublicTraining
... 5 more
*Caused by: java.lang.reflect.InvocationTargetException
... 5 more
Caused by: groovy.lang.MissingMethodException: No signature of method: org.grails.plugins.settings.Setting.methodMissing() is applicable for argument types: () values: []
at org.grails.plugins.settings.Setting.valueFor(Setting.groovy:53)**
Check out the Settings plugin. I use it in almost every project. Allows you to create any number of these type of config settings and access them in GSP’s or Contollers/Services/etc. It even provides a CRUD gui to manage them.
To use it in domain classes I’ve always used the
beforeInsertorbeforeUpdateevents.Handles settings of types String, Integer, BigDecimal or Date.
If you had multiple values that are similar(like “Training start time” and “Inventory start time”) you needed to store you can segment them as
inventory.startTimeandtraining.startTimeas well.