问题
In any case id get exception Could not parse date
.
There is unified company standard of date format - 'dd/MM/yyyy'
There are computers with different system locales. I am using jQueryUI for datepicker
( it is standard for widgets and already settled css styles to match application theme).
At the beginning, i didn't found better solution then manually convert date string to date object using SimpleDateFormat
object. Now i have converter class but still need to configure every Action that has java.util.Date
property.
I am using XML configuration and I did try to add into struts.xml
:
<constant name="struts.date.format" value="dd/MM/yyyy" />
It didn't work.
Is there anything that can force all web-application to use single date format without locales just a unified format for output and input date?
Or the way how i can extract date format expected by struts date type converter, so i can use js to convert date before to be sent to server to match struts expectations?
回答1:
Struts2 is designed to behave differently according to a locale requested by the client.
i18n interceptor is a member of the default interceptor stack. So, it is responsible for setting requested locale to the action context, overriding the default settings. It also stores that locale to the session for further retrieving it if the locale is not requested by the request parameter.
The action context's locale is used by the default type converter, so setting a locale to the action context should probably override the default locale setting which could be configured via struts.locale
and i18n
interceptor doesn't change this.
If so, no other actions required, just put your date format to the global resource properties according to that locale. You can also use action properties that could be used with i18n
requested locale that has different format due to the order of processing localization resources.
If you don't need that possibility of switching a locale by the user you should remove i18n
interceptor from the stack.
How to format the dates and numbers using action context's locale: Formatting Dates and Numbers.
来源:https://stackoverflow.com/questions/23077771/is-it-possible-to-configure-unified-format-of-date-format-for-whole-struts-webap