struts-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "T.J. Hill (JIRA)" <j...@apache.org>
Subject [jira] Created: (STR-3151) messagePresent should not alter ActionMessages.accessed flag
Date Tue, 03 Jun 2008 15:31:05 GMT
messagePresent should not alter ActionMessages.accessed flag
------------------------------------------------------------

                 Key: STR-3151
                 URL: https://issues.apache.org/struts/browse/STR-3151
             Project: Struts 1
          Issue Type: Bug
          Components: Taglibs
    Affects Versions: 1.3.8
         Environment: n/a
            Reporter: T.J. Hill



The html|nested:messagePresent tags set ActionMessage.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, regarless if the messages were truly consumed.

Below is the curent 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 two changes would be appropriate to resolve the issue.


1) Add an exists(String) method to ActionMessages:

    public boolean exists(String property)  {
        return messages.containsKey(property);
    }
    
2) Modify the condition(boolean) method in MesssagesPresentTag to call the existing ActionMessages.isEmpty()
[when property not specified] and the suggested ActionMessages.exists(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 +++
         boolean present = (property == null) ? !am.isEmpty() : am.exists(property);
         return (present == desired);
    }	
    
 Thanks - TH

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message