Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
213 views
in Technique[技术] by (71.8m points)

java - Is it possible to configure unified format of date format for whole struts webapp?

In any case I 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...