1 16 package org.apache.myfaces.wap.renderkit.wml; 17 18 import java.util.Map ; 19 20 import javax.faces.component.UIComponent; 21 import javax.faces.context.FacesContext; 22 import javax.faces.context.ResponseWriter; 23 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogFactory; 26 import org.apache.myfaces.wap.component.SelectBoolean; 27 import org.apache.myfaces.wap.renderkit.Attributes; 28 import org.apache.myfaces.wap.renderkit.RendererUtils; 29 import org.apache.myfaces.wap.renderkit.WmlRenderer; 30 31 39 public class SelectBooleanRenderer extends WmlRenderer { 40 private static Log log = LogFactory.getLog(SelectBooleanRenderer.class); 41 private static String OPTION_VALUE = "bool"; 42 43 44 public SelectBooleanRenderer() { 45 super(); 46 log.debug("created object " + this.getClass().getName()); 47 } 48 49 public void encodeBegin(FacesContext context, UIComponent component) throws java.io.IOException { 50 log.debug("encodeBegin(" + component.getId() + ")"); 51 if (context == null || component == null) { 52 throw new NullPointerException (); 53 } 54 if (!component.isRendered()) return; 55 56 SelectBoolean comp = (SelectBoolean)component; 57 58 ResponseWriter writer = context.getResponseWriter(); 59 60 writer.startElement(Attributes.SELECT, component); 61 RendererUtils.writeAttribute(Attributes.ID, comp.getClientId(context), writer); 62 RendererUtils.writeAttribute(Attributes.STYLE_CLASS, comp.getStyleClass(), writer); 63 RendererUtils.writeAttribute(Attributes.XML_LANG, comp.getXmllang(), writer); 64 65 66 if (comp.getName() == null) { 67 log.debug("getName is null"); 68 comp.setName(comp.getClientId(context)); 69 } 70 RendererUtils.writeAttribute(Attributes.NAME, comp.getName(), writer); 71 72 RendererUtils.writeAttribute(Attributes.TABINDEX, comp.getTabindex(), writer); 73 RendererUtils.writeAttribute(Attributes.TITLE, comp.getTitle(), writer); 74 75 if (comp.isSelected()) 76 RendererUtils.writeAttribute(Attributes.VALUE, OPTION_VALUE, writer); 77 else { } 78 79 RendererUtils.writeAttribute(Attributes.MULTIPLE, "true", writer); 81 82 writer.startElement(Attributes.OPTION, component); 84 RendererUtils.writeAttribute(Attributes.VALUE, OPTION_VALUE, writer); 85 } 86 87 public void encodeChildren(FacesContext context, UIComponent component) throws java.io.IOException { 88 log.debug("encodeChildren(" + component.getId() + ")"); 89 if (context == null || component == null) { 90 throw new NullPointerException (); 91 } 92 if (!component.isRendered()) return; 93 94 RendererUtils.renderChildren(context, component); 95 } 96 97 public void encodeEnd(FacesContext context, UIComponent component) throws java.io.IOException { 98 log.debug("encodeEnd(" + component.getId() + ")"); 99 if (context == null || component == null) { 100 throw new NullPointerException (); 101 } 102 if (!component.isRendered()) return; 103 104 ResponseWriter writer = context.getResponseWriter(); 105 106 writer.endElement(Attributes.OPTION); 107 writer.endElement(Attributes.SELECT); 108 } 109 110 public void decode(FacesContext context, UIComponent component) { 111 log.debug("decode(" + component.getId() + ")"); 112 if (component == null || context == null) throw new NullPointerException (); 113 if (!(component instanceof SelectBoolean)) 114 log.error("Component " + component.getClass().getName() + " is no SelectMany component, cannot be converted!"); 115 116 SelectBoolean comp = (SelectBoolean)component; 117 118 Map map = context.getExternalContext().getRequestParameterMap(); 119 120 if (map.containsKey(comp.getName())){ 122 log.debug("Parameter:" + comp.getName() + " was found in the request. Value: " + (String )map.get(comp.getName())); 123 124 String value = (String )map.get(comp.getName()); 125 if (OPTION_VALUE.equalsIgnoreCase(value)) comp.setSelected(true); 126 else comp.setSelected(false); 127 } 128 } 129 } 130 131 | Popular Tags |