I am creating a domain class named HOLIDAY in grails.I need to have a year dropdown in my Holiday year field. Hear is my domain:-
class Holiday extends CategoryMaster {
String holidayName
Date startDate
int year
Date dateCreated
static constraints = {
holidayName(blank:false, nullable:false)
}
}
I need to a year dropdown in year field, Should it come dynamically from a domain method that will discard the month & day and reflect only year in that dropdown adding +50 -50 to that?... How can I get it?
Assuming you have an instance of Holiday named holiday in scope, you can create the dropdown using something like:
<g:select name="year" from="${holiday.year - 50..holiday.year + 50}"
value="${holiday.year}"/>
This will set the current value of the dropdown to holiday.year and offer a range 50 years either side of this.
As an aside, if year is the year of startDate, there is no need to store this as a separate field, as it can easily be computed via:
startDate[Calendar.YEAR]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With