i'm using the jQuery UI datepicker instead of the <g:datePicker>
, which is changing the selected date in a textbox. Now I want to save this neatly back into my database, and came across custom property editors. click me hard to see the topic on StackOverflow
However, adding this custom PropertyEditor didn't change anything, dates are still displayed like '2010-01-01 00:00:00.0' and if I try to save a date it crashes with Cannot cast object '05.05.2010' with class 'java.lang.String' to class 'java.util.Date'
.
Is there any additional magic needed, like a special naming of the textbox or something like that?
There shouldn't be that much magic.
resources.groovy
src/groovy/{yourpackage}/CustomPropertyEditorRegistrar.groovy
You many need to check the GrailsBinder code. However I have a possibly simpler solution. Below is some JQuery Code which finds all the g:datePicker code and renders a Grails Date Picker. It hides the original Select Boxes (so this code will degrade gracefully) then insert a new Textbox and the JQuery UI Datepicker. This solution also works when the user changes just the Text box without dropping down the date picker.
Finally add this code to update the inputs when the page loads and when an AJAX call is made
Hope this helps.
I have a created a simple grails custom tag to use the jQuery UI datepicker. It's characteristics are as follows:
It creates three hidden input fields dateField_day, dateField_month, dateField_year
It's responsible for populating these hidden input fields when a date has been selected from the calendar.
It's prerequisites are as follows:
The taglib code is as follows:
def jqDatePicker = {attrs, body -> def out = out def name = attrs.name def id = attrs.id ?: name
} }
The gsp code is as follows:
You can find the full article at: My Blog