Exemplo n.º 1
0
  protected void populateParams() {

    try {
      if (StringUtils.isNotBlank(minRows)) {
        this.setDynamicAttribute(null, "minRows", minRows);
      }
      if (StringUtils.isNotBlank(maxRows)) {
        this.setDynamicAttribute(null, "maxRows", maxRows);
      }
      if (StringUtils.isNotBlank(afterAdd)) {
        this.setDynamicAttribute(null, "afterAdd", afterAdd);
      }
    } catch (JspException e) {
      e.printStackTrace();
    }

    super.populateParams();

    DynamicTable uiBean = ((DynamicTable) component);
    if (id == null) {
      // 设置ID随机
      uiBean.setId("dynamictable_" + RandomStringUtils.randomAlphabetic(10));
    }
    if (cssClass == null) {
      uiBean.setCssClass("table table-striped table-condensed");
    }
  }
 /**
  * After tag body has been evaluated and buffered this creates and exposes the current
  * RequestContext. Delegates to {@link #doEndTagInternal()} for actual work.
  */
 @Override
 public final int doEndTag() throws JspException {
   try {
     // get request content available from pageContext
     this.requestContext =
         (RequestContext)
             this.pageContext.getAttribute(RequestContextAwareTag.REQUEST_CONTEXT_PAGE_ATTRIBUTE);
     // if request context is not specified, create empty request context and set it into
     // pageContext
     if (this.requestContext == null) {
       this.requestContext = new JspAwareRequestContext(this.pageContext);
       this.pageContext.setAttribute(
           RequestContextAwareTag.REQUEST_CONTEXT_PAGE_ATTRIBUTE, this.requestContext);
     }
     // do actual work of this tag
     return doEndTagInternal();
   } catch (JspException ex) {
     logger.error(ex.getMessage(), ex);
     throw ex;
   } catch (RuntimeException ex) {
     logger.error(ex.getMessage(), ex);
     throw ex;
   } catch (Exception ex) {
     logger.error(ex.getMessage(), ex);
     throw new JspTagException(ex.getMessage());
   }
 }
Exemplo n.º 3
0
 public void testWithInvalidList() throws Exception {
   this.tag.setPath("country");
   this.tag.setItems("${other}");
   this.tag.setItemValue("isoCode");
   try {
     this.tag.doStartTag();
     fail("Must not be able to use a non-Collection typed value as the value of 'items'");
   } catch (JspException expected) {
     String message = expected.getMessage();
     assertTrue(message.indexOf("items") > -1);
     assertTrue(message.indexOf("org.hdiv.beans.TestBean") > -1);
   }
 }
Exemplo n.º 4
0
  /**
   * Generate the required input tag, followed by the optional rendered text. Support for <code>
   * write</code> property since Struts 1.1.
   *
   * @exception JspException if a JSP exception has occurred
   * @see org.hdiv.dataComposer.IDataComposer#composeFormField(String, String, boolean, String)
   */
  public int doStartTag() throws JspException {

    try {
      String hiddenValue = value;
      Object lookupValue = null;

      if (value == null) {
        // locate and return the specified property of the specified bean
        lookupValue = TagUtils.getInstance().lookup(pageContext, name, property, null);

        if (lookupValue != null) {
          hiddenValue = lookupValue.toString();
        }
      }

      HttpServletRequest request = (HttpServletRequest) this.pageContext.getRequest();
      IDataComposer dataComposer = HDIVUtil.getDataComposer(request);
      this.encodedValue = dataComposer.composeFormField(prepareName(), hiddenValue, false, null);

      // Render the result to the output writer
      TagUtils.getInstance().write(this.pageContext, this.renderInputElement());

      // Is rendering the value separately requested?
      if (!write) {
        return (EVAL_BODY_TAG);
      }

      // Calculate the value to be rendered separately
      // * @since Struts 1.1
      String results = null;
      if (value != null) {
        results = TagUtils.getInstance().filter(value);
      } else {
        if (lookupValue == null) {
          results = "";
        } else {
          results = TagUtils.getInstance().filter(lookupValue.toString());
        }
      }

      // Render the result to the output writer
      TagUtils.getInstance().write(pageContext, results);
      return (EVAL_BODY_TAG);

    } catch (JspException e) {
      log.debug(e.getMessage());
      throw e;
    }
  }
 @Override
 public boolean isCustomizedFor(final Throwable t) {
   if (t instanceof JspException) {
     final JspException j = (JspException) t;
     if (j.getRootCause() != null) {
       return isCustomizedFor(j.getRootCause());
     }
   }
   if (t instanceof ServletException) {
     final ServletException s = (ServletException) t;
     if (s.getRootCause() != null) {
       return isCustomizedFor(s.getRootCause());
     }
   }
   return exceptionClass.isAssignableFrom(t.getClass());
 }
  public void testSimple() {
    BeanTag tag = new BeanTag();
    tag.setPageContext(pageContext);
    tag.setName("com.opensymphony.webwork.TestAction");

    try {
      tag.doStartTag();
      tag.component.addParameter("result", "success");

      assertEquals("success", stack.findValue("result"));
      // TestAction from bean tag, Action from execution and DefaultTextProvider
      assertEquals(3, stack.size());
      tag.doEndTag();
      assertEquals(2, stack.size());
    } catch (JspException ex) {
      ex.printStackTrace();
      fail();
    }

    request.verify();
    pageContext.verify();
  }
  /**
   * since the CCActionTable doesn't recognize 'unknown' tags, use a regular CCWizardWindowTag in
   * the table XML and swap its HTML with that our of special WizardWindowTag here.
   */
  public String endChildDisplay(ChildContentDisplayEvent ccde) throws ModelControlException {
    String childName = ccde.getChildName();

    String html = super.endChildDisplay(ccde);
    // if its one of our special wizards
    // i.e. name contains keyword "SamQFSWizard"
    if (childName.indexOf(Constants.Wizard.WIZARD_BUTTON_KEYWORD) != -1
        || childName.indexOf(Constants.Wizard.WIZARD_SCRIPT_KEYWORD) != -1) {
      // retrieve the html from a WizardWindowTag
      JspEndChildDisplayEvent event = (JspEndChildDisplayEvent) ccde;
      CCButtonTag sourceTag = (CCButtonTag) event.getSourceTag();
      Tag parentTag = sourceTag.getParent();

      // get the peer view of this tag
      View theView = getChild(childName);

      // instantiate the wizard tag
      WizardWindowTag tag = new WizardWindowTag();
      tag.setBundleID(sourceTag.getBundleID());
      tag.setDynamic(sourceTag.getDynamic());

      // Is this a script wizard tag?
      if (childName.indexOf(Constants.Wizard.WIZARD_SCRIPT_KEYWORD) != -1) {
        // This is a script wizard
        tag.setName(childName);
        tag.setWizardType(WizardWindowTag.TYPE_SCRIPT);
      }

      // try to retrieve the correct HTML from the tag
      try {
        html = tag.getHTMLStringInternal(parentTag, event.getPageContext(), theView);
      } catch (JspException je) {
        throw new IllegalArgumentException(
            "Error retrieving the " + "WizardWindowTag html : " + je.getMessage());
      }
    }

    return html;
  }
Exemplo n.º 8
0
  protected void populateParams() {
    // 此段落必须放在super.populateParams()之前
    try {
      if (StringUtils.isNotBlank(autoValidate)) {
        this.setDynamicAttribute(null, "autoValidate", autoValidate);
      }
    } catch (JspException e) {
      e.printStackTrace();
    }

    super.populateParams();
    UIBean uiBean = ((UIBean) component);

    if (id == null) {
      String formid = "form_" + RandomStringUtils.randomAlphabetic(10);
      uiBean.setId(formid);
      // 将id属性设置到pageContext中,便于前端JS代码进行对象分组控制
      pageContext.setAttribute("closestFormId", formid);
    }
    if (this.theme == null) {
      uiBean.setTheme("bootstrap");
    }
  }
Exemplo n.º 9
0
  /**
   * Formats the text to be displayed as the header by wraping it in a link if sorting is enabled.
   * Alt (hint) is localized, please define in your property file for messages the property
   * "sorting"
   *
   * @param columnInfo The ColumnInfo.
   * @param tableInfo The TableInfo.
   * @param info The ValueListInfo.
   * @return The formated HTML.
   */
  public String getHeaderLabel(
      ColumnInfo columnInfo, TableInfo tableInfo, ValueListInfo info, Map includeParameters) {

    ValueListConfigBean config = tableInfo.getConfig();
    Map parameters = new HashMap(includeParameters);

    if (columnInfo.getDefaultSort() != null) {
      // Get the current sort column and direction.
      String column = info.getSortingColumn();
      Integer direction = info.getSortingDirection();

      parameters.put(
          ValueListInfo.PAGING_NUMBER_PER + tableInfo.getId(),
          String.valueOf(info.getPagingNumberPer()));
      parameters.put(ValueListInfo.PAGING_PAGE + tableInfo.getId(), "1");
      parameters.put(
          ValueListInfo.SORT_COLUMN + tableInfo.getId(), columnInfo.getAdapterPropertyName());
      parameters.put(
          ValueListInfo.SORT_DIRECTION + tableInfo.getId(),
          ((columnInfo.getAdapterPropertyName().equals(column))
              ? (ValueListInfo.ASCENDING.equals(direction)
                  ? ValueListInfo.DESCENDING
                  : ValueListInfo.ASCENDING)
              : columnInfo.getDefaultSort()));

      if (info.isFocusEnabled()) {
        parameters.put(
            ValueListInfo.DO_FOCUS + tableInfo.getId(), info.isDoFocusAgain() ? "true" : "false");
        if (info.getFocusProperty() != null) {
          parameters.put(ValueListInfo.FOCUS_PROPERTY + tableInfo.getId(), info.getFocusProperty());
        }
        if (info.getFocusValue() != null) {
          parameters.put(ValueListInfo.FOCUS_VALUE + tableInfo.getId(), info.getFocusValue());
        }
      }

      StringBuffer sb = new StringBuffer();

      renderHeaderLabelLink(sb, columnInfo, tableInfo, info, parameters);

      if (columnInfo.getAdapterPropertyName().equals(column)) {
        if (usePadding) {
          sb.append("&nbsp;");
        }
        sb.append("<img src=\"")
            .append(getImageHome((HttpServletRequest) tableInfo.getPageContext().getRequest()))
            .append("/sort(");
        sb.append(
            (ValueListInfo.ASCENDING.equals(direction)
                ? ValueListInfo.DESCENDING
                : ValueListInfo.ASCENDING));
        sb.append(").png\" border=\"0\"/>");
      } else if (columnInfo.getDefaultSort() != null) {
        Locale locale =
            config
                .getLocaleResolver()
                .resolveLocale((HttpServletRequest) (tableInfo.getPageContext().getRequest()));
        String altSort;
        try {
          altSort =
              config
                  .getDisplayHelper()
                  .help(
                      tableInfo.getPageContext(),
                      config.getMessageSource().getMessage("sorting", null, "Sort", locale));
        } catch (JspException e) {
          LOGGER.error(
              "getHeaderLabel() - Error getting property 'sorting' : "
                  + e.getMessage()
                  + " Locale locale = "
                  + locale
                  + ", String column = "
                  + column
                  + " using defalt hint for sorting images.");

          altSort = "Sort";
        }

        sb.append(((usePadding) ? "&nbsp;" : ""))
            .append("<img alt=\"")
            .append(altSort)
            .append("\" src=\"")
            .append(getImageHome((HttpServletRequest) tableInfo.getPageContext().getRequest()))
            .append("/sort(null).png\" border=\"0\"/>");
      }

      return sb.toString();

    } else {
      return columnInfo.getTitle();
    }
  }