Issue Details (XML | Word | Printable)

Key: JELLY-120
Type: Improvement Improvement
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: dion gillard
Reporter: Hans Gilde
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Commons Jelly

UseBean tag improvement

Created: 21/Aug/04 05:32 PM   Updated: 31/Aug/04 05:01 AM
Return to search
Component/s: core / taglib.core
Affects Version/s: 1.0-beta-4
Fix Version/s: 1.0-beta-4

Time Tracking:
Not Specified

File Attachments:
  Size
Text File Licensed for inclusion in ASF works use-bean.txt 2004-08-30 12:32 AM Hans Gilde 5 kB
Zip Archive Licensed for inclusion in ASF works usebean-validate.zip 2004-08-31 04:15 AM Hans Gilde 2 kB

Resolution Date: 31/Aug/04 04:28 AM


 Description  « Hide
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 {@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;

}

}



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
dion gillard made changes - 30/Aug/04 12:05 AM
Field Original Value New Value
Fix Version/s 1.0-beta-4 [ 10215 ]
dion gillard made changes - 30/Aug/04 12:14 AM
Assignee dion gillard [ diongillard ]
dion gillard made changes - 30/Aug/04 12:30 AM
Status Open [ 1 ] In Progress [ 3 ]
Hans Gilde made changes - 30/Aug/04 12:32 AM
Attachment use-bean.txt [ 15050 ]
Hans Gilde made changes - 31/Aug/04 04:15 AM
Attachment usebean-validate.zip [ 15060 ]
dion gillard made changes - 31/Aug/04 04:28 AM
Status In Progress [ 3 ] Closed [ 6 ]
Resolution Fixed [ 1 ]