1 16 package org.apache.myfaces.renderkit.html; 17 18 import org.apache.myfaces.renderkit.JSFAttr; 19 import org.apache.myfaces.renderkit.RendererUtils; 20 21 import javax.faces.component.UIComponent; 22 import javax.faces.component.UIInput; 23 import javax.faces.component.UIOutput; 24 import javax.faces.component.html.HtmlInputSecret; 25 import javax.faces.context.FacesContext; 26 import javax.faces.context.ResponseWriter; 27 import javax.faces.convert.ConverterException; 28 import java.io.IOException ; 29 30 31 51 public class HtmlSecretRendererBase 52 extends HtmlRenderer 53 { 54 public void encodeEnd(FacesContext facesContext, UIComponent uiComponent) 55 throws IOException 56 { 57 RendererUtils.checkParamValidity(facesContext, uiComponent, UIInput.class); 58 59 ResponseWriter writer = facesContext.getResponseWriter(); 60 writer.startElement(HTML.INPUT_ELEM, uiComponent); 61 writer.writeAttribute(HTML.TYPE_ATTR, HTML.INPUT_TYPE_PASSWORD, null); 62 63 String clientId = uiComponent.getClientId(facesContext); 64 65 HtmlRendererUtils.writeIdIfNecessary(writer, uiComponent, facesContext); 66 writer.writeAttribute(HTML.NAME_ATTR, clientId, null); 67 68 boolean isRedisplay; 69 if (uiComponent instanceof HtmlInputSecret) 70 { 71 isRedisplay = ((HtmlInputSecret)uiComponent).isRedisplay(); 72 } 73 else 74 { 75 isRedisplay = RendererUtils.getBooleanAttribute(uiComponent, JSFAttr.REDISPLAY_ATTR, false); 76 } 77 if (isRedisplay) 78 { 79 String strValue = RendererUtils.getStringValue(facesContext, uiComponent); 80 writer.writeAttribute(HTML.VALUE_ATTR, strValue, JSFAttr.VALUE_ATTR); 81 } 82 83 HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, HTML.INPUT_PASSTHROUGH_ATTRIBUTES_WITHOUT_DISABLED); 84 if (isDisabled(facesContext, uiComponent)) 85 { 86 writer.writeAttribute(HTML.DISABLED_ATTR, Boolean.TRUE, null); 87 } 88 89 writer.endElement(HTML.INPUT_ELEM); 90 } 91 92 93 protected boolean isDisabled(FacesContext facesContext, UIComponent uiComponent) 94 { 95 if (uiComponent instanceof HtmlInputSecret) 97 { 98 return ((HtmlInputSecret)uiComponent).isDisabled(); 99 } 100 else 101 { 102 return RendererUtils.getBooleanAttribute(uiComponent, HTML.DISABLED_ATTR, false); 103 } 104 } 105 106 107 public void decode(FacesContext facesContext, UIComponent component) 108 { 109 RendererUtils.checkParamValidity(facesContext, component, UIInput.class); 110 HtmlRendererUtils.decodeUIInput(facesContext, component); 111 } 112 113 public Object getConvertedValue(FacesContext facesContext, UIComponent uiComponent, Object submittedValue) throws ConverterException 114 { 115 RendererUtils.checkParamValidity(facesContext, uiComponent, UIOutput.class); 116 return RendererUtils.getConvertedUIOutputValue(facesContext, 117 (UIOutput)uiComponent, 118 submittedValue); 119 } 120 121 } 122 | Popular Tags |