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

org.skyway.spring.util.jsf.ConverterForCalendar Maven / Gradle / Ivy

The newest version!
package org.skyway.spring.util.jsf;

import java.util.Calendar;
import java.util.Locale;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

import org.skyway.spring.util.databinding.CalendarConverter;
import org.skyway.spring.util.databinding.TypeConversionUtils;

/**
 * Base class for a converter that handles java.util.Calendar fields.
 * Subclasses provide the pattern and optionally the locale.
 * 
 * @author jperkins
 *
 */
public class ConverterForCalendar implements Converter{
	private CalendarConverter converter;
	
	public ConverterForCalendar(String pattern){
		this(pattern, TypeConversionUtils.getLocale());
	}
	
	public ConverterForCalendar(String pattern, Locale locale){
		this.converter = new CalendarConverter(pattern, locale);
	}
	
	protected CalendarConverter getCalendarConverter(){
		return converter;
	}

	public Object getAsObject(FacesContext context, UIComponent component, String value) {
		return converter.getCalendarFromText(value);
	}

	public String getAsString(FacesContext context, UIComponent component, Object value) {
		return converter.getTextFromCalendar((Calendar)value);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy