| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.seasar.teeda.core.render.html; |
| 17 | |
|
| 18 | |
import java.io.IOException; |
| 19 | |
|
| 20 | |
import javax.faces.component.UIComponent; |
| 21 | |
import javax.faces.component.html.HtmlInputSecret; |
| 22 | |
import javax.faces.context.FacesContext; |
| 23 | |
import javax.faces.context.ResponseWriter; |
| 24 | |
import javax.faces.internal.IgnoreAttribute; |
| 25 | |
|
| 26 | |
import org.seasar.teeda.core.JsfConstants; |
| 27 | |
import org.seasar.teeda.core.render.AbstractInputRenderer; |
| 28 | |
import org.seasar.teeda.core.util.HTMLEncodeUtil; |
| 29 | |
import org.seasar.teeda.core.util.RendererUtil; |
| 30 | |
import org.seasar.teeda.core.util.ValueHolderUtil; |
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | 35 | public class HtmlInputSecretRenderer extends AbstractInputRenderer { |
| 36 | |
|
| 37 | |
public static final String COMPONENT_FAMILY = "javax.faces.Input"; |
| 38 | |
|
| 39 | |
public static final String RENDERER_TYPE = "javax.faces.Secret"; |
| 40 | |
|
| 41 | 35 | private final IgnoreAttribute ignoreAttribute = new IgnoreAttribute(); |
| 42 | |
{ |
| 43 | 35 | addIgnoreAttributeName(JsfConstants.ID_ATTR); |
| 44 | 35 | addIgnoreAttributeName(JsfConstants.VALUE_ATTR); |
| 45 | 35 | addIgnoreAttributeName(JsfConstants.REDISPLAY_ATTR); |
| 46 | 35 | addIgnoreAttributeName(JsfConstants.STYLE_CLASS_ATTR); |
| 47 | 35 | addIgnoreAttributeName(JsfConstants.TYPE_ATTR); |
| 48 | 35 | addIgnoreAttributeName(JsfConstants.NAME_ATTR); |
| 49 | 35 | } |
| 50 | |
|
| 51 | |
public void encodeEnd(final FacesContext context, |
| 52 | |
final UIComponent component) throws IOException { |
| 53 | 10 | assertNotNull(context, component); |
| 54 | 8 | if (!component.isRendered()) { |
| 55 | 1 | return; |
| 56 | |
} |
| 57 | 7 | encodeHtmlInputSecretEnd(context, (HtmlInputSecret) component); |
| 58 | 7 | } |
| 59 | |
|
| 60 | |
protected void encodeHtmlInputSecretEnd(final FacesContext context, |
| 61 | |
final HtmlInputSecret htmlInputSecret) throws IOException { |
| 62 | 7 | final ResponseWriter writer = context.getResponseWriter(); |
| 63 | 7 | writer.startElement(JsfConstants.INPUT_ELEM, htmlInputSecret); |
| 64 | 7 | RendererUtil.renderAttribute(writer, JsfConstants.TYPE_ATTR, |
| 65 | |
JsfConstants.PASSWORD_VALUE); |
| 66 | 7 | RendererUtil.renderIdAttributeIfNecessary(writer, htmlInputSecret, |
| 67 | |
getIdForRender(context, htmlInputSecret)); |
| 68 | 7 | RendererUtil.renderAttribute(writer, JsfConstants.NAME_ATTR, |
| 69 | |
htmlInputSecret.getClientId(context)); |
| 70 | |
|
| 71 | 7 | String value = ValueHolderUtil.getValueForRender(context, |
| 72 | |
htmlInputSecret); |
| 73 | 7 | if (!htmlInputSecret.isRedisplay()) { |
| 74 | 5 | value = ""; |
| 75 | |
} |
| 76 | 7 | RendererUtil.renderAttribute(writer, JsfConstants.VALUE_ATTR, |
| 77 | |
HTMLEncodeUtil.encode(value, true, true)); |
| 78 | 7 | renderStyleClass(context, htmlInputSecret, writer); |
| 79 | 7 | renderRemainAttributes(htmlInputSecret, writer, ignoreAttribute); |
| 80 | 7 | writer.endElement(JsfConstants.INPUT_ELEM); |
| 81 | 7 | } |
| 82 | |
|
| 83 | |
protected void renderStyleClass(final FacesContext context, |
| 84 | |
final HtmlInputSecret htmlInputSecret, final ResponseWriter writer) |
| 85 | |
throws IOException { |
| 86 | 7 | final String styleClass = htmlInputSecret.getStyleClass(); |
| 87 | 7 | RendererUtil.renderAttribute(writer, JsfConstants.STYLE_CLASS_ATTR, |
| 88 | |
styleClass); |
| 89 | 7 | } |
| 90 | |
|
| 91 | |
public void decode(final FacesContext context, final UIComponent component) { |
| 92 | 4 | assertNotNull(context, component); |
| 93 | 2 | decodeHtmlInputSecret(context, (HtmlInputSecret) component); |
| 94 | 2 | } |
| 95 | |
|
| 96 | |
protected void decodeHtmlInputSecret(final FacesContext context, |
| 97 | |
final HtmlInputSecret htmlInputSecret) { |
| 98 | 2 | getDecoder().decode(context, htmlInputSecret); |
| 99 | 2 | } |
| 100 | |
|
| 101 | |
public void addIgnoreAttributeName(final String name) { |
| 102 | 210 | ignoreAttribute.addAttributeName(name); |
| 103 | 210 | } |
| 104 | |
|
| 105 | |
} |