private static void renderPassThruAttributesUnoptimized( FacesContext context, ResponseWriter writer, UIComponent component, Attribute[] knownAttributes, Map<String, List<ClientBehavior>> behaviors) throws IOException { boolean isXhtml = XHTML_CONTENT_TYPE.equals(writer.getContentType()); Map<String, Object> attrMap = component.getAttributes(); for (Attribute attribute : knownAttributes) { String attrName = attribute.getName(); String[] events = attribute.getEvents(); boolean hasBehavior = ((events != null) && (events.length > 0) && (behaviors.containsKey(events[0]))); Object value = attrMap.get(attrName); if (value != null && shouldRenderAttribute(value) && !hasBehavior) { writer.writeAttribute(prefixAttribute(attrName, isXhtml), value, attrName); } else if (hasBehavior) { renderHandler(context, component, null, attrName, value, events[0]); } } }
private static void renderPassThruAttributesOptimized( FacesContext context, ResponseWriter writer, UIComponent component, Attribute[] knownAttributes, List<String> setAttributes, Map<String, List<ClientBehavior>> behaviors) throws IOException { String behaviorEventName = getSingleBehaviorEventName(behaviors); boolean renderedBehavior = false; Collections.sort(setAttributes); boolean isXhtml = XHTML_CONTENT_TYPE.equals(writer.getContentType()); Map<String, Object> attrMap = component.getAttributes(); for (String name : setAttributes) { int index = Arrays.binarySearch(knownAttributes, Attribute.attr(name)); if (index >= 0) { Object value = attrMap.get(name); if (value != null && shouldRenderAttribute(value)) { Attribute attr = knownAttributes[index]; if (isBehaviorEventAttribute(attr, behaviorEventName)) { renderHandler(context, component, null, name, value, behaviorEventName); renderedBehavior = true; } else { writer.writeAttribute(prefixAttribute(name, isXhtml), value, name); } } } } if ((behaviorEventName != null) && !renderedBehavior) { for (int i = 0; i < knownAttributes.length; i++) { Attribute attr = knownAttributes[i]; String[] events = attr.getEvents(); if ((events != null) && (events.length > 0) && (behaviorEventName.equals(events[0]))) { renderHandler(context, component, null, attr.getName(), null, behaviorEventName); } } } }
@SuppressWarnings("rawtypes") public static void renderXHTMLStyleBooleanAttributes(ResponseWriter writer, UIComponent component) throws IOException { assert (writer != null); assert (component != null); Map attrMap = component.getAttributes(); for (String attrName : BOOLEAN_ATTRIBUTES) { Object val = attrMap.get(attrName); if (val == null) { continue; } if (Boolean.valueOf(val.toString())) { writer.writeAttribute(attrName, true, attrName); } } }
@SuppressWarnings("rawtypes") public static void renderOnclick( FacesContext context, UIComponent component, Collection<ClientBehaviorContext.Parameter> params) throws IOException { final String handlerName = "onclick"; final Object userHandler = component.getAttributes().get(handlerName); String behaviorEventName = "action"; if (component instanceof ClientBehaviorHolder) { Map behaviors = ((ClientBehaviorHolder) component).getClientBehaviors(); if (null != behaviors && behaviors.containsKey("click")) { behaviorEventName = "click"; } } renderHandler(context, component, params, handlerName, userHandler, behaviorEventName); }