i have 2 select tags as,
<td><g:select name="Year" from="${2004..2014}" optionValue="${Year}" /></td>
<td><g:select name="Month" from="${['January','February','March','April','May','Jun','July','August','September','October','November','December']}" optionValue="${month}" /></td>
Now i want in gsp it should display me the current year and month in select box of year and month instea开发者_开发技巧d of displaying first year and month in list ..
how to achieve it?..can any one answer me please.
advance thanks Laxmi
Try this
<g:set var="months" value="${new java.text.DateFormatSymbols().months}"/>
<g:set var="today" value="${new Date()}"/>
<td><g:select name="Year" from="${2004..2014}" value="${today[Calendar.YEAR]}" /></td>
<td><g:select name="Month" from="${months as List}"
value="${months[today[Calendar.MONTH]]}" /></td>
In the controller create the date:
def year = new Date().format("yyyy")
def month = new Date().format("MM")
[year:year, month:month]
Should give you the current month and year.
精彩评论