1 16 package org.apache.myfaces.wap.renderkit.wml; 17 18 import java.util.List ; 19 import java.util.Map ; 20 21 import javax.faces.component.UIComponent; 22 import javax.faces.component.UISelectItem; 23 import javax.faces.component.UISelectItems; 24 import javax.faces.context.FacesContext; 25 import javax.faces.context.ResponseWriter; 26 import javax.faces.model.SelectItem; 27 28 import org.apache.commons.logging.Log; 29 import org.apache.commons.logging.LogFactory; 30 import org.apache.myfaces.wap.component.SelectOne; 31 import org.apache.myfaces.wap.renderkit.Attributes; 32 import org.apache.myfaces.wap.renderkit.RendererUtils; 33 import org.apache.myfaces.wap.renderkit.WmlRenderUtils; 34 import org.apache.myfaces.wap.renderkit.WmlRenderer; 35 36 44 public class SelectOneRenderer extends WmlRenderer { 45 private static Log log = LogFactory.getLog(SelectOneRenderer.class); 46 47 48 public SelectOneRenderer() { 49 super(); 50 log.debug("created object " + this.getClass().getName()); 51 } 52 53 public void encodeBegin(FacesContext context, UIComponent component) throws java.io.IOException { 54 log.debug("encodeBegin(" + component.getId() + ")"); 55 if (context == null || component == null) { 56 throw new NullPointerException (); 57 } 58 } 59 60 public void encodeChildren(FacesContext context, UIComponent component) throws java.io.IOException { 61 log.debug("encodeChildren(" + component.getId() + ")"); 62 if (context == null || component == null) { 63 throw new NullPointerException (); 64 } 65 } 66 67 public void encodeEnd(FacesContext context, UIComponent component) throws java.io.IOException { 68 log.debug("encodeEnd(" + component.getId() + ")"); 69 if (context == null || component == null) { 70 throw new NullPointerException (); 71 } 72 73 if (!component.isRendered()) return; 74 75 SelectOne comp = (SelectOne)component; 76 77 ResponseWriter writer = context.getResponseWriter(); 78 79 writer.startElement(Attributes.SELECT, component); 80 RendererUtils.writeAttribute(Attributes.ID, comp.getClientId(context), writer); 81 RendererUtils.writeAttribute(Attributes.STYLE_CLASS, comp.getStyleClass(), writer); 82 RendererUtils.writeAttribute(Attributes.XML_LANG, comp.getXmllang(), writer); 83 84 85 86 if (comp.getName() == null) { 87 log.debug("getName is null"); 88 comp.setName(comp.getClientId(context)); 89 } 90 RendererUtils.writeAttribute(Attributes.NAME, comp.getName(), writer); 91 92 RendererUtils.writeAttribute(Attributes.TABINDEX, comp.getTabindex(), writer); 93 RendererUtils.writeAttribute(Attributes.TITLE, comp.getTitle(), writer); 94 RendererUtils.writeAttribute(Attributes.VALUE, comp.getValue(), writer); 95 96 99 List child = component.getChildren(); 100 for (int i = 0; i < child.size(); i++){ 101 if (child.get(i) instanceof UISelectItem){ 102 UISelectItem item = (UISelectItem)child.get(i); 103 WmlRenderUtils.writeOption((SelectItem)item.getValue(), comp, writer); 104 } 105 if (child.get(i) instanceof UISelectItems){ 106 UISelectItems item = (UISelectItems)child.get(i); 107 WmlRenderUtils.writeOptions(item.getValue(), comp, writer); 108 } 109 } 110 111 writer.endElement(Attributes.SELECT); 112 } 113 114 public void decode(FacesContext context, UIComponent component) { 115 log.debug("decode(" + component.getId() + ")"); 116 if (component == null || context == null) throw new NullPointerException (); 117 if (!(component instanceof SelectOne)) 118 log.error("Component " + component.getClass().getName() + " is no SelectOne component, cannot be converted!"); 119 120 SelectOne comp = (SelectOne)component; 121 122 Map map = context.getExternalContext().getRequestParameterMap(); 123 124 if (map.containsKey(comp.getName())){ 126 log.debug("Parameter:" + comp.getName() + " was found in the request. Value: " + (String )map.get(comp.getName())); 127 comp.setSubmittedValue(map.get(comp.getName())); 128 } 130 } 131 132 133 public Object getConvertedValue(FacesContext context, UIComponent component, Object submittedValue) throws javax.faces.convert.ConverterException { 134 return(RendererUtils.convertToObject(context, component)); 135 } 136 } 137 138 | Popular Tags |