package com.nanometer.smartlab.converter; import com.nanometer.smartlab.entity.enumtype.SeeFlag; import org.apache.commons.lang.StringUtils; import javax.faces.component.UIComponent; import javax.faces.context.FacesContext; import javax.faces.convert.Converter; import javax.faces.convert.FacesConverter; /** * Created by maweiqing on 15-5-18. */ @FacesConverter("seeFlagConvert") public class SeeFlagConvert implements Converter { public Object getAsObject(FacesContext context, UIComponent component, String value) { try { if (StringUtils.isNotBlank(value)) { return SeeFlag.parse(Integer.parseInt(value)); } return null; } catch (Exception e) { return null; } } public String getAsString(FacesContext context, UIComponent component, Object value) { try { if (value != null && value instanceof SeeFlag) { SeeFlag seeFlag = (SeeFlag) value; return String.valueOf(seeFlag.getKey()); } return null; } catch (Exception e) { return null; } } }