/** 重载方法,调整元素的输出顺序。 */
  private void writeElementTag(
      TagWriter tagWriter, Object item, Object value, Object label, int itemIndex)
      throws JspException {
    String id = resolveId();

    String resolvedLabelClass = getInputType();
    if (labelCssClass != null) {
      resolvedLabelClass += " " + labelCssClass;
    }

    tagWriter.startTag("label");
    tagWriter.writeAttribute("for", id);

    tagWriter.writeAttribute("class", resolvedLabelClass);

    if (itemIndex > 0) {
      Object resolvedDelimiter = evaluate("delimiter", getDelimiter());
      if (resolvedDelimiter != null) {
        tagWriter.appendValue(resolvedDelimiter.toString());
      }
    }
    tagWriter.startTag("input");

    writeOptionalAttribute(tagWriter, "id", id);
    writeOptionalAttribute(tagWriter, "name", getName());
    writeOptionalAttributes(tagWriter);
    tagWriter.writeAttribute("type", getInputType());
    renderFromValue(item, value, tagWriter);
    tagWriter.endTag();

    tagWriter.appendValue(convertToDisplayString(label));
    tagWriter.endTag();
  }
  /**
   * Creates messagesPanel tag
   *
   * @throws JspException In case when {@link JspException} is generated later in the chain when tag
   *     configured by messagesPanel could not be created
   * @see org.springframework.web.servlet.tags.RequestContextAwareTag#doStartTagInternal()
   */
  @Override
  protected int doStartTagInternal() throws JspException {

    if (!StringUtils.hasText(this.panelElement)
        && !StringUtils.hasText(this.outerElement)
        && !StringUtils.hasText(this.innerElement)) {
      throw new JspTagException(
          "At least one out of panelElement, outerElement, innerElement should be set");
    }

    TagWriter tagWriter = createTagWriter();

    Object messages = this.pageContext.findAttribute(messagesAttributeName);

    if (messages != null) {

      if (StringUtils.hasText(panelElement)) {
        tagWriter.startTag(panelElement); // <div>

        StringBuilder className = new StringBuilder(panelClassName);
        String type = getType(messages);

        if (panelTypeClassPrefix != null && StringUtils.hasText(type)) {

          if (StringUtils.hasLength(className)) {
            className.append(" ");
          }
          className.append(panelTypeClassPrefix);
        }
        className.append(type);

        if (StringUtils.hasText(className)) {
          tagWriter.writeAttribute("class", className.toString());
        }
      }

      {
        if (StringUtils.hasText(outerElement)) {
          tagWriter.startTag(outerElement); // <ul>
        }

        writeMessages(tagWriter, messages);

        if (StringUtils.hasText(outerElement)) {
          tagWriter.endTag(); // </ul>
        }
      }

      if (StringUtils.hasText(panelElement)) {
        tagWriter.endTag(); // </div>
      }
    }

    return EVAL_BODY_INCLUDE;
  }
Пример #3
0
  @Override
  protected void renderDefaultContent(TagWriter tagWriter) throws JspException {
    String[] errorMessages = getBindStatus().getErrorMessages();

    if (CollectionUtils.size(errorMessages) > 1) {
      tagWriter.startTag(getElement());
      writeDefaultAttributes(tagWriter);

      for (String errorMessage : errorMessages) {
        tagWriter.startTag("li");
        tagWriter.appendValue(errorMessage);
        tagWriter.endTag();
      }

      tagWriter.endTag();
    } else {
      tagWriter.startTag("span");
      for (String errorMessage : errorMessages) {
        tagWriter.appendValue(errorMessage);
      }
      tagWriter.endTag();
    }
  }
Пример #4
0
  @Override
  protected void writeInputContent(TagWriter tagWriter) throws JspException {
    tagWriter.startTag("textarea");
    if (isAutoValidate() || getValidConf() != null) {
      writeOptionalAttribute(tagWriter, ATTR_VALID_CONF, getValidConf());
      setOnblur("validateEventHandler();");
    }

    writeDefaultAttributes(tagWriter);
    writeOptionalAttribute(tagWriter, ROWS_ATTRIBUTE, getRows());
    writeOptionalAttribute(tagWriter, COLS_ATTRIBUTE, getCols());
    writeOptionalAttribute(tagWriter, ONSELECT_ATTRIBUTE, getOnselect());
    tagWriter.appendValue(getDisplayString(getBoundValue(), getPropertyEditor()));
    tagWriter.endTag();
  }
  /**
   * writes the message tag.
   *
   * <p>If {@link #innerElement} is specified, the tag specified in it will be applied around the
   * message.<br>
   *
   * @param tagWriter a TagWriter instance
   * @param message message
   * @throws JspException Occurs when {@link JspTagException} occurs in case when nothing is set in
   *     the configuration of the tag that configures messagesPanel using tagWriter.
   */
  protected void writeMessage(TagWriter tagWriter, Object message) throws JspException {
    if (message != null) {
      if (StringUtils.hasText(innerElement)) {
        tagWriter.startTag(innerElement); // <li>
      }
      if (disableHtmlEscape) {
        tagWriter.appendValue(getText(message));
      } else {
        tagWriter.appendValue(HtmlEscapeUtils.htmlEscape(getText(message)));
      }

      if (StringUtils.hasText(innerElement)) {
        tagWriter.endTag(); // </li>
      }
    }
  }
Пример #6
0
  @Override
  protected int writeTagContent(TagWriter tagWriter) throws JspException {
    super.writeTagContent(tagWriter);

    if (!isDisabled()) {
      // Write out the 'field was present' marker.
      tagWriter.startTag("input");
      tagWriter.writeAttribute("type", "hidden");
      String name = WebDataBinder.DEFAULT_FIELD_MARKER_PREFIX + getName();
      tagWriter.writeAttribute("name", name);
      tagWriter.writeAttribute("value", processFieldValue(name, "on", getInputType()));
      tagWriter.endTag();
    }

    return SKIP_BODY;
  }