1 17 package org.alfresco.web.ui.common.renderer; 18 19 import java.io.IOException ; 20 import java.io.Writer ; 21 import java.util.List ; 22 import java.util.Map ; 23 24 import javax.faces.component.UIComponent; 25 import javax.faces.context.FacesContext; 26 27 import org.alfresco.web.ui.common.Utils; 28 import org.alfresco.web.ui.common.component.IBreadcrumbHandler; 29 import org.alfresco.web.ui.common.component.UIBreadcrumb; 30 31 36 public class BreadcrumbRenderer extends BaseRenderer 37 { 38 41 44 public void decode(FacesContext context, UIComponent component) 45 { 46 Map requestMap = context.getExternalContext().getRequestParameterMap(); 47 String fieldId = getHiddenFieldName(context, component); 48 String value = (String )requestMap.get(fieldId); 49 if (value != null && value.length() != 0) 50 { 51 int selectedIndex = Integer.parseInt(value); 53 UIBreadcrumb.BreadcrumbEvent event = new UIBreadcrumb.BreadcrumbEvent(component, selectedIndex); 54 component.queueEvent(event); 55 } 56 } 57 58 61 public void encodeBegin(FacesContext context, UIComponent component) throws IOException 62 { 63 if (component.isRendered() == true) 65 { 66 Writer out = context.getResponseWriter(); 67 68 UIBreadcrumb breadcrumb = (UIBreadcrumb)component; 69 List <IBreadcrumbHandler> elements = (List )breadcrumb.getValue(); 71 72 boolean first = true; 73 for (int index=0; index<elements.size(); index++) 74 { 75 IBreadcrumbHandler element = elements.get(index); 76 77 if (index != 0 || breadcrumb.getShowRoot() == true) 79 { 80 out.write( renderBreadcrumb(context, breadcrumb, element.toString(), index, first) ); 81 first = false; 82 } 83 } 84 } 85 } 86 87 88 91 102 private String renderBreadcrumb(FacesContext context, UIBreadcrumb bc, String element, int index, boolean first) 103 { 104 StringBuilder buf = new StringBuilder (200); 106 107 if (first == false) 109 { 110 buf.append(' ') 111 .append(Utils.encode(bc.getSeparator())) 112 .append(' '); 113 } 114 115 buf.append("<a HREF='#' onclick=\""); 118 buf.append(Utils.generateFormSubmit(context, bc, getHiddenFieldName(context, bc), Integer.toString(index))); 119 buf.append('"'); 120 121 if (bc.getAttributes().get("style") != null) 122 { 123 buf.append(" style=\"") 124 .append(bc.getAttributes().get("style")) 125 .append('"'); 126 } 127 if (bc.getAttributes().get("styleClass") != null) 128 { 129 buf.append(" class=") 130 .append(bc.getAttributes().get("styleClass")); 131 } 132 if (bc.getAttributes().get("tooltip") != null) 133 { 134 buf.append(" title=\"") 135 .append(bc.getAttributes().get("tooltip")) 136 .append('"'); 137 } 138 buf.append('>'); 139 140 buf.append(Utils.encode(element)); 143 144 buf.append("</a>"); 146 147 return buf.toString(); 148 } 149 150 157 private static String getHiddenFieldName(FacesContext context, UIComponent component) 158 { 159 return component.getClientId(context); 160 } 161 } 162 | Popular Tags |