1 16 package org.apache.myfaces.renderkit.html; 17 18 import org.apache.myfaces.renderkit.JSFAttr; 19 import org.apache.myfaces.renderkit.RendererUtils; 20 21 import javax.faces.component.UIComponent; 22 import javax.faces.component.UISelectMany; 23 import javax.faces.component.UISelectOne; 24 import javax.faces.component.html.HtmlSelectManyListbox; 25 import javax.faces.component.html.HtmlSelectOneListbox; 26 import javax.faces.context.FacesContext; 27 import javax.faces.convert.ConverterException; 28 import java.io.IOException ; 29 30 31 52 public class HtmlListboxRendererBase 53 extends HtmlRenderer 54 { 55 public void encodeEnd(FacesContext facesContext, UIComponent uiComponent) 56 throws IOException 57 { 58 RendererUtils.checkParamValidity(facesContext, uiComponent, null); 59 60 if (uiComponent instanceof UISelectMany) 61 { 62 int size; 63 if (uiComponent instanceof HtmlSelectManyListbox) 64 { 65 size = ((HtmlSelectManyListbox)uiComponent).getSize(); 66 } 67 else 68 { 69 Integer i = (Integer )uiComponent.getAttributes().get(JSFAttr.SIZE_ATTR); 70 size = i != null ? i.intValue() : 0; 71 } 72 HtmlRendererUtils.renderListbox(facesContext, 73 (UISelectMany)uiComponent, 74 isDisabled(facesContext, uiComponent), 75 size); 76 } 77 else if (uiComponent instanceof HtmlSelectOneListbox) 78 { 79 int size; 80 if (uiComponent instanceof HtmlSelectOneListbox) 81 { 82 size = ((HtmlSelectOneListbox)uiComponent).getSize(); 83 } 84 else 85 { 86 Integer i = (Integer )uiComponent.getAttributes().get(JSFAttr.SIZE_ATTR); 87 size = i != null ? i.intValue() : 0; 88 } 89 HtmlRendererUtils.renderListbox(facesContext, 90 (UISelectOne)uiComponent, 91 isDisabled(facesContext, uiComponent), 92 size); 93 } 94 else 95 { 96 throw new IllegalArgumentException ("Unsupported component class " + uiComponent.getClass().getName()); 97 } 98 } 99 100 101 protected boolean isDisabled(FacesContext facesContext, UIComponent uiComponent) 102 { 103 if (uiComponent instanceof HtmlSelectManyListbox) 105 { 106 return ((HtmlSelectManyListbox)uiComponent).isDisabled(); 107 } 108 else if (uiComponent instanceof HtmlSelectOneListbox) 109 { 110 return ((HtmlSelectOneListbox)uiComponent).isDisabled(); 111 } 112 else 113 { 114 return RendererUtils.getBooleanAttribute(uiComponent, HTML.DISABLED_ATTR, false); 115 } 116 } 117 118 119 public void decode(FacesContext facesContext, UIComponent uiComponent) 120 { 121 RendererUtils.checkParamValidity(facesContext, uiComponent, null); 122 123 if (uiComponent instanceof UISelectMany) 124 { 125 HtmlRendererUtils.decodeUISelectMany(facesContext, uiComponent); 126 } 127 else if (uiComponent instanceof UISelectOne) 128 { 129 HtmlRendererUtils.decodeUISelectOne(facesContext, uiComponent); 130 } 131 else 132 { 133 throw new IllegalArgumentException ("Unsupported component class " + uiComponent.getClass().getName()); 134 } 135 } 136 137 public Object getConvertedValue(FacesContext facesContext, UIComponent uiComponent, Object submittedValue) throws ConverterException 138 { 139 RendererUtils.checkParamValidity(facesContext, uiComponent, null); 140 141 if (uiComponent instanceof UISelectMany) 142 { 143 return RendererUtils.getConvertedUISelectManyValue(facesContext, 144 (UISelectMany)uiComponent, 145 submittedValue); 146 } 147 else if (uiComponent instanceof UISelectOne) 148 { 149 return RendererUtils.getConvertedUIOutputValue(facesContext, 150 (UISelectOne)uiComponent, 151 submittedValue); 152 } 153 else 154 { 155 throw new IllegalArgumentException ("Unsupported component class " + uiComponent.getClass().getName()); 156 } 157 } 158 159 } 160 | Popular Tags |