All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.databasesandlife.util.wicket.YearMonthDayConverter Maven / Gradle / Ivy

There is a newer version: 21.0.1
Show newest version
package com.databasesandlife.util.wicket;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Locale;

import org.apache.wicket.util.convert.ConversionException;
import org.apache.wicket.util.convert.IConverter;

import com.databasesandlife.util.*;

/**
 * Allows Wicket fields to have models of type {@link YearMonthDay}.
 *    

* In HTML, use <input type="date">. In Wicket, add the following to the application class: *

 * protected IConverterLocator newConverterLocator() {
 *   ConverterLocator locator = 
 *     (ConverterLocator) super.newConverterLocator();
 *   locator.set(YearMonthDay.class, new YearMonthDayConverter());
 *   return locator;
 * }
 * 
* * @deprecated use {@link DateTextField} instead * @author This source is copyright Adrian Smith and licensed under the LGPL 3. * @see Project on GitHub */ @Deprecated @SuppressWarnings("serial") public class YearMonthDayConverter implements IConverter{ private final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); private SimpleDateFormat userFormat; public YearMonthDayConverter() { userFormat = format; } public YearMonthDayConverter(SimpleDateFormat format) { userFormat = format; } @Override public YearMonthDay convertToObject(String arg0, Locale arg1) { if(arg0 == null) return null; try { return YearMonthDay.newForYYYYMMDD(format.format(userFormat.parse(arg0))); } catch (ParseException e) { throw new ConversionException(e).setResourceKey("invalid"); } } @Override public String convertToString(YearMonthDay arg0, Locale arg1) { if(arg0 == null) return null; try { return userFormat.format(format.parse(arg0.toYYYYMMDD())); } catch (ParseException e) { throw new ConversionException(e).setResourceKey("invalid"); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy