Stripes

Access to DateFormatter's formatPattern

Details

  • Type: Improvement Improvement
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: Release 1.5
  • Fix Version/s: Release 1.5
  • Component/s: None
  • Labels:
    None

Description

DateFormatter's formatPattern should be protected (or maybe a getter-method?). I want to extend DateFormatter to set the default format to "medium" (right now, init() defaults formatPattern to "short"), so I would like to do something like this:

public class GermanDateFormatter extends DateFormatter {
@Override
public void init() {
if (formatPattern == null) { formatPattern = "medium"; }
super.init();
}
}

Or is there any better way to provide a formatPattern to the UrlBuilder#format() method?

Activity

Hide
Frederic Daoud added a comment - 07/Feb/08 8:55 AM

The setFormatPattern(String) method always gets called before init(), even if the format pattern is null.
So you can override the default format pattern by intercepting the call to setFormatPattern:

public class GermanDateFormatter extends DateFormatter {
@Override
public void setFormatPattern(String formatPattern) { super.setFormatPattern(formatPattern == null ? "medium" : formatPattern); }
}

Show
Frederic Daoud added a comment - 07/Feb/08 8:55 AM The setFormatPattern(String) method always gets called before init(), even if the format pattern is null. So you can override the default format pattern by intercepting the call to setFormatPattern: public class GermanDateFormatter extends DateFormatter { @Override public void setFormatPattern(String formatPattern) { super.setFormatPattern(formatPattern == null ? "medium" : formatPattern); } }
Hide
Sebastian Beigel added a comment - 07/Feb/08 9:05 AM

Thank you – great idea! This solves my problem...

I still wonder if DateFormatter's formatPattern should have a getter, though I think it wouldn't harm but could make it a little bit more flexible as (these) TypeConverters and Formatters are prominent candidates for inheritance.

Show
Sebastian Beigel added a comment - 07/Feb/08 9:05 AM Thank you – great idea! This solves my problem... I still wonder if DateFormatter's formatPattern should have a getter, though I think it wouldn't harm but could make it a little bit more flexible as (these) TypeConverters and Formatters are prominent candidates for inheritance.
Hide
Frederic Daoud added a comment - 07/Feb/08 9:16 AM

I agree, but ideally the getter would be on the Formatter interface, for the formatPattern as well as other properties.
Ben pointed out that the problem with doing that is that it would break all existing Formatters that people have written for their applications.
This non-backwards compatible change shouldn't be done at the time that the beta has just been released.
Something to think about for a later version, perhaps.

Show
Frederic Daoud added a comment - 07/Feb/08 9:16 AM I agree, but ideally the getter would be on the Formatter interface, for the formatPattern as well as other properties. Ben pointed out that the problem with doing that is that it would break all existing Formatters that people have written for their applications. This non-backwards compatible change shouldn't be done at the time that the beta has just been released. Something to think about for a later version, perhaps.
Hide
Ben Gunter added a comment - 08/Feb/08 9:00 AM

On the other hand, I see no reason why we can't just add it to DateFormatter without modifying the Formatter interface. I've added getters for formatType, formatPattern, and locale to make life easier for those who wish to subclass DateFormatter.

Show
Ben Gunter added a comment - 08/Feb/08 9:00 AM On the other hand, I see no reason why we can't just add it to DateFormatter without modifying the Formatter interface. I've added getters for formatType, formatPattern, and locale to make life easier for those who wish to subclass DateFormatter.
Hide
Frederic Daoud added a comment - 08/Feb/08 9:16 AM

Same for NumberFormatter.

Show
Frederic Daoud added a comment - 08/Feb/08 9:16 AM Same for NumberFormatter.

People

Vote (0)
Watch (0)

Dates

  • Created:
    07/Feb/08 5:30 AM
    Updated:
    04/Jan/11 2:49 PM
    Resolved:
    08/Feb/08 9:00 AM