Package org.apache.wicket

Examples of org.apache.wicket.ConverterLocator


   * WICKET-3441
   */
  @Test
  public void dateToLongConverting()
  {
    ConverterLocator converterLocator = new ConverterLocator();
    final IConverter<Date> dateConverter = converterLocator.get(Date.class);
    IConverter<Long> customLongConverter = new AbstractConverter<Long>()
    {
      private static final long serialVersionUID = 1L;

      @Override
      public Long convertToObject(String value, Locale locale)
      {
        Date date = dateConverter.convertToObject(value, locale);
        return date != null ? date.getTime() : null;
      }

      @Override
      public String convertToString(Long value, Locale locale)
      {
        Date date;
        if (value != null)
        {
          date = new Date();
          date.setTime(value);
        }
        else
        {
          date = null;
        }

        return dateConverter.convertToString(date, locale);
      }

      @Override
      protected Class<Long> getTargetType()
      {
        return Long.class;
      }
    };
    converterLocator.set(Long.class, customLongConverter);
    converterLocator.set(Long.TYPE, customLongConverter);

    PropertyResolverConverter converter = new PropertyResolverConverter(converterLocator,
      Locale.ENGLISH);

    Calendar calDate = Calendar.getInstance();
View Full Code Here


    // add your configuration here
  }
 
  @Override
  protected IConverterLocator newConverterLocator() {
    ConverterLocator defaultLocator = new ConverterLocator();
   
    defaultLocator.set(Pattern.class, new RegExpPatternConverter());
   
    return defaultLocator;
  }
View Full Code Here

   * WICKET-3441
   */
  @Test
  public void dateToStringConverting()
  {
    IConverterLocator converterLocator = new ConverterLocator();
    Locale locale = Locale.GERMAN;
    PropertyResolverConverter converter = new PropertyResolverConverter(converterLocator,
      locale);

    Calendar calDate = Calendar.getInstance();
    calDate.clear();
    calDate.set(2011, Calendar.APRIL, 17);
    Date date = calDate.getTime();

    Object actual = converter.convert(date, String.class);
    String expected = converterLocator.getConverter(Date.class).convertToString(date, locale);
    assertEquals(expected, actual);
  }
View Full Code Here

   * WICKET-3441
   */
  @Test
  public void dateToLongConverting()
  {
    ConverterLocator converterLocator = new ConverterLocator();
    final IConverter<Date> dateConverter = converterLocator.get(Date.class);
    IConverter<Long> customLongConverter = new AbstractConverter<Long>()
    {
      private static final long serialVersionUID = 1L;

      public Long convertToObject(String value, Locale locale)
      {
        Date date = dateConverter.convertToObject(value, locale);
        return date != null ? date.getTime() : null;
      }

      @Override
      public String convertToString(Long value, Locale locale)
      {
        Date date;
        if (value != null)
        {
          date = new Date();
          date.setTime(value);
        }
        else
        {
          date = null;
        }

        return dateConverter.convertToString(date, locale);
      }

      @Override
      protected Class<Long> getTargetType()
      {
        return Long.class;
      }
    };
    converterLocator.set(Long.class, customLongConverter);
    converterLocator.set(Long.TYPE, customLongConverter);

    PropertyResolverConverter converter = new PropertyResolverConverter(converterLocator,
      Locale.ENGLISH);

    Calendar calDate = Calendar.getInstance();
View Full Code Here

   *
   */
  @Override
  protected IConverterLocator newConverterLocator()
  {
    final ConverterLocator converterLocator = new ConverterLocator();
    converterLocator.set(java.util.Date.class, new MyDateConverter());
    converterLocator.set(java.sql.Date.class, new MyDateConverter(java.sql.Date.class, "S-"));
    return converterLocator;
  }
View Full Code Here

  }

  @Override
  protected IConverterLocator newConverterLocator()
  {
    ConverterLocator back = new ConverterLocator();
    back.set(Date.class, new DateConverter());
    return back;
  }
View Full Code Here

TOP

Related Classes of org.apache.wicket.ConverterLocator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.