views:

27

answers:

1

I wonder how can I pass a Java Date object from beans --> hibernate --> Spring MVC --> dojo and back to that Date object that would be stored in the database using hibernate.

I have tried, in beans class, creating getter and setter that return/get String by parsing the value to dojo friendly format (yyyy-MM-dd). When the date from the database is null then there is no problem and everything works as expected, but when the date isn't null the webpage cannot be generated due to the error _841.getMonth() is not a method. I figured out that this is due to spring setting value of form:input ... to a String in format yyyy-MM-dd and dojo not treating it as a Date but as a String.

My code looks like:

<form:input path="tDate" />
<script type="text/javascript">
   Spring.addDecoration(new Spring.ElementDecoration({
      elementId : "tDate",
      widgetType : "dijit.form.DateTextBox",
      widgetAttrs : {promptMessage: "Enter a date",
                     required: "true"}
}));
</script>

and spring converts form:input ... to something like:

<input id="tDate" name="tDate" value="2010-07-29" />

I would greatly appreciate if you could suggest a solution to this problem. If it is possible to have getter and setter for Java Date object to get/return Date and not String, as I am doing now, it would be perfect.

Cheers

A: 

Adding:

datePattern : "yyyy-MM-dd"

to widgetAttrs solved the problem. Even though dojo DateTextBox uses this pattern as a default it has to be specified for form:input to work properly.

This solution is not perfect as in beans class I am still using getter and setter to use String for my Date object and parse the value inside these methods.

Artur