From issues-return-10149-apmail-struts-issues-archive=struts.apache.org@struts.apache.org Tue Jun 03 16:46:30 2008 Return-Path: Delivered-To: apmail-struts-issues-archive@locus.apache.org Received: (qmail 46105 invoked from network); 3 Jun 2008 16:46:30 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 3 Jun 2008 16:46:30 -0000 Received: (qmail 61450 invoked by uid 500); 3 Jun 2008 16:46:32 -0000 Delivered-To: apmail-struts-issues-archive@struts.apache.org Received: (qmail 61410 invoked by uid 500); 3 Jun 2008 16:46:32 -0000 Mailing-List: contact issues-help@struts.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@struts.apache.org Delivered-To: mailing list issues@struts.apache.org Received: (qmail 61401 invoked by uid 99); 3 Jun 2008 16:46:32 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Jun 2008 09:46:32 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.140] (HELO brutus.apache.org) (140.211.11.140) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Jun 2008 16:45:44 +0000 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 9F783234C12C for ; Tue, 3 Jun 2008 09:46:05 -0700 (PDT) Message-ID: <1547861887.1212511565651.JavaMail.jira@brutus> Date: Tue, 3 Jun 2008 09:46:05 -0700 (PDT) From: "T.J. Hill (JIRA)" To: issues@struts.apache.org Subject: [jira] Updated: (STR-3151) messagesPresent should not alter ActionMessages.accessed flag In-Reply-To: <1319840911.1212507065316.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/struts/browse/STR-3151?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] T.J. Hill updated STR-3151: --------------------------- Description: 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 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 was: 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, regarless 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 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 > 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 > > 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 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.