Esempio n. 1
0
  /**
   * Passes attribute information up to the parent TableTag.
   *
   * <p>When we hit the end of the tag, we simply let our parent (which better be a TableTag) know
   * what the user wants to do with this column. We do that by simple registering this tag with the
   * parent. This tag's only job is to hold the configuration information to describe this
   * particular column. The TableTag does all the work.
   *
   * @return int
   * @throws JspException if this tag is being used outside of a &lt;display:list...&gt; tag.
   * @see javax.servlet.jsp.tagext.Tag#doEndTag()
   */
  public int doEndTag() throws JspException {
    TableTag tableTag = getTableTag();

    MediaTypeEnum currentMediaType =
        (MediaTypeEnum) this.pageContext.findAttribute(TableTag.PAGE_ATTRIBUTE_MEDIA);
    if (currentMediaType != null && !MediaUtil.availableForMedia(this, currentMediaType)) {
      if (log.isDebugEnabled()) {
        log.debug("skipping column body, currentMediaType=" + currentMediaType);
      }
      return SKIP_BODY;
    }

    // add column header only once
    if (tableTag.isFirstIteration()) {
      addHeaderToTable(tableTag);
    }

    if (!tableTag.isIncludedRow()) {
      return super.doEndTag();
    }

    Cell cell = null;
    if (this.property == null && this.value != null) {
      cell = new Cell(value);
    } else if (this.property == null && this.bodyContent != null) {
      cell = new Cell(this.bodyContent.getString());
    }

    Object rowStyle = this.attributeMap.get(TagConstants.ATTRIBUTE_STYLE);
    Object rowClass = this.attributeMap.get(TagConstants.ATTRIBUTE_CLASS);
    if (rowStyle != null || rowClass != null) {
      HtmlAttributeMap perRowValues = new HtmlAttributeMap();
      if (rowStyle != null) {
        perRowValues.put(TagConstants.ATTRIBUTE_STYLE, rowStyle);
      }
      if (rowClass != null) {
        perRowValues.put(TagConstants.ATTRIBUTE_CLASS, rowClass);
      }
      if (cell == null) {
        cell = new Cell(null);
      }
      cell.setPerRowAttributes(perRowValues);
    }

    tableTag.addCell(cell != null ? cell : Cell.EMPTY_CELL);

    // cleanup non-attribute variables
    this.alreadySorted = false;

    return super.doEndTag();
  }
Esempio n. 2
0
  @Override
  public int doStartTag() throws JspException {
    int i = super.doStartTag();

    Tag parent = getParent();
    if (parent instanceof TableTag) {
      Tablecol col = (Tablecol) component;
      TableTag tbtag = (TableTag) parent;
      List<Tablecol> columns = tbtag.getColumns();
      int ci = tbtag.getColindex();
      if (ci > columns.size()) {
        ci = columns.size() - 1;
      }
      if (ci < 0) {
        ci = 0;
      }
      if (StrUtil.isNull(dataattribute) || StrUtil.isNull(tbtag.getCustColumns())) {
        columns.add(ci, col);
        tbtag.setColindex(ci + 1);
      } else {
        int idx = tbtag.getTablecol(dataattribute);
        if (idx >= 0) {
          tbtag.getColumns().remove(idx);
          tbtag.getColumns().add(idx, col);
          tbtag.setColindex(idx + 1);
        }
      }
    }
    return i;
  }
Esempio n. 3
0
  /** @see javax.servlet.jsp.tagext.Tag#doStartTag() */
  public int doStartTag() throws JspException {
    TableTag tableTag = getTableTag();
    if (tableTag == null) {
      throw new TagStructureException(getClass(), "column", "table");
    }

    // If the list is empty, do not execute the body; may result in NPE
    if (tableTag.isEmpty() || !tableTag.isIncludedRow()) {
      return SKIP_BODY;
    }

    MediaTypeEnum currentMediaType =
        (MediaTypeEnum) this.pageContext.findAttribute(TableTag.PAGE_ATTRIBUTE_MEDIA);
    if (!MediaUtil.availableForMedia(this, currentMediaType)) {
      return SKIP_BODY;
    }

    return super.doStartTag();
  }
  @Override
  public int doEndTag() throws JspException {

    TableTag parent = (TableTag) findAncestorWithClass(this, TableTag.class);

    // The tag is evaluated only once, at the first iteration
    if (parent.isFirstIteration()) {

      Option<?> option = DatatableOptions.findByName(name);

      if (option == null) {
        throw new JspException(
            "'" + name + "' is not a valid option. Please read the documentation.");
      } else {
        parent.getStagingOptions().put(option, value);
      }
    }

    return EVAL_PAGE;
  }
Esempio n. 5
0
  /**
   * Adds the current header to the table model calling addColumn in the parent table tag. This
   * method should be called only at first iteration.
   *
   * @param tableTag parent table tag
   * @throws DecoratorInstantiationException for error during column decorator instantiation
   * @throws ObjectLookupException for errors in looking up values
   */
  private void addHeaderToTable(TableTag tableTag)
      throws DecoratorInstantiationException, ObjectLookupException {
    // don't modify "title" directly
    String evalTitle = this.title;

    // title has precedence over titleKey
    if (evalTitle == null && (this.titleKey != null || this.property != null)) {
      // handle title i18n
      evalTitle =
          tableTag
              .getProperties()
              .geResourceProvider()
              .getResource(this.titleKey, this.property, tableTag, this.pageContext);
    }

    HeaderCell headerCell = new HeaderCell();
    headerCell.setHeaderAttributes((HtmlAttributeMap) this.headerAttributeMap.clone());
    headerCell.setHtmlAttributes((HtmlAttributeMap) this.attributeMap.clone());
    headerCell.setTitle(evalTitle);
    headerCell.setSortable(this.sortable);

    List<DisplaytagColumnDecorator> decorators = new ArrayList<DisplaytagColumnDecorator>();

    // handle multiple chained decorators, whitespace separated
    if (StringUtils.isNotEmpty(this.decorator)) {
      String[] decoratorNames = StringUtils.split(this.decorator);
      for (int j = 0; j < decoratorNames.length; j++) {
        decorators.add(
            tableTag
                .getProperties()
                .getDecoratorFactoryInstance()
                .loadColumnDecorator(this.pageContext, decoratorNames[j]));
      }
    }

    // "special" decorators
    if (this.escapeXml) {
      decorators.add(EscapeXmlColumnDecorator.INSTANCE);
    }
    if (this.autolink) {
      decorators.add(AutolinkColumnDecorator.INSTANCE);
    }
    if (StringUtils.isNotBlank(this.format)) {
      decorators.add(
          new MessageFormatColumnDecorator(this.format, tableTag.getProperties().getLocale()));
    }

    headerCell.setColumnDecorators(
        decorators.toArray(new DisplaytagColumnDecorator[decorators.size()]));

    headerCell.setBeanPropertyName(this.property);
    headerCell.setShowNulls(this.nulls);
    headerCell.setMaxLength(this.maxLength);
    headerCell.setMaxWords(this.maxWords);
    headerCell.setGroup(this.group);
    headerCell.setSortProperty(this.sortProperty);
    headerCell.setTotaled(this.totaled);

    Comparator<Object> headerComparator =
        (comparator != null) ? comparator : tableTag.getProperties().getDefaultComparator();

    headerCell.setComparator(headerComparator);
    headerCell.setDefaultSortOrder(this.defaultorder);
    headerCell.setSortName(this.sortName);

    // href and parameter, create link
    if (this.href != null) {
      Href colHref;

      // empty base url, use href with parameters from parent table
      if (StringUtils.isEmpty(this.href.getBaseUrl())) {
        colHref = (Href) tableTag.getBaseHref().clone();
      } else {
        colHref = (Href) this.href.clone();
      }

      if (this.paramId != null) {
        // parameter value is in a different object than the iterated one
        if (this.paramName != null || this.paramScope != null) {
          // create a complete string for compatibility with previous version before expression
          // evaluation.
          // this approach is optimized for new expressions, not for previous property/scope
          // parameters
          StringBuffer expression = new StringBuffer();

          // append scope
          if (StringUtils.isNotBlank(this.paramScope)) {
            expression.append(this.paramScope).append("Scope.");
          }

          // base bean name
          if (this.paramId != null) {
            expression.append(this.paramName);
          } else {
            expression.append(tableTag.getName());
          }

          // append property
          if (StringUtils.isNotBlank(this.paramProperty)) {
            expression.append('.').append(this.paramProperty);
          }

          // evaluate expression.
          // note the value is fixed, not based on any object created during iteration
          // this is here for compatibility with the old version mainly
          Object paramValue = tableTag.evaluateExpression(expression.toString());

          // add parameter
          colHref.addParameter(this.paramId, paramValue);
        } else {
          // set id
          headerCell.setParamName(this.paramId);

          // set property
          headerCell.setParamProperty(this.paramProperty);
        }
      }

      // sets the base href
      headerCell.setHref(colHref);
    }

    tableTag.addColumn(headerCell);

    if (log.isDebugEnabled()) {
      log.debug("columnTag.addHeaderToTable() :: first iteration - adding header " + headerCell);
    }
  }
Esempio n. 6
0
 @Override
 protected void populateParams() {
   Tablecol col = (Tablecol) component;
   col.setId(id);
   col.setType(type);
   col.setMxevent_desc(mxevent_desc);
   col.setMxevent(mxevent);
   col.setMxevent_disabled(mxevent_disabled);
   col.setDataattribute(dataattribute);
   col.setLookup(lookup);
   col.setLookupWidth(lookupWidth);
   col.setLookupHeight(lookupHeight);
   col.setLookupWrite(lookupWrite);
   col.setLinkedcontrolid(linkedcontrolid);
   col.setMxevent_icon(mxevent_icon);
   col.setFilterable(filterable);
   col.setFiltername(filtername);
   col.setSortable(sortable);
   col.setSortname(sortname);
   col.setStartHtml(startHtml);
   col.setHtml(html);
   col.setRender(render);
   col.setVisibleHead(visibleHead);
   col.setFormat(format);
   col.setTable(table);
   col.setInputsize(inputsize);
   col.setMaxlength(maxlength);
   col.setWidth(width);
   col.setHeight(height);
   col.setNote(note);
   col.setReadonly(readonly);
   col.setSecondAttributes(secondAttributes);
   col.setDataname(dataname);
   JxParams jparam = BeanUtil.getJxParams();
   if (jparam != null) {
     if ("comtop".equalsIgnoreCase(urlType)) {
       col.setUrlType(jparam.getComtopUrl());
     } else if ("report".equalsIgnoreCase(urlType)) {
       col.setUrlType(jparam.getReportUrl());
     } else {
       col.setUrlType(urlType);
     }
   } else {
     col.setUrlType(urlType);
   }
   col.setUrlParamName(urlParamName);
   col.setUrlParamValue(urlParamValue);
   transformUrlParams(); // 转换所有参数的值
   col.setAllUrlParams(allUrlParams);
   col.setUrlTarget(urlTarget);
   col.setTitle(title);
   col.setAlign(align);
   col.setDataDisplay(dataDisplay);
   col.setVisible(visible);
   col.setDescdataattribute(descdataattribute);
   Tag tag = findAncestorWithClass(this, TableTag.class);
   if (tag != null && dataattribute != null) {
     TableTag ttag = (TableTag) tag;
     JboSetIFace jboset = ttag.getJboset();
     if (jboset != null) {
       try {
         Object jo = jboset.getJxAttribute(dataattribute.toUpperCase());
         if (jo != null) {
           jxattribute = (JxAttribute) jo;
           col.setJxattribute(jxattribute);
           for (JboIFace jbo : jboset.getJbolist()) {
             if (null != jbo) {
               if (!"TRUE".equalsIgnoreCase(required)) {
                 required = String.valueOf(jbo.isRequired(dataattribute));
               } else {
                 jbo.setRequired(dataattribute, true);
               }
             }
           }
         }
       } catch (Exception e) {
         LOG.error(e.getMessage(), e);
       }
     }
   }
   super.populateParams();
 }