1 16 package javax.faces.convert; 17 18 import javax.faces.component.UIComponent; 19 import javax.faces.context.FacesContext; 20 21 33 public class CharacterConverter 34 implements Converter 35 { 36 public static final String CONVERTER_ID = "javax.faces.Character"; 38 39 public CharacterConverter() 41 { 42 } 43 44 public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String value) 46 { 47 if (facesContext == null) throw new NullPointerException ("facesContext"); 48 if (uiComponent == null) throw new NullPointerException ("uiComponent"); 49 50 if (value != null) 51 { 52 value = value.trim(); 53 if (value.length() > 0) 54 { 55 return new Character (value.charAt(0)); 56 } 57 } 58 return null; 59 } 60 61 public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object value) 62 { 63 if (facesContext == null) throw new NullPointerException ("facesContext"); 64 if (uiComponent == null) throw new NullPointerException ("uiComponent"); 65 66 if (value == null) 67 { 68 return ""; 69 } 70 if (value instanceof String ) 71 { 72 return (String )value; 73 } 74 try 75 { 76 return ((Character )value).toString(); 77 } 78 catch (Exception e) 79 { 80 throw new ConverterException(e); 81 } 82 } 83 84 } 85 | Popular Tags |