Message: The following issue has been closed.
Resolver: dion gillard Date: Mon, 30 Aug 2004 9:28 PM I made minor changes to the patch: - use Properties instead of Props - remove use of Jelly junit taglib, and put asserts back in the code - added license for new file --------------------------------------------------------------------- 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: Closed Priority: Major Resolution: FIXED Project: jelly Components: core / taglib.core Fix Fors: 1.0-beta-4 Versions: 1.0-beta-4 Assignee: dion gillard Reporter: Hans Gilde Created: Sat, 21 Aug 2004 10:32 AM Updated: Mon, 30 Aug 2004 9:28 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. + * <p/> + * This method ignores all property names in the Set returned by [EMAIL PROTECTED] #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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]