Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 40016 invoked from network); 30 Aug 2004 00:04:42 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 30 Aug 2004 00:04:42 -0000 Received: (qmail 33394 invoked by uid 500); 30 Aug 2004 00:04:40 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 33279 invoked by uid 500); 30 Aug 2004 00:04:39 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 33264 invoked by uid 99); 30 Aug 2004 00:04:39 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [192.18.33.10] (HELO exchange.sun.com) (192.18.33.10) by apache.org (qpsmtpd/0.27.1) with SMTP; Sun, 29 Aug 2004 17:04:38 -0700 Received: (qmail 3420 invoked from network); 30 Aug 2004 00:06:20 -0000 Received: from localhost (HELO nagoya) (127.0.0.1) by nagoya.betaversion.org with SMTP; 30 Aug 2004 00:06:20 -0000 Message-ID: <1195473260.1093824380691.JavaMail.apache@nagoya> Date: Sun, 29 Aug 2004 17:06:20 -0700 (PDT) From: commons-dev@jakarta.apache.org To: commons-dev@jakarta.apache.org Subject: [jira] Updated: (JELLY-120) UseBean tag improvement In-Reply-To: <1877552333.1093109540056.JavaMail.apache@nagoya> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N The following issue has been updated: Updater: dion gillard (mailto:dion@apache.org) Date: Sun, 29 Aug 2004 5:05 PM Comment: I think this should be done for beta4 Changes: Fix Version changed to 1.0-beta-4 --------------------------------------------------------------------- For a full history of the issue, see: http://issues.apache.org/jira/browse/JELLY-120?page=history --------------------------------------------------------------------- View the issue: http://issues.apache.org/jira/browse/JELLY-120 Here is an overview of the issue: --------------------------------------------------------------------- Key: JELLY-120 Summary: UseBean tag improvement Type: Improvement Status: Unassigned Priority: Major Project: jelly Components: core / taglib.core Fix Fors: 1.0-beta-4 Versions: 1.0-beta-4 Assignee: Reporter: Hans Gilde Created: Sat, 21 Aug 2004 10:32 AM Updated: Sun, 29 Aug 2004 5:05 PM Description: It's sort of hard to extend UseBean because it will try to set all the tag attributes as bean properties. You can remove an attribute from the map, but that's annoying because then your subclasses don't see it. I added a couple of methods that let a subclass tell UseBean to ignore certain property names. So, those properties stay in the attribute map but don't cause errors in setting the bean. This is the first step to a patch to clean up the Swing ComponentTag so that it fails properly when one misspells a bean property. As long as everyone agrees to this method of ignoring attributes that aren't bean properties. Hans ########################## Index: UseBeanTag.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/jelly/src/java/org/apache/commons/jelly/tags/core/UseBeanTag.java,v retrieving revision 1.14 diff -u -r1.14 UseBeanTag.java --- UseBeanTag.java 24 Feb 2004 14:10:38 -0000 1.14 +++ UseBeanTag.java 20 Aug 2004 01:22:12 -0000 @@ -16,13 +16,15 @@ package org.apache.commons.jelly.tags.core; import java.lang.reflect.InvocationTargetException; +import java.util.HashMap; +import java.util.HashSet; import java.util.Map; +import java.util.Set; import org.apache.commons.beanutils.BeanUtils; - import org.apache.commons.jelly.JellyTagException; -import org.apache.commons.jelly.MissingAttributeException; import org.apache.commons.jelly.MapTagSupport; +import org.apache.commons.jelly.MissingAttributeException; import org.apache.commons.jelly.XMLOutput; import org.apache.commons.jelly.impl.BeanSource; @@ -50,6 +52,11 @@ /** the default class to use if no Class is specified */ private Class defaultClass; + + /**a Set of Strings of property names to ignore (remove from the + * Map of attributes before passing to ConvertUtils) + */ + private Set ignoreProperties; public UseBeanTag() { } @@ -74,7 +81,8 @@ public void doTag(XMLOutput output) throws JellyTagException { Map attributes = getAttributes(); String var = (String) attributes.get( "var" ); - Object classObject = attributes.remove( "class" ); + Object classObject = attributes.get( "class" ); + addIgnoreProperty("class"); try { // this method could return null in derived classes @@ -163,10 +171,15 @@ /** * Sets the properties on the bean. Derived tags could implement some custom * type conversion etc. + *

+ * This method ignores all property names in the Set returned by {@link #getIgnorePropertySet()}. */ protected void setBeanProperties(Object bean, Map attributes) throws JellyTagException { + Map attrsToUse = new HashMap(attributes); + attrsToUse.keySet().removeAll(getIgnorePropertySet()); + try { - BeanUtils.populate(bean, attributes); + BeanUtils.populate(bean, attrsToUse); } catch (IllegalAccessException e) { throw new JellyTagException("could not set the properties of the bean",e); } catch (InvocationTargetException e) { @@ -196,5 +209,26 @@ */ protected Class getDefaultClass() { return defaultClass; + } + + /** Adds a name to the Set of property names that will be skipped when setting + * bean properties. In other words, names added here won't be set into the bean + * if they're present in the attribute Map. + * @param name + */ + protected void addIgnoreProperty(String name) { + getIgnorePropertySet().add(name); + } + + /** Gets the Set of property names that should be ignored when setting the + * properties of the bean. + * @return + */ + protected Set getIgnorePropertySet() { + if (ignoreProperties == null) { + ignoreProperties = new HashSet(); + } + + return ignoreProperties; } } --------------------------------------------------------------------- JIRA INFORMATION: This message is automatically generated by JIRA. If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa If you want more information on JIRA, or have a bug to report see: http://www.atlassian.com/software/jira --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org