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.InputText; 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 InputTextRenderer extends WmlRenderer { 40 private static Log log = LogFactory.getLog(InputTextRenderer.class); 41 42 43 public InputTextRenderer() { 44 super(); 45 log.debug("created object " + this.getClass().getName()); 46 } 47 48 public void encodeBegin(FacesContext context, UIComponent component) throws java.io.IOException { 49 log.debug("encodeBegin(" + component.getId() + ")"); 50 if (context == null || component == null) { 51 throw new NullPointerException (); 52 } 53 } 54 55 public void encodeChildren(FacesContext context, UIComponent component) throws java.io.IOException { 56 log.debug("encodeChildren(" + component.getId() + ")"); 57 if (context == null || component == null) { 58 throw new NullPointerException (); 59 } 60 } 61 62 public void encodeEnd(FacesContext context, UIComponent component) throws java.io.IOException { 63 log.debug("encodeEnd(" + component.getId() + ")"); 64 if (context == null || component == null) { 65 throw new NullPointerException (); 66 } 67 68 if (!component.isRendered()) return; 69 70 InputText comp = (InputText)component; 71 72 ResponseWriter writer = context.getResponseWriter(); 73 writer.startElement(Attributes.INPUT, component); 74 75 RendererUtils.writeAttribute(Attributes.ID, comp.getClientId(context), writer); 76 RendererUtils.writeAttribute(Attributes.STYLE_CLASS, comp.getStyleClass(), writer); 77 RendererUtils.writeAttribute(Attributes.XML_LANG, comp.getXmllang(), writer); 78 79 80 if (comp.getName() == null) { 81 log.debug("getName is null"); 82 comp.setName(comp.getClientId(context)); 83 } 84 RendererUtils.writeAttribute(Attributes.NAME, comp.getName(), writer); 85 86 87 if (comp.isEmptyok()) RendererUtils.writeAttribute(Attributes.EMPTY_OK, "true", writer); 88 89 RendererUtils.writeAttribute(Attributes.FORMAT, comp.getFormat(), writer); 90 RendererUtils.writeAttribute(Attributes.MAX_LENGTH, comp.getMaxlength(), writer); 91 RendererUtils.writeAttribute(Attributes.SIZE, comp.getSize(), writer); 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 writer.endElement(Attributes.INPUT); 100 } 101 102 public void decode(FacesContext context, UIComponent component) { 103 log.debug("decode(" + component.getId() + ")"); 104 if (component == null || context == null) throw new NullPointerException (); 105 if (!(component instanceof InputText)) 106 log.error("Component " + component.getClass().getName() + " is no InputText, cannot be converted!"); 107 108 InputText comp = (InputText)component; 109 110 Map map = context.getExternalContext().getRequestParameterMap(); 111 112 if (map.containsKey(comp.getName())){ 114 log.debug("Parameter:" + comp.getName() + " was found in the request. Value: " + (String )map.get(comp.getName())); 115 comp.setSubmittedValue(map.get(comp.getName())); 116 } 118 } 119 120 121 public Object getConvertedValue(FacesContext context, UIComponent component, Object submittedValue) throws javax.faces.convert.ConverterException { 122 return(RendererUtils.convertToObject(context, component)); 123 } 124 } 125 126 | Popular Tags |