Search code examples
javatapestry

How do I use a base class or interface with a grid or loop component in Tapestry 5?


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?


Solution

  • 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.