tags:

views:

165

answers:

2

I have a concrete class A that extends BaseA and implements InterfaceA. I want to loop through a list of A using either the base class or interface as the looping variable. Trying something like this:

<t:loop source="listOfA" value="propertyOfTypeBaseA">
    ${propertyOfTypeBaseA.someField}
</t:loop>

gives me an error "Could not find a coercion from type A to BaseA". The same thing happens when I set value to a property of type InterfaceA. I can get the loop to work if I use Object as the looping variable type, but then I can't access any of the fields on the concrete class or the interface.

It seems like Tapestry should know how to coerce from an object to an interface it implements, but I also tried contributing a coercion from A to BaseA/InterfaceA and it still gave me that error, even though it actually showed the coercion in the list.

Any ideas?

+3  A: 

The interface will work if it is not in a package that Tapestry manages. And I now know that the 'base' package is one that Tapestry manages in addition to pages and components. I had put my base class and interface in that package thinking they would be safe from Tapestry's classloader voodoo. After moving them out, I still needed to contribute a coercion for the base class, but not for the interface.

Brian Deterling
A: 

I was going to ramble on about BeanModel properties and contributing to DefaultDataTypeAnalyzer, thank god I didn't. Out of curiosity, could you show what a "coercion contribution" looks like? Thanks.

jtgameover
You can find a good example for a type coercer contribution in the Tapestry 5 documentation: http://tapestry.apache.org/tapestry5/tapestry-ioc/coerce.html.
Henning
Yes, that's exactly the one I copied to create mine.
Brian Deterling