You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Paul Stanton <pa...@mapshed.com.au> on 2010/11/24 03:57:10 UTC

grid containing multiple types of same interface

I'm trying to make a grid that is backed by a list of items which 
implement an interface, however it looks like the grid caches the 
concrete type of the first item and expects every other item to be of 
the same type.

Is there a way to avoid this behaviour?

Regards, Paul.

Caused by: java.lang.ClassCastException: package.entities.Type2 cannot 
be cast to package.entities.Type1
     at 
$PropertyConduit_12c7bbcb301.getRoot($PropertyConduit_12c7bbcb301.java)
     at $PropertyConduit_12c7bbcb301.get($PropertyConduit_12c7bbcb301.java)
     at 
org.apache.tapestry5.internal.services.CoercingPropertyConduitWrapper.get(CoercingPropertyConduitWrapper.java:36)
     at 
org.apache.tapestry5.corelib.base.AbstractPropertyOutput.readPropertyForObject(AbstractPropertyOutput.java:152)
     at 
org.apache.tapestry5.corelib.base.AbstractPropertyOutput.renderPropertyValue(AbstractPropertyOutput.java:132)
     at 
org.apache.tapestry5.corelib.components.GridCell.beginRender(GridCell.java:28)

public class Type1 implements MyInterface<A>
{....}

public class Type2 implements MyInterface<B>
{....}

public class MyPage
{
     public List<MyInterface<?>> getItems()
     {
         List<MyInterface<?>> list = new ArrayList<MyInterface<?>>();
         list.add(new Type1());
         list.add(new Type2());
         return list;
     }
}

MyPage.tml:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<t:layout xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd" 
xmlns:p="tapestry:parameter">

<t:grid source="items" />

</t:layout>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: grid containing multiple types of same interface

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Wed, 24 Nov 2010 20:27:51 -0200, Paul Stanton <pa...@mapshed.com.au>  
wrote:

> by 'manually create the model' do you mean 'create your own  
> implementation of GridModel' ?

No. Inject the BeanModelSource and use its createDisplayModel() method to  
get a GridModel instance.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: grid containing multiple types of same interface

Posted by Paul Stanton <pa...@mapshed.com.au>.
by 'manually create the model' do you mean 'create your own 
implementation of GridModel' ?

can you provide an example?

On 25/11/2010 12:50 AM, LLTYK wrote:
> You manually create the grid model, which lets you specifically tell it to
> use the interface.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: grid containing multiple types of same interface

Posted by LLTYK <LL...@mailinator.com>.
You manually create the grid model, which lets you specifically tell it to
use the interface.
-- 
View this message in context: http://tapestry-users.832.n2.nabble.com/grid-containing-multiple-types-of-same-interface-tp5769095p5770402.html
Sent from the Tapestry Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org