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]);
      }
    }
  }
  /** Decodes the data from the form. */
  @Override
  public void decode(FacesContext context, UIComponent component) {
    String clientId = component.getClientId(context);

    ExternalContext ext = context.getExternalContext();
    Map<String, String> paramMap = ext.getRequestParameterMap();

    String value = paramMap.get(clientId);

    if (value != null) ((EditableValueHolder) component).setSubmittedValue(value);
  }
Exemple #3
0
  private String calculateViewId(FacesContext context) {
    Map map = context.getExternalContext().getRequestMap();

    String viewId = (String) map.get(RequestDispatcher.INCLUDE_PATH_INFO);

    if (viewId == null) viewId = context.getExternalContext().getRequestPathInfo();

    if (viewId == null) viewId = (String) map.get(RequestDispatcher.INCLUDE_SERVLET_PATH);

    if (viewId == null) viewId = context.getExternalContext().getRequestServletPath();

    return viewId;
  }
Exemple #4
0
  /**
   * This code is currently common to all {@link ViewHandlingStrategy} instances.
   *
   * @see ViewHandler#calculateRenderKitId(javax.faces.context.FacesContext)
   */
  public String calculateRenderKitId(FacesContext context) {

    Util.notNull("context", context);

    Map<String, String> requestParamMap = context.getExternalContext().getRequestParameterMap();
    String result = requestParamMap.get(ResponseStateManager.RENDER_KIT_ID_PARAM);

    if (result == null) {
      if (null == (result = context.getApplication().getDefaultRenderKitId())) {
        result = RenderKitFactory.HTML_BASIC_RENDER_KIT;
      }
    }
    return result;
  }
  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);
  }
  /** Renders the open tag for the text. */
  @Override
  public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
    ResponseWriter out = context.getResponseWriter();

    String id = component.getId();

    String accesskey;
    String dir;
    boolean disabled;
    String disabledClass;
    String enabledClass;
    String lang;

    String onblur;
    String onchange;
    String onclick;
    String ondblclick;
    String onfocus;

    String onkeydown;
    String onkeypress;
    String onkeyup;

    String onmousedown;
    String onmousemove;
    String onmouseout;
    String onmouseover;
    String onmouseup;

    String onselect;

    boolean readonly;
    String style;
    String styleClass;
    String tabindex;
    String title;
    Object value;

    if (component instanceof HtmlSelectOneMenu) {
      HtmlSelectOneMenu htmlComponent = (HtmlSelectOneMenu) component;

      accesskey = htmlComponent.getAccesskey();
      dir = htmlComponent.getDir();
      disabled = htmlComponent.isDisabled();
      disabledClass = htmlComponent.getDisabledClass();
      enabledClass = htmlComponent.getEnabledClass();
      lang = htmlComponent.getLang();

      onblur = htmlComponent.getOnblur();
      onchange = htmlComponent.getOnchange();
      onclick = htmlComponent.getOnclick();
      ondblclick = htmlComponent.getOndblclick();
      onfocus = htmlComponent.getOnfocus();

      onkeydown = htmlComponent.getOnkeydown();
      onkeypress = htmlComponent.getOnkeypress();
      onkeyup = htmlComponent.getOnkeyup();

      onmousedown = htmlComponent.getOnmousedown();
      onmousemove = htmlComponent.getOnmousemove();
      onmouseout = htmlComponent.getOnmouseout();
      onmouseover = htmlComponent.getOnmouseover();
      onmouseup = htmlComponent.getOnmouseup();

      onselect = htmlComponent.getOnselect();

      readonly = htmlComponent.isReadonly();
      style = htmlComponent.getStyle();
      styleClass = htmlComponent.getStyleClass();
      tabindex = htmlComponent.getTabindex();
      title = htmlComponent.getTitle();

      value = htmlComponent.getValue();
    } else {
      Map<String, Object> attrMap = component.getAttributes();

      accesskey = (String) attrMap.get("accesskey");
      dir = (String) attrMap.get("dir");
      disabled = Boolean.TRUE.equals(attrMap.get("disabled"));
      disabledClass = (String) attrMap.get("disabledClass");
      enabledClass = (String) attrMap.get("enabledClass");
      lang = (String) attrMap.get("lang");

      onblur = (String) attrMap.get("onblur");
      onchange = (String) attrMap.get("onchange");
      onclick = (String) attrMap.get("onclick");
      ondblclick = (String) attrMap.get("ondblclick");
      onfocus = (String) attrMap.get("onfocus");

      onkeydown = (String) attrMap.get("onkeydown");
      onkeypress = (String) attrMap.get("onkeypress");
      onkeyup = (String) attrMap.get("onkeyup");

      onmousedown = (String) attrMap.get("onmousedown");
      onmousemove = (String) attrMap.get("onmousemove");
      onmouseout = (String) attrMap.get("onmouseout");
      onmouseover = (String) attrMap.get("onmouseover");
      onmouseup = (String) attrMap.get("onmouseup");

      onselect = (String) attrMap.get("onselect");

      readonly = Boolean.TRUE.equals(attrMap.get("readonly"));
      style = (String) attrMap.get("style");
      styleClass = (String) attrMap.get("styleClass");
      tabindex = (String) attrMap.get("tabindex");
      title = (String) attrMap.get("title");

      value = attrMap.get("value");
    }

    UIViewRoot viewRoot = context.getViewRoot();

    out.startElement("select", component);

    if (style != null) out.writeAttribute("style", style, "style");

    if (styleClass != null) out.writeAttribute("class", styleClass, "class");

    String clientId = component.getClientId(context);
    out.writeAttribute("name", clientId, "name");

    if (id != null && !id.startsWith(UIViewRoot.UNIQUE_ID_PREFIX))
      out.writeAttribute("id", clientId, "id");

    if (disabled) out.writeAttribute("disabled", "disabled", "disabled");

    if (accesskey != null) out.writeAttribute("accesskey", accesskey, "accesskey");

    if (dir != null) out.writeAttribute("dir", dir, "dir");

    if (lang != null) out.writeAttribute("lang", lang, "lang");

    if (onblur != null) out.writeAttribute("onblur", onblur, "onblur");

    if (onchange != null) out.writeAttribute("onchange", onchange, "onchange");

    if (onclick != null) out.writeAttribute("onclick", onclick, "onclick");

    if (ondblclick != null) out.writeAttribute("ondblclick", ondblclick, "ondblclick");

    if (onfocus != null) out.writeAttribute("onfocus", onfocus, "onfocus");

    if (onkeydown != null) out.writeAttribute("onkeydown", onkeydown, "onkeydown");

    if (onkeypress != null) out.writeAttribute("onkeypress", onkeypress, "onkeypress");

    if (onkeyup != null) out.writeAttribute("onkeyup", onkeyup, "onkeyup");

    if (onmousedown != null) out.writeAttribute("onmousedown", onmousedown, "onmousedown");

    if (onmousemove != null) out.writeAttribute("onmousemove", onmousemove, "onmousemove");

    if (onmouseout != null) out.writeAttribute("onmouseout", onmouseout, "onmouseout");

    if (onmouseover != null) out.writeAttribute("onmouseover", onmouseover, "onmouseover");

    if (onmouseup != null) out.writeAttribute("onmouseup", onmouseup, "onmouseup");

    if (onselect != null) out.writeAttribute("onselect", onselect, "onselect");

    if (readonly) out.writeAttribute("readonly", "readonly", "readonly");

    if (tabindex != null) out.writeAttribute("tabindex", tabindex, "tabindex");

    if (title != null) out.writeAttribute("title", title, "title");

    out.writeAttribute("size", "1", "size");

    out.write("\n");

    encodeOneChildren(out, context, component, value, enabledClass, disabledClass);

    out.endElement("select");
    out.write("\n");

    for (UIComponent child : component.getChildren()) {
      if (child instanceof UIComponent) child.encodeAll(context);
    }
  }