コード例 #1
0
  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]);
      }
    }
  }
コード例 #2
0
  private static boolean isBehaviorEventAttribute(Attribute attr, String behaviorEventName) {

    String[] events = attr.getEvents();

    return ((behaviorEventName != null)
        && (events != null)
        && (events.length > 0)
        && (behaviorEventName.equals(events[0])));
  }
コード例 #3
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);
        }
      }
    }
  }