Uploaded image for project: 'Stripes'
  1. STS-958

Wiki on how to add Converter and Formatter classes is wrong

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: Release 1.5.8, Release 1.6
    • Fix Version/s: None
    • Component/s: Documentation
    • Labels:
      None
    • Sprint:

      Description

      The Wiki says to add Type Converter and Formatter classes one adds the following to web.xml:

      <init-param>
      <param-name>Extension.Packages</param-name>
      <param-value>
      path.to.LocalDateTimeConverter,
      path.to.LocalDateTimeFormatter,
      </param-value>
      </init-param>

      This never worked (as far back as 1.4). The correct way is to do the following:
      (1) in web.xml

      <init-param>
      <param-name>TypeConverterFactory.Class</param-name>
      <param-value>path.to.TypeConverterFactory</param-value>
      </init-param>
      <init-param>
      <param-name>FormatterFactory.Class</param-name>
      <param-value>path.to.FormatterFactory</param-value>
      </init-param>

      (2)
      public class TypeConverterFactory extends DefaultTypeConverterFactory
      {
      public TypeConverterFactory()

      { super(); }

      public void init(Configuration configuration)

      { super.add(LocalDateTime.class, LocalDateTimeTypeConverter.class); }

      }

      3)
      public class FormatterFactory extends DefaultFormatterFactory {
      public Formatter<?> getFormatter(Class<?> clazz, Locale locale, String formatType, String formatPattern)

      { if (clazz == LocalDateTime.class) return new LocalDateTimeFormatter(); else return super.getFormatter(clazz, locale, formatType, formatPattern); }

      public void init(Configuration configuration) { }
      }

      4)
      public class LocalDateTimeTypeConverter implements TypeConverter<LocalDateTime>
      {
      @Override
      public LocalDateTime convert(String input, Class<? extends LocalDateTime> type,
      Collection<ValidationError> errors)

      { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); return LocalDateTime.parse(input, formatter); }

      @Override
      public void setLocale(Locale arg0) {}
      }

      5)
      public class LocalDateTimeFormatter implements Formatter<LocalDateTime> {
      public String format(LocalDateTime date)

      { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); return date.format(formatter); }

      public void init() { }

      public void setFormatPattern(String pattern) { }

      public void setFormatType(String arg0) { }

      public void setLocale(Locale arg0) { }
      }

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              cnyee CN Yee
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: