| 1 33 34 package com.icesoft.faces.renderkit.dom_html_basic; 35 36 import com.icesoft.faces.context.DOMContext; 37 import org.w3c.dom.Element ; 38 import org.w3c.dom.Node ; 39 import org.w3c.dom.Text ; 40 41 import javax.faces.component.UIComponent; 42 import javax.faces.context.FacesContext; 43 import java.io.IOException ; 44 45 59 60 public class LabelRenderer extends DomBasicInputRenderer { 61 62 public void encodeBegin(FacesContext facesContext, UIComponent uiComponent) 63 throws IOException { 64 65 validateParameters(facesContext, uiComponent, null); 66 67 DOMContext domContext = 68 DOMContext.attachDOMContext(facesContext, uiComponent); 69 70 if (!domContext.isInitialized()) { 71 Element root = domContext.createElement("label"); 72 domContext.setRootNode(root); 73 setRootElementId(facesContext, root, uiComponent); 74 PassThruAttributeRenderer.renderAttributes( 75 facesContext, uiComponent, null); 76 } 77 Element root = (Element ) domContext.getRootNode(); 78 79 UIComponent forComponent = null; 86 String forComponentClientId = null; 87 String forAttribute = (String ) uiComponent.getAttributes().get("for"); 88 if (forAttribute != null) { 89 forComponent = findForComponent(facesContext, uiComponent); 90 if (forComponent != null) { 91 forComponentClientId = forComponent.getClientId(facesContext); 92 } else { 93 forComponentClientId = fabricateClientId(uiComponent, 94 facesContext, 95 forAttribute); 96 } 97 } 98 if (forComponentClientId != null) { 101 root.setAttribute("for", forComponentClientId); 102 } 103 String styleClass = 104 (String ) uiComponent.getAttributes().get("styleClass"); 105 if (styleClass != null) { 106 root.setAttribute("class", styleClass); 107 } 108 String currentValue = getValue(facesContext, uiComponent); 109 if (currentValue != null && currentValue.length() != 0) { 110 Node firstChild = root.getFirstChild(); 111 if (firstChild != null && firstChild instanceof Text ) { 112 ((Text ) firstChild).setData(currentValue); 113 } else { 114 root.appendChild( 115 domContext.getDocument().createTextNode(currentValue)); 116 } 117 } 118 119 domContext.stepOver(); 120 domContext.streamWrite(facesContext, uiComponent); 121 } 122 123 public void encodeChildren(FacesContext facesContext, 124 UIComponent uiComponent) { 125 validateParameters(facesContext, uiComponent, null); 126 } 127 128 public void encodeEnd(FacesContext facesContext, UIComponent uiComponent) 129 throws IOException { 130 validateParameters(facesContext, uiComponent, null); 131 } 132 133 134 } 135 | Popular Tags |