Exemplo n.º 1
0
  /** ${@inheritDoc} */
  public int doEndTag() throws JspException {

    /* If a reference link was provided, it needs to be rendered on a separate
     * row within the table.
     */
    if ((refLink != null) && (!isEmpty())) {
      ListTagUtil.write(pageContext, "<tr");
      renderRowClassAndId();
      ListTagUtil.write(pageContext, ">");

      ListTagUtil.write(
          pageContext,
          "<td style=\"text-align: center;\" " + "class=\"first-column last-column\" ");

      ListTagUtil.write(pageContext, "colspan=" + String.valueOf(getColumnCount()) + ">");
      ListTagUtil.write(pageContext, "<a href=\"" + refLink + "\" >");

      /* Here we render the reflink and its key. If the key hasn't been set
       * we just display the link address itself.
       */
      if (refLinkKey != null) {
        Object[] args = new Object[2];
        args[0] = new Integer(getPageRowCount());
        args[1] = refLinkKeyArg0;
        String message = LocalizationService.getInstance().getMessage(refLinkKey, args);

        ListTagUtil.write(pageContext, message);
      } else {
        ListTagUtil.write(pageContext, refLink);
      }

      ListTagUtil.write(pageContext, "</a>");
      ListTagUtil.write(pageContext, "</td>");
      ListTagUtil.write(pageContext, "</tr>");
    }

    ListTagUtil.write(pageContext, "</table>");
    renderPaginationControls(true);
    ListTagUtil.write(pageContext, "<!-- END " + getUniqueName() + " -->");
    release();
    return BodyTagSupport.EVAL_PAGE;
  }
Exemplo n.º 2
0
  /** ${@inheritDoc} */
  public int doAfterBody() throws JspException {
    int retval = BodyTagSupport.EVAL_BODY_AGAIN;

    ListCommand cmd = ListTagUtil.getCurrentCommand(this, pageContext);
    boolean haveRenderedColumnHeaderEndTag = false;
    if (cmd.equals(ListCommand.COL_HEADER)) {
      ListTagUtil.write(pageContext, "</tr></thead><tbody>");
      haveRenderedColumnHeaderEndTag = true;
    }

    setState();
    if (haveColsEnumerated && !haveTblHeadersRendered) {
      setupManipulator();
      manip.sort();
      pageData = manip.getPage();

      if (!manip.isListEmpty() && !StringUtils.isBlank(alphaBarColumn)) {
        AlphaBarHelper.getInstance()
            .writeAlphaBar(pageContext, manip.getAlphaBarIndex(), getUniqueName());
      }

      for (ListDecorator dec : getDecorators()) {
        dec.setCurrentList(this);
        dec.beforeList();
      }
      ListTagUtil.write(
          pageContext,
          String.format(
              HIDDEN_TEXT, ListTagUtil.makeFilterSearchParentLabel(uniqueName), searchParent));
      ListTagUtil.write(
          pageContext,
          String.format(
              HIDDEN_TEXT, ListTagUtil.makeFilterSearchChildLabel(uniqueName), searchChild));
      ListTagUtil.write(
          pageContext,
          String.format(
              HIDDEN_TEXT, ListTagUtil.makeParentIsAnElementLabel(uniqueName), parentIsElement));
      setupFilterUI();
      if (filter != null && manip.getUnfilteredDataSize() != 0) {
        ListTagUtil.renderFilterUI(
            pageContext, filter, getUniqueName(), width, columnCount, searchParent, searchChild);
      }
      if (isSortable()) {
        String sortByLabel = ListTagUtil.makeSortByLabel(getUniqueName());
        String sortDirLabel = ListTagUtil.makeSortDirLabel(getUniqueName());

        HtmlTag sortByInputTag = new HtmlTag("input");
        sortByInputTag.setAttribute("type", "hidden");
        sortByInputTag.setAttribute("name", sortByLabel);
        sortByInputTag.setAttribute("id", ListTagUtil.makeSortById(getUniqueName()));
        sortByInputTag.setAttribute(
            "value", StringUtils.defaultString(pageContext.getRequest().getParameter(sortByLabel)));

        HtmlTag sortByDirTag = new HtmlTag("input");
        sortByDirTag.setAttribute("type", "hidden");
        sortByDirTag.setAttribute("name", sortDirLabel);
        sortByDirTag.setAttribute("id", ListTagUtil.makeSortDirId(getUniqueName()));
        sortByDirTag.setAttribute(
            "value",
            StringUtils.defaultString(pageContext.getRequest().getParameter(sortDirLabel)));

        ListTagUtil.write(pageContext, sortByInputTag.render());
        ListTagUtil.write(pageContext, sortByDirTag.render());
      }

      if (!isEmpty()) {
        for (ListDecorator dec : getDecorators()) {
          dec.beforeTopPagination();
        }
      }
      renderPaginationControls(false);
      startTable();
      HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
      manip.bindPaginationInfo();
      request.setAttribute("dataSize", String.valueOf(pageData.size() + 1));
      ListTagUtil.setCurrentCommand(pageContext, getUniqueName(), ListCommand.TBL_HEADER);
      if (pageData != null && pageData.size() > 0) {
        iterator = pageData.iterator();
      } else {
        iterator = null;
      }
    }
    if (haveColsEnumerated && haveTblHeadersRendered && !haveColHeadersRendered) {
      ListTagUtil.setCurrentCommand(pageContext, getUniqueName(), ListCommand.COL_HEADER);

      ListTagUtil.write(pageContext, "<thead><tr>");

      if (!StringUtils.isBlank(title)) {
        HtmlTag th = new HtmlTag("th");
        th.setAttribute("colspan", String.valueOf(getColumnCount()));
        HtmlTag strong = new HtmlTag("strong");
        strong.addBody(title);
        th.addBody(strong.render());

        ListTagUtil.write(pageContext, th.render());

        ListTagUtil.write(pageContext, "</tr>\n<tr>");
      }
    }
    if (haveColHeadersRendered && !haveTblFootersRendered) {
      if (!haveRenderedColumnHeaderEndTag) {
        ListTagUtil.write(pageContext, "</tr>");
      }

      if (manip.isListEmpty()) {
        renderEmptyList();
        return BodyTagSupport.SKIP_BODY;
      } else {
        ListTagUtil.setCurrentCommand(pageContext, getUniqueName(), ListCommand.RENDER);
        if (iterator.hasNext()) {
          Object obj = iterator.next();
          if (RhnListTagFunctions.isExpandable(obj)) {
            parentObject = obj;
          }
          currentObject = obj;
        } else {
          currentObject = null;
        }
        if (currentObject == null) {
          ListTagUtil.write(pageContext, "</tbody>");
          ListTagUtil.setCurrentCommand(pageContext, getUniqueName(), ListCommand.TBL_FOOTER);
        } else {
          ListTagUtil.write(pageContext, "<tr");
          renderRowClassAndId();

          ListTagUtil.write(pageContext, ">");
          pageContext.setAttribute(rowName, currentObject);
        }
      }
    } else if (haveTblFootersRendered) {
      retval = BodyTagSupport.SKIP_BODY;
    }
    return retval;
  }