You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "Niall Pemberton (JIRA)" <ji...@apache.org> on 2008/06/04 02:35:05 UTC

[jira] Commented: (STR-3151) messagesPresent should not alter ActionMessages.accessed flag

    [ https://issues.apache.org/struts/browse/STR-3151?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=44013#action_44013 ] 

Niall Pemberton commented on STR-3151:
--------------------------------------

Could you describe the scenario where this has caused a problem?

>From memory the ActionMessages's accessed flag is only used in the CacheMessages[1] / RemoveCachedMessages[2] commands and typically anyone using <html:messagesPresent> then goes on to do something with them.

I'm not objecting to this (yet) - but I would like to understand the use-case.

[1] http://svn.apache.org/repos/asf/struts/struts1/trunk/core/src/main/java/org/apache/struts/chain/commands/CacheMessages.java
[2] http://svn.apache.org/repos/asf/struts/struts1/trunk/core/src/main/java/org/apache/struts/chain/commands/RemoveCachedMessages.java

> messagesPresent 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
>            Assignee: Paul Benedict
>             Fix For: 1.4.0
>
>
> 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

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