cancel
Showing results for 
Search instead for 
Did you mean: 

Date in InputField/TextView

Former Member
0 Kudos

Hi all,

I was wondering if anyone knows how a date value gets formatted to a string before it's displayed in an InputField or TextView. I believe the conversion uses the current session locale you can obtain by calling WDResourceHandler.getCurrentSessionLocale(). However, using DateFormat.getDateInstance and passing it the locale and any of the predefined styles does not produce the same results. Even using WDResourceHandler.formatDate yields different results. I'm in Australia and for this locale I get dates displayed in format d/MM/yyyy and if I switch to US locale, I get dates in format M/d/yyyy. Is there any means to obtain the pattern and/or SimpleDateFormat (if they use one) they use in Web Dynpro internally. I need this to be able to display dates consistently.

Thanks,

Martin

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi guys,

Thanks for your answers. Not sure we understood each other completely. What I meant was this. I know how to format a date value to my desired pattern. The problem is, I don't know what my desired pattern is. I'm trying to write an application that should be internationalized. For the start, it should work both with Australian and US customers. So there's different date formats involved. When I bind a date attribute to a textview element Web Dynpro formats it for me automatically. If the language setting in the browser are US, it formats it using this pattern (as specified by SimpleDateFormat) "M/d/yyyy". If I switch to en_AU, then it uses format "d/MM/yyyy". Now these patterns don't seem to be the default ones that you can get by calling java.text.DateFormat.getDateInstance(). I was wondering if there is any way to retrieve the date format pattern that Web Dynpro is using by default (and that is locale specific) so that I can use it elsewhere.

Thanks,

Martin

former_member485701
Active Participant
0 Kudos

Hi Martin,

I got your problem, you want to internationalize your date

Locale locale;

java.util.Date date;

You are already getting the above two variables: then use the following method to obtain the result.

DateFormat.getDateInstance(DateFormat.SHORT, locale).format(date);

I hope this will solve your problem.

Regards,

Praveen

Former Member
0 Kudos

Hi Praveen,

Thanks for your reply. I've tried that and that's what I was getting at, that DateFormat.getDateInstance(style, locale).format(date) does not yield the same results as binding a date to a textview in Web Dynpro. If I use style DateFormat.SHORT I get only the last 2 digits for the year, i.e. m/d/yy rather than m/d/yyyy in the textview. If I use DateFormat.MEDIUM I get a completely different pattern for the US locale, something like Oct 23, 2007. Anyway, I guess the SHORT format is the closest I can get. I was just wondering whether there's any way to get to the actual format pattern they use in Web Dynpro when formatting dates.

Thanks,

Martin

Former Member
0 Kudos

Hi,

For this,

Create a Simple Type(goto Your WD projec->Dictionaries->LocalDictionary->Data Types->Simple Types-> right click->create Simple type

Give built-in type as 'date'.

Goto its 'representation' tab ,in format column,give dd/MM/yyyy or whatever format you need.

Then create a context value attribute of the created Simple type .

bind this to inputfield or textview.

Then this UI element will contain date in the specified format consistently.

Thanks

Smitha

Former Member
0 Kudos

Hi,

For this,

Create a Simple Type(goto Your WD projec->Dictionaries->LocalDictionary->Data Types->Simple Types-> right click->create Simple type

Give built-in type as 'date'.

Goto its 'representation' tab ,in format column,give dd/MM/yyyy or whatever format you need.

Then create a context value attribute of the created Simple type .

bind this to inputfield or textview.

Then this UI element will contain date in the specified format consistently.

Thanks

Smitha

former_member1
Active Participant
0 Kudos

Hi Martin,

Create a simple data type of type date and give the Date format in that data type.

No create a context attribute of the same simple data type created and give the value of the text field as the attribute.

This will solve your problem.

For more clarification on how to do this revert.

Thanks,

Anish