1 16 package org.apache.myfaces.custom.tree.renderkit.html; 17 18 import org.apache.myfaces.custom.tree.HtmlTreeImageCommandLink; 19 import org.apache.myfaces.custom.tree.HtmlTreeNode; 20 import org.apache.myfaces.renderkit.html.HTML; 21 import org.apache.myfaces.renderkit.html.HtmlLinkRendererBase; 22 import org.apache.myfaces.renderkit.html.HtmlRendererUtils; 23 24 import javax.faces.component.UIComponent; 25 import javax.faces.context.FacesContext; 26 import javax.faces.context.ResponseWriter; 27 import java.io.IOException ; 28 29 30 57 public class HtmlTreeImageCommandLinkRenderer 58 extends HtmlLinkRendererBase 59 { 60 61 private static final Integer ZERO = new Integer (0); 62 63 64 public void decode(FacesContext facesContext, UIComponent component) 65 { 66 super.decode(facesContext, component); 67 String clientId = component.getClientId(facesContext); 68 String reqValue = (String )facesContext.getExternalContext().getRequestParameterMap().get(HtmlRendererUtils.getHiddenCommandLinkFieldName(HtmlRendererUtils.getFormName(component, facesContext))); 69 if (reqValue != null && reqValue.equals(clientId)) 70 { 71 HtmlTreeNode node = (HtmlTreeNode)component.getParent(); 72 73 node.toggleExpanded(); 74 } 75 } 76 77 78 protected void renderCommandLinkStart(FacesContext facesContext, 79 UIComponent component, 80 String clientId, 81 Object value, 82 String style, 83 String styleClass) throws IOException 84 { 85 86 super.renderCommandLinkStart(facesContext, component, clientId, value, style, styleClass); 87 88 String url = ((HtmlTreeImageCommandLink)component).getImage(); 89 90 if ((url != null) && (url.length() > 0)) 91 { 92 ResponseWriter writer = facesContext.getResponseWriter(); 93 writer.startElement(HTML.IMG_ELEM, component); 94 String src = facesContext.getApplication().getViewHandler().getResourceURL(facesContext, url); 95 writer.writeAttribute(HTML.SRC_ATTR, src, null); 110 writer.writeAttribute(HTML.BORDER_ATTR, ZERO, null); 111 112 HtmlRendererUtils.renderHTMLAttributes(writer, component, HTML.IMG_PASSTHROUGH_ATTRIBUTES); 113 114 writer.endElement(HTML.IMG_ELEM); 115 } 116 } 117 } 118 | Popular Tags |