cancel
Showing results for 
Search instead for 
Did you mean: 

Date Formats

tom_cole3
Explorer
0 Kudos

I am using a SimpleType to provide a custom date format for my date fields in Web Dynpro. We now have a requirement that the dates in the portal screens be the same as the user defined date format in the backend (SU01). Is it possible to set the Representation of my Simple Type at runtime? Or is there a better method to acheive this custom date format by user settings.

BTW, I already have the code that retrieves the date format string from the backend.

Many thanks.

Accepted Solutions (0)

Answers (1)

Answers (1)

siarhei_pisarenka3
Active Contributor
0 Kudos

Hi Tom

Before I type the code you are asking I'd like to say that at runtime WebDynpro Java shall automatically apply date format according to the current logged in user's locale defined in UME. If you have double stack (Java+ABAP) with common UME the feature shall work too, because in double stack Java user settings shall be loaded from SU01.

If you do not have double stack with common UME then try the following code that can be inserted, for example, in wdDoInit() of the controller:

IWDAttributeInfo attrInfo = nodeInfo.getAttribute(dateAttrName);
ISimpleTypeModifiable dateTypeMod = attrInfo.getModifiableSimpleType();
dateTypeMod.setFormat(<yourBackendFormat>);

But keep in mind that <yourBackendFormat> shall be standard Java date format pattern. For example, 'dd/MM/yy', You can see all the format constants here: http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html

BR, Siarhei

tom_cole3
Explorer
0 Kudos

Thank you for the feedback. My experience so far has been that the user locale has had no effect on date or number display. However, the language preference set in the browser DOES have the affect of formatting the date and numbers to a locale appropriate format, albeit not necessarily exactly like the format they have specified in SU01.

The method you mention does appear to get me somewhat closer in that I can apply a format at runtime. I have the interesting effect, though, that the first time a date is selected using the calendar button, a date with the browser settings is placed in the input field. Any subsequence date selection in the same field THEN uses the proper format.

For example if my browser settings display a date in dd/MM/yyyy and I have applied a custom format of dd-MM-yyyy using the method you mention in the wdDoModify method, I get the following:

1. I click the date select button and the calendar widget appears. I pick a date of November 18th 2009. The date that is inserted in the input field is 18/11/2009.

2. In the same field I select the same date again (or another date, doesn't matter) and I get a date inserted in the format 18-11-2009.

3. Any subsequence date selections in that field have the proper format dd-MM-yyyy.

Strange Web Dynpro behaviour..

The other thing is I was hoping to somehow alter the SimpleType rather than the individual context elements as I have MANY dates in the form. This current method requires that I alter dozens of fields. If I could alter the FormattedDate simple type I made, I would only need to change one thing and the others would update.