New issue 809 by dang...@gmail.com: SJ:DATEPICKER - Date format issue with
Firefox and Timepicker
http://code.google.com/p/struts2-jquery/issues/detail?id=809
(This is for feature requests and bugs in Struts2 jQuery Plugin - for
getting help, please use the User Group.
http://groups.google.com/group/struts2-jquery )
What steps will reproduce the problem?
1. Create a datepicker on the page with timepicker="true"
2. Have the backing action have a Date value bound to this
3. Run the action and get the below
What is the expected output? What do you see instead?
from JSP:
<sj:datepicker name="fromDate" showAnim="slideDown"
displayFormat="dd/mm/yy" timepicker="true"
onchange="dojo.event.topic.publish('refresh_info');"></sj:datepicker>
from action:
private Date fromDate;
public void setFromDate(Date fromDate) {
this.fromDate = fromDate;
}
The exception is swallowed up by struts 2 debugging and then redirects to
result INPUT but if you turn the logging up you can see:
Could not parse date - [unknown location]
at
com.opensymphony.xwork2.conversion.impl.XWorkBasicConverter.doConvertToDate(XWorkBasicConverter.java:377)
at
com.opensymphony.xwork2.conversion.impl.XWorkBasicConverter.convertValue(XWorkBasicConverter.java:115)
at
com.opensymphony.xwork2.conversion.impl.XWorkBasicConverter.convertValue(XWorkBasicConverter.java:146)
at
com.opensymphony.xwork2.conversion.impl.XWorkConverter.convertValue(XWorkConverter.java:334)
at
com.opensymphony.xwork2.ognl.OgnlTypeConverterWrapper.convertValue(OgnlTypeConverterWrapper.java:39)
at ognl.OgnlRuntime.getConvertedType(OgnlRuntime.java:1067)
at ognl.OgnlRuntime.getConvertedTypes(OgnlRuntime.java:1084)
at ognl.OgnlRuntime.getConvertedMethodAndArgs(OgnlRuntime.java:1110)
at ognl.OgnlRuntime.getAppropriateMethod(OgnlRuntime.java:1196)
at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1210)
at ognl.OgnlRuntime.setMethodValue(OgnlRuntime.java:1481)
<SNIP>
Caused by: java.text.ParseException: Unparseable date: "22/04/2012 19:57 "
at java.text.DateFormat.parse(Unknown Source)
at
com.opensymphony.xwork2.conversion.impl.XWorkBasicConverter.doConvertToDate(XWorkBasicConverter.java:367)
... 107 more
Which struts2 version?
2.3.1.1
Which struts2-jquery plugin version?
3.2.0 and 3.3.0
Please provide any additional information below.
It looks like there is a trailing space that might be causing the issue
- "21/04/2012 19:59 "
This only affects Firefox (I'm using 11.0) - have tested in Chrome and IE 9
and it works fine.
Firefox doesn't let me capture the request parameters (it's a POST) but in
IE the parameter goes across as:
fromDate=26%2F04%2F2012%2019%3A59%20&toDate=22%2F04%2F2012%2019%3A59%20&
which to my old eyes looks like it does send the trailing space.
I don't have time to setup something like Wireshark to capture the trace.
However - one difference I see in the request parameters is that IE sets
the content type to: application/x-www-form-urlencoded but Firefox uses:
application/x-www-form-urlencoded; charset=UTF-8
the difference being the character-set UTF-8.
So this is probably a locale thing....
From my struts.properties: struts.i18n.encoding=UTF-8
Hope all this helps. Please contact me if you need anything else - dangrout
at googlemail.com
More info:
So - removing 'displayFormat="dd/mm/yy' makes it work in FF but breaks it
for IE and Chrome!
<sj:head locale="en" jqueryui="true" jquerytheme="smoothness" />
Appologies for brain dumping:
Notice this as well in the FF headers - looks like the source (the trailing
space was a red-herring):
Accept-Language: en-us,en;q=0.5
From IE:
Accept-Language: en-gb
I don't believe this is a bug for your project - but more an interesting
observation about different browsers and the interaction with struts 2.
The fix is going to be changing the date conversion strategy for my
application. I don't want to hard code a locale but it is an interesting
point as to what happens if I have my app in one place but users in
another....
I think I'll be looking to use Joda time to sort this out.
Anyway - sorry for the ticket but hopefully this detail might help-out
someone else.