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.InputSecret; 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 InputSecretRenderer extends WmlRenderer { 40 private static Log log = LogFactory.getLog(InputSecretRenderer.class); 41 42 43 public InputSecretRenderer() { 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 InputSecret comp = (InputSecret)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 RendererUtils.writeAttribute(Attributes.TYPE, "password", writer); 96 97 writer.endElement(Attributes.INPUT); 98 } 99 100 public void decode(FacesContext context, UIComponent component) { 101 log.debug("decode(" + component.getId() + ")"); 102 if (component == null || context == null) throw new NullPointerException (); 103 if (!(component instanceof InputSecret)) 104 log.error("Component " + component.getClass().getName() + " is no InputSecret, cannot be converted!"); 105 106 InputSecret comp = (InputSecret)component; 107 108 Map map = context.getExternalContext().getRequestParameterMap(); 109 110 if (map.containsKey(comp.getName())){ 112 log.debug("Parameter:" + comp.getName() + " was found in the request. Value: " + map.get(comp.getName())); 113 comp.setSubmittedValue(map.get(comp.getName())); 114 } 116 } 117 118 119 public Object getConvertedValue(FacesContext context, UIComponent component, Object submittedValue) throws javax.faces.convert.ConverterException { 120 return(RendererUtils.convertToObject(context, component)); 121 } 122 } 123 124 | Popular Tags |