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

messagesPresent should not alter ActionMessages.accessed flag

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Won't Fix
    • Affects Version/s: 1.3.8
    • Fix Version/s: None
    • Component/s: Tag Libraries
    • Labels:
      None
    • Environment:
      n/a

      Description

      20080603 12:53

      The html|nested:messagesPresent tags set ActionMessages.accessed flag to true when interrogating.

      Currently, MessagesPresentTag calls the methods get() and get(String) of ActionMessages to determine if any messages exist. However, both get(...) methods in ActionMessages set the accessed field to true. So any subsequent call to ActionMessages.isAccessed() by external code will get true, regardless if the messages were truly consumed.

      Below is the current condition method in MessagesPresentTag:

      protected boolean condition(boolean desired)
      throws JspException {
      ActionMessages am = null;

      String key = name;

      if ((message != null) && "true".equalsIgnoreCase(message))

      { key = Globals.MESSAGE_KEY; }

      try

      { am = TagUtils.getInstance().getActionMessages(pageContext, key); }

      catch (JspException e)

      { TagUtils.getInstance().saveException(pageContext, e); throw e; }

      Iterator iterator = (property == null) ? am.get() : am.get(property); // HERE is the issue – using get(...) methods will cause the accessed property of ActionMessages to be set to true.

      return (iterator.hasNext() == desired);
      }

      Perhaps the following change would be appropriate to resolve the issue.

      Modify the condition(boolean) method in MesssagesPresentTag to call the existing ActionMessages.size() [when property not specified] and the exsiting ActionMessages.size(String) method above [when property specified]:

      protected boolean condition(boolean desired)
      throws JspException {
      ActionMessages am = null;

      String key = name;

      if ((message != null) && "true".equalsIgnoreCase(message))

      { key = Globals.MESSAGE_KEY; }

      try

      { am = TagUtils.getInstance().getActionMessages(pageContext, key); }

      catch (JspException e)

      { TagUtils.getInstance().saveException(pageContext, e); throw e; }

      // — CURRENT —
      //Iterator iterator = (property == null) ? am.get() : am.get(property);
      //return (iterator.hasNext() == desired);

      // +++ SUGGESTED +++
      int present = (property == null) ? am.size() : am.size(property);
      return ((present > 0) == desired);
      }

      Thanks - TH

        Attachments

          Activity

            People

            • Assignee:
              pbenedict Paul Benedict
              Reporter:
              thill T.J. Hill
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: