title: Grails - jQuery datepicker error when editing
body: <p>I had my jQuery datepicker working and saving the date the way it should several days ago. But now I have an error when I'm trying to edit an entry. I think it has to do with the way Grails import the date from DB to form. Please pinpoint me to the right direction. 
  I've used a custom taglib. </p>
  
  <pre><code>import org.springframework.web.servlet.support.RequestContextUtils as RCU
  
  /**
   * 
   * A datepicker based on JQuery datepicker (http://jqueryui.com/datepicker/) and (mostly) compatible with the Grails framework
   * 
   * Version 0.1 - 27/02/2014
   * 
   * Supported attributes:
   *  - name      : will be used as name and if for the actual input field
   *  - value     : default value
   *  - option    : options to pass to datepicker {key1: value1, key2: value2, ...}. See API: http://api.jqueryui.com/datepicker/
   *  - locale    : locale to be used. If not passed, it will take the grails session's locale (first two letters). jquery.datepicker's locale files should be available to your app: https://github.com/jquery/jquery-ui/tree/master/ui/i18n
   *  - class     : HTML classes to apply to the visible field
   *  - required  : HTML required attribute
   * 
   * Setup:
   *  - make sure JQuery-UI and JQuery are installed
   *  - put this class in your grails-app/tablib folder
   * 
   * Example: 
   *  &lt;g:datepickerUI name="myDate" required="true" value="${myDomainClass?.myDate?:new Date()}" options="{minDate:'0', maxDate:'+10Y'}" class="form-control"/&gt;
   * 
   * 
   * Tested with:
   *  - JQuery-1.11.1
   *  - JQueryUI-1.11.3 
   *  - Grails 2.4.4
   */
  
  
  //Renders the content from DB to GSP preserving newlines
  class JQueryUITagLib {
      def datepickerUI = { attrs -&gt;
          def name = attrs['name']?:'myDateField'
          def value = attrs['value']
          def options = attrs['options']?:'{}' //{key1: value1, key2: value2, ...}
          def locale = attrs['locale']?:RCU.getLocale(request).toString().substring(0,2)
          def htmlClass = attrs['class']
          def htmlRequired = attrs['required']?"required = 'true'":''
          def placeholder = attrs['placeholder']?:''
  
          def namePicker = name+"_picker";
          def nameDay = name+"_day";
          def nameMonth = name+"_month";
          def nameYear = name+"_year";
  
          def c = null
          def day;
          def month;
          def year;
          if(value!=null){
              if(value instanceof Calendar) {
                  c = value
              } else {
                  c = new GregorianCalendar();
                  c.setTime(value)
              }
              day = c.get(GregorianCalendar.DAY_OF_MONTH)
              month = c.get(GregorianCalendar.MONTH)+1
              year = c.get(GregorianCalendar.YEAR)
          }
  
          out &lt;&lt; "\
          &lt;input type='text' id='${namePicker}' name='${namePicker}' placeholder='${placeholder}' class='${htmlClass}' ${htmlRequired} style='position: relative; z-index:100;'/&gt;\
          \
          \
          &lt;input type='hidden' id='${name}' name='${name}' value='date.struct' /&gt;\
          \
          &lt;input type='hidden' id='${nameDay}' name='${nameDay}' value='${day}' /&gt;\
          &lt;input type='hidden' id='${nameMonth}' name='${nameMonth}' value='${month}' /&gt;\
          &lt;input type='hidden' id='${nameYear}' name='${nameYear}' value='${year}' /&gt;\
          "
  
          out &lt;&lt; "\
           &lt;script type='text/javascript'&gt;\
           \$(document).ready(function(){\n\
               \$('#${namePicker}').datepicker(${options});\n\
               \$('#${namePicker}').datepicker('option',\$.datepicker.regional['${locale}']);\n\
               \$('#${namePicker}').on('change', function(){\n\
                   selDate = \$('#${namePicker}').datepicker('getDate');\n\
                   \$('#${nameDay}').val(selDate?selDate.getDate():null);\n\
                   \$('#${nameMonth}').val(selDate?selDate.getMonth()+1:null);\n\
                   \$('#${nameYear}').val(selDate?selDate.getFullYear():null);\n\
               });\n\
               var dateFormat = \$('#${namePicker}').datepicker( 'option', 'dateFormat');\n\
           "
          // If a value is specified it overrides the default date
          if(attrs['value']){
              out &lt;&lt; "\
                   //Set date from value\n\
                   \$('#${namePicker}').datepicker('option', 'defaultDate',new Date(${year},${month-1},${day}));\n\
                   "
          }
          out &lt;&lt; "\
               var defaultDate = \$('#${namePicker}').datepicker( 'option', 'defaultDate');\n\
               //Set default date\n\
               \$('#${namePicker}').val(\$.datepicker.formatDate(dateFormat, defaultDate))\n\
           });\n\
           &lt;/script&gt;\
           \
           "
      }
  }
  </code></pre>
  
  <p>And this is the error I get.</p>
  
  <pre><code>Class
  groovy.lang.MissingMethodException
  Message
  No signature of method: java.util.GregorianCalendar.setTime() is applicable for argument types: (java.lang.String) values: [02-Mar-2006] Possible solutions: setTime(java.util.Date), getTime(), clearTime(), setTimeZone(java.util.TimeZone), setTimeZone(java.util.TimeZone), getAt(java.lang.String
  </code></pre>
  
  <p>)</p>