1 16 package org.apache.myfaces.custom.checkbox; 17 18 import javax.faces.component.UIComponentBase; 19 import javax.faces.context.FacesContext; 20 import javax.faces.el.ValueBinding; 21 22 40 public class HtmlCheckbox 41 extends UIComponentBase 42 { 43 45 public static final String FOR_ATTR = "for".intern(); 46 public static final String INDEX_ATTR = "index".intern(); 47 48 49 51 public static final String COMPONENT_TYPE = "org.apache.myfaces.HtmlCheckbox"; 52 public static final String COMPONENT_FAMILY = "org.apache.myfaces.Checkbox"; 53 private static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.Checkbox"; 54 55 private String _for = null; 56 private Integer _index = null; 57 58 public HtmlCheckbox() 59 { 60 setRendererType(DEFAULT_RENDERER_TYPE); 61 } 62 63 public String getFamily() 64 { 65 return COMPONENT_FAMILY; 66 } 67 68 public void setFor(String forValue) 69 { 70 _for = forValue; 71 } 72 73 public String getFor() 74 { 75 if (_for != null) return _for; 76 ValueBinding vb = getValueBinding("for"); 77 return vb != null ? (String )vb.getValue(getFacesContext()) : null; 78 } 79 80 public void setIndex(int index) 81 { 82 _index = new Integer (index); 83 } 84 85 public int getIndex() 86 { 87 if (_index != null) return _index.intValue(); 88 ValueBinding vb = getValueBinding("index"); 89 Number v = vb != null ? (Number )vb.getValue(getFacesContext()) : null; 90 return v != null ? v.intValue() : Integer.MIN_VALUE; 91 } 92 93 94 95 public Object saveState(FacesContext context) 96 { 97 Object values[] = new Object [3]; 98 values[0] = super.saveState(context); 99 values[1] = _for; 100 values[2] = _index; 101 return ((Object ) (values)); 102 } 103 104 public void restoreState(FacesContext context, Object state) 105 { 106 Object values[] = (Object [])state; 107 super.restoreState(context, values[0]); 108 _for = (String )values[1]; 109 _index = (Integer )values[2]; 110 } 111 113 } 114 | Popular Tags |