You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by danrwilliams <da...@yahoo.co.uk> on 2010/09/10 23:17:26 UTC
Generics problem with Grid row parameter
Hi,
I am trying to standardise the way our developers code a page class that
uses a Grid component. Part of this process is defining an interface that
contains the get/set methods for the property used in the row parameter of
the Grid component.
Since the data used in any Grid in our project will always extend from a
specific super-type, I have created a bounded generic interface to give type
safety to the get/set methods in the page class.
The problem is, Tapestry 5.1.0.5 doesn't seem to honour this.
I'll try to illustrate..
Our code looks something like this;
class MyPageClass implements MyInterface<MyGridRowType> {
...
...
@Override
public MyGridRowType getRow() {...}
@Override
public void setRow(MyGridRowType row) {...}
...
}
interface MyInterface<T extends GridRowSupertype> {
T getRow():
void setRow(T row):
}
interface GridRowSupertype {
String getStringA();
}
class MyGridRowType implements GridRowSupertype {
@Override
public String getStringA() {...}
public String getStringB() {...}
}
Now, in the Grid component in our template file, if I try to use
'${row.stringb}' Tapestry throws an exception saying;
"...Class GridRowSupertype does not contain a property named 'stringb'...
...Available properties: stringa..."
Even though this is technically correct, Tapestry is referencing the
super-type and not the sub-type supplied by the page class. The return type
on the getRow() method in the page class is MyGridRowType, which does
contain the required method (getStringB).
I have confirmed this by simply removing the interface 'MyInterface' from
the page class and everything works fine.
Any suggestions?
Thanks,
Dan
--
View this message in context: http://tapestry.1045711.n5.nabble.com/Generics-problem-with-Grid-row-parameter-tp2835598p2835598.html
Sent from the Tapestry - User 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
Re: Generics problem with Grid row parameter
Posted by Josh Canfield <jo...@gmail.com>.
Ok, here is my test, which is working in the latest generics code.
// class MyPageClass implements MyInterface<MyGridRowType> {
public class GridGenericSourceDemo implements GenericGridPage<Person> {
@Component
private Grid grid;
@Inject
@Property
private GenericDatabase<Person> personDatabase;
public Person getRow() {}
public void setRow(Person person) {}
}
// interface MyInterface<T extends GridRowSupertype> {
public interface GenericGridPage<T extends GenericDatabaseItem> {
}
// interface GridRowSupertype {
public interface GenericDatabaseItem<T> extends Cloneable
// class MyGridRowType implements GridRowSupertype {
public class Person implements GenericDatabaseItem<Person>
GridGenericSourceDemo.tml contains
<table t:id="grid" source="personDatabase.findAll()" row="row">
<t:parameter name="nameCell">The Name ${row.name}</t:parameter>
</table>
Josh
On Fri, Sep 10, 2010 at 2:17 PM, danrwilliams
<da...@yahoo.co.uk> wrote:
>
> Hi,
>
> I am trying to standardise the way our developers code a page class that
> uses a Grid component. Part of this process is defining an interface that
> contains the get/set methods for the property used in the row parameter of
> the Grid component.
>
> Since the data used in any Grid in our project will always extend from a
> specific super-type, I have created a bounded generic interface to give type
> safety to the get/set methods in the page class.
>
> The problem is, Tapestry 5.1.0.5 doesn't seem to honour this.
>
> I'll try to illustrate..
>
> Our code looks something like this;
>
> class MyPageClass implements MyInterface<MyGridRowType> {
> ...
> ...
> @Override
> public MyGridRowType getRow() {...}
>
> @Override
> public void setRow(MyGridRowType row) {...}
>
> ...
> }
>
> interface MyInterface<T extends GridRowSupertype> {
>
> T getRow():
>
> void setRow(T row):
> }
>
> interface GridRowSupertype {
> String getStringA();
> }
>
> class MyGridRowType implements GridRowSupertype {
>
> @Override
> public String getStringA() {...}
>
> public String getStringB() {...}
> }
>
> Now, in the Grid component in our template file, if I try to use
> '${row.stringb}' Tapestry throws an exception saying;
>
> "...Class GridRowSupertype does not contain a property named 'stringb'...
> ...Available properties: stringa..."
>
> Even though this is technically correct, Tapestry is referencing the
> super-type and not the sub-type supplied by the page class. The return type
> on the getRow() method in the page class is MyGridRowType, which does
> contain the required method (getStringB).
>
> I have confirmed this by simply removing the interface 'MyInterface' from
> the page class and everything works fine.
>
> Any suggestions?
>
> Thanks,
> Dan
>
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/Generics-problem-with-Grid-row-parameter-tp2835598p2835598.html
> Sent from the Tapestry - User 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
>
>
--
--
http://www.bodylabgym.com - a private, by appointment only, one-on-one
health and fitness facility.
--
http://www.ectransition.com - Quality Electronic Cigarettes at a
reasonable price!
--
TheDailyTube.com. Sign up and get the best new videos on the internet
delivered fresh to your inbox.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Generics problem with Grid row parameter
Posted by danrwilliams <da...@yahoo.co.uk>.
Thanks for the response. It's good to know this issue is a valid use case!
I'll live without the interface for now.
Thanks again,
Dan
--
View this message in context: http://tapestry.1045711.n5.nabble.com/Generics-problem-with-Grid-row-parameter-tp2835598p2835816.html
Sent from the Tapestry - User 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
Re: Generics problem with Grid row parameter
Posted by Josh Canfield <jo...@gmail.com>.
The generics support in 5.1 is pretty limited. I've implemented a patch for 5.2 that should solve your problem which will be checked into the trunk soon. Since you've provided a good use case I'll add it to the unit tests when I get to a computer. I'm not sure that it will be back-ported to 5.1 (is generics support a feature or bug fix?)
-- Josh
On Sep 10, 2010, at 2:17 PM, danrwilliams <da...@yahoo.co.uk> wrote:
>
> Hi,
>
> I am trying to standardise the way our developers code a page class that
> uses a Grid component. Part of this process is defining an interface that
> contains the get/set methods for the property used in the row parameter of
> the Grid component.
>
> Since the data used in any Grid in our project will always extend from a
> specific super-type, I have created a bounded generic interface to give type
> safety to the get/set methods in the page class.
>
> The problem is, Tapestry 5.1.0.5 doesn't seem to honour this.
>
> I'll try to illustrate..
>
> Our code looks something like this;
>
> class MyPageClass implements MyInterface<MyGridRowType> {
> ...
> ...
> @Override
> public MyGridRowType getRow() {...}
>
> @Override
> public void setRow(MyGridRowType row) {...}
>
> ...
> }
>
> interface MyInterface<T extends GridRowSupertype> {
>
> T getRow():
>
> void setRow(T row):
> }
>
> interface GridRowSupertype {
> String getStringA();
> }
>
> class MyGridRowType implements GridRowSupertype {
>
> @Override
> public String getStringA() {...}
>
> public String getStringB() {...}
> }
>
> Now, in the Grid component in our template file, if I try to use
> '${row.stringb}' Tapestry throws an exception saying;
>
> "...Class GridRowSupertype does not contain a property named 'stringb'...
> ...Available properties: stringa..."
>
> Even though this is technically correct, Tapestry is referencing the
> super-type and not the sub-type supplied by the page class. The return type
> on the getRow() method in the page class is MyGridRowType, which does
> contain the required method (getStringB).
>
> I have confirmed this by simply removing the interface 'MyInterface' from
> the page class and everything works fine.
>
> Any suggestions?
>
> Thanks,
> Dan
>
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/Generics-problem-with-Grid-row-parameter-tp2835598p2835598.html
> Sent from the Tapestry - User 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
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org