Public feed #893292

Mine

public text v1 · immutable
Raw Edit
·published 2008-02-06 00:55 UTC
rendered paste body
public class CountryConverter implements Converter, Serializable {

    Map<String, Country> map;

    public CountryConverter(List<Country> list) {
        map = new HashMap<String, Country>();
        for (Country c : list) {
            map.put(c.getIso(), c);
        }
    }

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

    public String getAsString(FacesContext context, UIComponent component, Object value) {

        if (value instanceof Country) {
            return ((Country) value).getIso();
        } else {
            return null;
        }
    }
}