Пример #1
0
  @Override
  protected void getEndTextToRender(
      FacesContext context, UIComponent component, String currentValue) throws IOException {

    ResponseWriter writer = context.getResponseWriter();
    assert (writer != null);

    String redisplay = String.valueOf(component.getAttributes().get("redisplay"));
    if (redisplay == null || !redisplay.equals("true")) {
      currentValue = "";
    }

    writer.startElement("input", component);
    writeIdAttributeIfNecessary(context, writer, component);
    writer.writeAttribute("type", "password", "type");
    writer.writeAttribute("name", component.getClientId(context), "clientId");

    String autoComplete = (String) component.getAttributes().get("autocomplete");
    if (autoComplete != null) {
      // only output the autocomplete attribute if the value
      // is 'off' since its lack of presence will be interpreted
      // as 'on' by the browser
      if ("off".equals(autoComplete)) {
        writer.writeAttribute("autocomplete", "off", "autocomplete");
      }
    }

    // render default text specified
    if (currentValue != null) {
      writer.writeAttribute("value", currentValue, "value");
    }

    RenderKitUtils.renderPassThruAttributes(
        context, writer, component, ATTRIBUTES, getNonOnChangeBehaviors(component));
    RenderKitUtils.renderXHTMLStyleBooleanAttributes(writer, component);

    RenderKitUtils.renderOnchange(context, component, false);

    String styleClass;
    if (null != (styleClass = (String) component.getAttributes().get("styleClass"))) {
      writer.writeAttribute("class", styleClass, "styleClass");
    }

    writer.endElement("input");
  }
Пример #2
0
  @Override
  protected void getEndTextToRender(
      FacesContext context, UIComponent component, String currentValue) throws IOException {

    ResponseWriter writer = context.getResponseWriter();
    assert (writer != null);
    boolean shouldWriteIdAttribute = false;
    boolean isOutput = false;

    String style = (String) component.getAttributes().get("style");
    String styleClass = (String) component.getAttributes().get("styleClass");
    String dir = (String) component.getAttributes().get("dir");
    String lang = (String) component.getAttributes().get("lang");
    String title = (String) component.getAttributes().get("title");
    Map<String, Object> passthroughAttributes = component.getPassThroughAttributes(false);
    boolean hasPassthroughAttributes =
        null != passthroughAttributes && !passthroughAttributes.isEmpty();
    if (component instanceof UIInput) {
      writer.startElement("input", component);
      writeIdAttributeIfNecessary(context, writer, component);

      if (component instanceof HtmlInputFile) {
        writer.writeAttribute("type", "file", null);
      } else {
        writer.writeAttribute("type", "text", null);
      }
      writer.writeAttribute("name", (component.getClientId(context)), "clientId");

      // only output the autocomplete attribute if the value
      // is 'off' since its lack of presence will be interpreted
      // as 'on' by the browser
      if ("off".equals(component.getAttributes().get("autocomplete"))) {
        writer.writeAttribute("autocomplete", "off", "autocomplete");
      }

      // render default text specified
      if (currentValue != null) {
        writer.writeAttribute("value", currentValue, "value");
      }
      if (null != styleClass) {
        writer.writeAttribute("class", styleClass, "styleClass");
      }

      // style is rendered as a passthur attribute
      RenderKitUtils.renderPassThruAttributes(
          context, writer, component, INPUT_ATTRIBUTES, getNonOnChangeBehaviors(component));
      RenderKitUtils.renderXHTMLStyleBooleanAttributes(writer, component);

      RenderKitUtils.renderOnchange(context, component, false);

      writer.endElement("input");

    } else if (isOutput = (component instanceof UIOutput)) {
      if (styleClass != null
          || style != null
          || dir != null
          || lang != null
          || title != null
          || hasPassthroughAttributes
          || (shouldWriteIdAttribute = shouldWriteIdAttribute(component))) {
        writer.startElement("span", component);
        writeIdAttributeIfNecessary(context, writer, component);
        if (null != styleClass) {
          writer.writeAttribute("class", styleClass, "styleClass");
        }
        // style is rendered as a passthru attribute
        RenderKitUtils.renderPassThruAttributes(context, writer, component, OUTPUT_ATTRIBUTES);
      }
      if (currentValue != null) {
        Object val = component.getAttributes().get("escape");
        if ((val != null) && Boolean.valueOf(val.toString())) {
          writer.writeText(currentValue, component, "value");
        } else {
          writer.write(currentValue);
        }
      }
    }
    if (isOutput
        && (styleClass != null
            || style != null
            || dir != null
            || lang != null
            || title != null
            || hasPassthroughAttributes
            || (shouldWriteIdAttribute))) {
      writer.endElement("span");
    }
  }
Пример #3
0
  @Override
  public void encodeBegin(FacesContext context, UIComponent component) throws IOException {

    // Hoy por hoy se tiene que hacer de esta manera
    rendererParamsNotNull(context, component);

    if (!shouldEncode(component)) {
      return;
    }

    // Which button type (SUBMIT, RESET, or BUTTON) should we generate?
    String type = getButtonType(component);

    ResponseWriter writer = context.getResponseWriter();
    assert (writer != null);

    String label = "";
    Object value = ((UICommand) component).getValue();
    if (value != null) {
      label = value.toString();
    }

    /*
     * If we have any parameters and the button type is submit or button,
     * then render Javascript to use later.
     * RELEASE_PENDING this logic is slightly wrong - we should buffer the user onclick, and use it later.
     * Leaving it for when we decide how to do script injection.
     */

    Collection<ClientBehaviorContext.Parameter> params = getBehaviorParameters(component);
    if (!params.isEmpty() && (type.equals("submit") || type.equals("button"))) {
      RenderKitUtils.renderJsfJs(context);
    }

    String imageSrc = (String) component.getAttributes().get("image");
    writer.startElement("input", component);
    writeIdAttributeIfNecessary(context, writer, component);
    String clientId = component.getClientId(context);
    if (imageSrc != null) {
      writer.writeAttribute("type", "image", "type");
      writer.writeURIAttribute(
          "src", RenderKitUtils.getImageSource(context, component, "image"), "image");
      writer.writeAttribute("name", clientId, "clientId");
    } else {
      writer.writeAttribute("type", type, "type");
      writer.writeAttribute("name", clientId, "clientId");
      writer.writeAttribute("value", label, "value");
    }

    RenderKitUtils.renderPassThruAttributes(
        context, writer, component, ATTRIBUTES, getNonOnClickBehaviors(component));

    RenderKitUtils.renderXHTMLStyleBooleanAttributes(writer, component);

    String styleClass = (String) component.getAttributes().get("styleClass");
    if (styleClass != null && styleClass.length() > 0) {
      writer.writeAttribute("class", styleClass, "styleClass");
    }

    // EasyTech
    // Data-*
    for (String key : component.getAttributes().keySet()) {
      if (key.startsWith("data-"))
        writer.writeAttribute(key, component.getAttributes().get(key), key);
    }

    RenderKitUtils.renderOnclick(context, component, params, null, false);

    writer.endElement("input");
  }