2

I am using Struts2 with ModelDriven for form submitting.

When I use datetimepicker tag of Dojo and select date from that tag the form is submitted correctly with the form values populated in the ModelDriven object.

But when datepicker tag of jQuery is taken in the form and date is selected the object in ModelDriven have null values.

If date is not selected and form is submitted then it work fine.

Is there any setting required that I missed to resolve the issue ?

I had included following jar for JQuery.

JQuery:

<sx:datepicker name="startDate" id="startDate" label="" cssStyle="width:275px; " 
minDate="0" displayFormat="dd/mm/y" changeMonth="true" changeYear="true" 
readonly="true" value="%{startDate}"/>
Roman C
  • 49,761
  • 33
  • 66
  • 176
Kidaaaa
  • 91
  • 1
  • 5

4 Answers4

1

remove readonly="true" and everything will work fine.

readonly attribute default to false tells that whether the input is read-only.

Roman C
  • 49,761
  • 33
  • 66
  • 176
0

I'm pretty sure that

name="startDate"

should be changed to

name="yourmodel.startDate"

Show more code for a better help...

Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
0

Struts expects a value to be sent to the server as a locale-independent value, conforming to RFC3 339 (yyyy-MM-dd'T'HH:mm:ss) this is what the default dojo tag (now deprecated) provides: http://struts.apache.org/2.0.12/docs/datetimepicker.html

You can just send: 2013-01-03 the rest is optional.

The jQuery Datepicker I uses mm/dd/yy. To change this format to what struts2 expects either change the defaultFormat used for presentation or set altFormat which changes what was input into the format presented during submission (So if you like "mm/dd/yy" you can just set altFormat to "yyyy-mm-dd" and get the desired effect).

http://jqueryui.com/datepicker/#date-formats

http://api.jqueryui.com/datepicker/

As you can see jQuery easily provides for this, how to do it with the tag... I don't know. Someone else is welcome to take this information and extend it in another answer, with a tag specific technique if possible.

Community
  • 1
  • 1
Quaternion
  • 10,380
  • 6
  • 51
  • 102
0

Problem was Dojo takes the date value on JSP as Date in java whereas JQuery takes it as string.

And so struts was finding for setDate(String) and not setDate(Date) for JQuery.

lmcanavals
  • 2,339
  • 1
  • 24
  • 35
Kidaaaa
  • 91
  • 1
  • 5
  • Issue is during submission and all request parameters arrive as String. Struts2 looks at the property name and checks the property type and then will attempt to apply a known conversion (struts2 parameters interceptor), if there is not one the value will not be settable. Simply it can not account for every date format (and it only accounts for one afaik, without a custom conversion that is). – Quaternion Jan 03 '13 at 23:07