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