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