commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Arron Bates <ar...@keyboardmonkey.com>
Subject Re: [BeanUtils] Having a mapped property and indexed property with th e same name
Date Thu, 14 Feb 2002 08:19:23 GMT
I've found that it will never actually get back a 
MappedPropertyDescriptor. The logic in it invoking the mapped property 
seems to be out a bit.

I even sent a mail into the group and Struts-dev, but I think that 
people's efforts are focused elsewhere at the moment.

So I've hit the same wall but haven't had the time to fix the problem 
properly.
It's easy with a hack though (isn't everything? :).


Arron.


Guijt, Bart (fin) wrote:

>Hi all,
>
>I am having trouble using the PropertyUtils class in the BeanUtils package.
>In my classes I have a property Item defined like this:
>
>public class Foo
>{
>	private List items = new ArrayList();
>
>	public List getItems() { /* bla bla */ }
>	public void addItem( Bar newItem ) { /* bla bla */ }
>	// etc.
>	
>	/** Return an item by index */
>	public Bar getItem( int index )
>	{
>		return items.get( index );
>	}
>
>	/** Return an item by name */
>	public Bar getItem( String name )
>	{
>		for ( int i=0; i<items.size(); i++ )
>		{
>			Bar x = (Bar) items.get( i );
>			if ( x.getName().equals( name ) )
>			{
>				return x;
>			}
>		}
>		return null;
>	}
>}
>
>So there's a property 'items'  which is a collection and individual items
>can be retrieved using either the mapped version getItem(String) or the
>indexed version getItem(int).
>
>I use this class with the PropertyUtils like this (there is an existing Bar
>with name="helpme"):
>
>	// This one runs fine:
>	Object obj = PropertyUtils.getProperty( instanceOfFoo, "item[0]" );
>
>	// This one throws a NPE:
>	Object obj = PropertyUtils.getProperty( instanceOfFoo,
>"item(helpme)" );
>
>
>Digging through the PropertyUtils code I found out it relies on the
>getPropertyDescriptor() method for getting metadata on the specified bean
>(the Foo class in this case). This getProperrtyDescriptor() returns *either*
>a java.beans.IndexPropertyDescriptor or a
>org.apache.commons.beanutils.MappedPropertyDescriptor and the
>IndexedPropertyDescriptor takes precedence.
>
>My question is: Is this the intended behaviour? My property is both mapped
>and indexed, and using method overloading to support this seems to be the
>right way to do it.
>
>- Bart Guijt
>
>
>- Bart Guijt
>
>Ordina Finance BIS
>
>E: bguijt@finance.ordina.nl
>W: www.ordina-finance.nl
>
>A: Paalbergweg 46
>   1105 BW Amsterdam
>P: Postbus 94690
>   1090 GR Amsterdam
>
>T: +31 20 409 6660
>F: +31 20 409 6674
>M: +31 6 2705 0579
>
>
>--
>To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
>For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>
>



--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message