Uploaded image for project: 'Struts 1'
  1. Struts 1
  2. STR-3155

TextTag enhancement, nameprefix, nameproperty, doErrorsExist()

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • None
    • None
    • Tag Libraries
    • None

    Description

      This issue depends on the following issue: https://issues.apache.org/jira/browse/VALIDATOR-265

      As I want to use the errorStyle attribute for the text tag I wrote my own TextTag class and enhanced it with the two variables nameprefix and nameproperty. If both exist i build the name with concatenating the two values, otherwise i call the prepareName() method.

      <pc:text errorStyle="..." errorKey="..." name="name" property="mobile" nameprefix="sms_" nameproperty="email" />

      protected String prepareNamePlusPrefix() throws JspException {
      String res = null;
      if (this.nameprefix == null || 0 == this.nameprefix.trim().length())

      { res = super.prepareName(); }

      else {
      res = this.nameprefix.trim();
      if (this.nameproperty != null)

      { Object valueName = TagUtils.getInstance().lookup(pageContext, name, this.nameproperty, null); res += valueName.toString(); }

      else

      { res += super.prepareName(); }

      }
      return res;
      }

      When validation fails and I add an Error with property "sms_email" this property also has to be checked in the doErrosExist() method:

      protected boolean doErrorsExist() throws JspException {
      boolean errorsExist = false;
      if ((getErrorStyleId() != null) || (getErrorStyle() != null) || (getErrorStyleClass() != null)) {
      if (this.nameprefix == null || 0 == this.nameprefix.trim().length())

      { return super.doErrorsExist(); }

      String actualName = prepareNamePlusPrefix();

      if (actualName != null)

      { ActionMessages errors = TagUtils.getInstance().getActionMessages(pageContext, GUIConstants.ERRORS_KEY + GUIConstants.PREV); errorsExist = ((errors != null) && (errors.size(actualName) > 0)); }

      }
      return errorsExist;
      }

      Attachments

        Activity

          People

            Unassigned Unassigned
            mstricker Mark Stricker
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: