You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Onno Scheffers <on...@AtomicDigitalStudios.com> on 2005/11/01 20:14:13 UTC

Problem with T4 and Generics

I'm trying to use Generics to take away most of the plumbing code in a 
typical CRUD application, like I used to do with Tapestry3.
I basically set up my own base-page for the different edit-screens that 
looks something like this:

public abstract class ItemPage<K, I> extends BasePage [...] {
   public abstract K getKey();
   public abstract void setKey(K key);
   public abstact I getItem();
   public abstract void setItem(I item);

   // Subclasses implement these:
   public abstract I fetchItem(K key);
   public abstract void populatePageProperties(I item);
   public abstract K updateItem(IRequestCycle cycle, I item);
   public abstract K addItem(IRequestCycle cycle, K key);
   public abstract void deleteItem(IRequestCycle cycle, I item);
}

It handles most of the repetative code that each page needs and simply 
calls some methods for handling the logic that does differ for each page:

public abstract class EditUserPage extends ItemPage<Integer, User> {
   public User fetchItem(Integer key) { [...] }
   public void populatePageProperties(User user) { [...] }
   public Integer updateItem(IRequestCycle cycle, User user) { [...] }
   public Integer addItem(IRequestCycle cycle, Integer key) { [...] }
   public void deleteItem(IRequestCycle cycle, User user) { [...] }
}

I get a ClassCastException though because Tapestry tries to convert the 
numeric user-input for the key-field into a Long, while an Integer is 
expected by the subclass.
Tapestry is not written for Java 5, so I'm guessing it won't look at the 
generic type and thus only sees an 'Object' as the return-type, which 
might confuse things (please correct me if I'm wrong).

I was hoping I could somehow tell Tapestry to use an Integer in classes 
where the key is an Integer, Strings where the key is a String, etc.

In Tapestry 3 I could at least provide a 'type' in a 
<property-specification> of the page-file, which is not possible with 
the new <property> tag anymore. Has anyone else done something like this 
with Tapestry 4?

Regards,

Onno Scheffers


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


Re: Problem with T4 and Generics

Posted by Scott Russell <sc...@hotmail.com>.
On Wed 2 November 2005 07:07, Onno Scheffers wrote:
> >I'm not sure how much of the generics type information is carried
> >forward to runtime;
>
> Basically all of it....

As I understand it, no generics info gets carried forward to runtime, because 
the JDK5 implementation of generics implements 'erasure', which means the 
generic type information is erased at compile time, so that compiled classes 
are runtime compatible with older JREs. Thus, there is no way to dynamically 
discover generic type info at runtime, for instance, which is a real pain.

-Scott

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


Re: Problem with T4 and Generics

Posted by Onno Scheffers <on...@AtomicDigitalStudios.com>.
>I'm not sure how much of the generics type information is carried
>forward to runtime;
>
Basically all of it, but supporting it does indeed create dependancies 
on Java5 and that was not what I was after, since I understand that 
would have a huge impact on backward compatibility. What I am looking 
for is for a work-around: A way to define the type for the key in each 
subclass like it used to be possible for T3. That way the base class can 
still use generics, but the developer is responsible for defining the 
proper type in the sub-pages' property-specification to override the 
default 'Object'-type?

>... and require JDK 1.5 for Tapestry, something that sends people into fits when you even suggest it.
>  
>
I can imagine, although I would personally never want to look back to 
older VM's anymore for web-development  :oP

Regards,

Onno Scheffers

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


Re: Problem with T4 and Generics

Posted by Sergei Dubov <sd...@gmail.com>.
But nothing from generics is carried forward to runtime. Generics is 
meant to be compile-time fiction. It is all gone through Erasure.

Serge.

Howard Lewis Ship wrote:
> I'm not sure how much of the generics type information is carried
> forward to runtime; further, unlike the "slap it on the side"
> annoation support, support for generic pages and components would
> require some re-work in the core code ... and require JDK 1.5 for
> Tapestry, something that sends people into fits when you even suggest
> it.
> 
> On 11/1/05, Onno Scheffers <on...@atomicdigitalstudios.com> wrote:
> 
>>I'm trying to use Generics to take away most of the plumbing code in a
>>typical CRUD application, like I used to do with Tapestry3.
>>I basically set up my own base-page for the different edit-screens that
>>looks something like this:
>>
>>public abstract class ItemPage<K, I> extends BasePage [...] {
>>   public abstract K getKey();
>>   public abstract void setKey(K key);
>>   public abstact I getItem();
>>   public abstract void setItem(I item);
>>
>>   // Subclasses implement these:
>>   public abstract I fetchItem(K key);
>>   public abstract void populatePageProperties(I item);
>>   public abstract K updateItem(IRequestCycle cycle, I item);
>>   public abstract K addItem(IRequestCycle cycle, K key);
>>   public abstract void deleteItem(IRequestCycle cycle, I item);
>>}
>>
>>It handles most of the repetative code that each page needs and simply
>>calls some methods for handling the logic that does differ for each page:
>>
>>public abstract class EditUserPage extends ItemPage<Integer, User> {
>>   public User fetchItem(Integer key) { [...] }
>>   public void populatePageProperties(User user) { [...] }
>>   public Integer updateItem(IRequestCycle cycle, User user) { [...] }
>>   public Integer addItem(IRequestCycle cycle, Integer key) { [...] }
>>   public void deleteItem(IRequestCycle cycle, User user) { [...] }
>>}
>>
>>I get a ClassCastException though because Tapestry tries to convert the
>>numeric user-input for the key-field into a Long, while an Integer is
>>expected by the subclass.
>>Tapestry is not written for Java 5, so I'm guessing it won't look at the
>>generic type and thus only sees an 'Object' as the return-type, which
>>might confuse things (please correct me if I'm wrong).
>>
>>I was hoping I could somehow tell Tapestry to use an Integer in classes
>>where the key is an Integer, Strings where the key is a String, etc.
>>
>>In Tapestry 3 I could at least provide a 'type' in a
>><property-specification> of the page-file, which is not possible with
>>the new <property> tag anymore. Has anyone else done something like this
>>with Tapestry 4?
>>
>>Regards,
>>
>>Onno Scheffers
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>
>>
> 
> 
> 
> --
> Howard M. Lewis Ship
> Independent J2EE / Open-Source Java Consultant
> Creator, Jakarta Tapestry
> Creator, Jakarta HiveMind
> 
> Professional Tapestry training, mentoring, support
> and project work.  http://howardlewisship.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 
> 

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


Re: Problem with T4 and Generics

Posted by Howard Lewis Ship <hl...@gmail.com>.
I'm not sure how much of the generics type information is carried
forward to runtime; further, unlike the "slap it on the side"
annoation support, support for generic pages and components would
require some re-work in the core code ... and require JDK 1.5 for
Tapestry, something that sends people into fits when you even suggest
it.

On 11/1/05, Onno Scheffers <on...@atomicdigitalstudios.com> wrote:
> I'm trying to use Generics to take away most of the plumbing code in a
> typical CRUD application, like I used to do with Tapestry3.
> I basically set up my own base-page for the different edit-screens that
> looks something like this:
>
> public abstract class ItemPage<K, I> extends BasePage [...] {
>    public abstract K getKey();
>    public abstract void setKey(K key);
>    public abstact I getItem();
>    public abstract void setItem(I item);
>
>    // Subclasses implement these:
>    public abstract I fetchItem(K key);
>    public abstract void populatePageProperties(I item);
>    public abstract K updateItem(IRequestCycle cycle, I item);
>    public abstract K addItem(IRequestCycle cycle, K key);
>    public abstract void deleteItem(IRequestCycle cycle, I item);
> }
>
> It handles most of the repetative code that each page needs and simply
> calls some methods for handling the logic that does differ for each page:
>
> public abstract class EditUserPage extends ItemPage<Integer, User> {
>    public User fetchItem(Integer key) { [...] }
>    public void populatePageProperties(User user) { [...] }
>    public Integer updateItem(IRequestCycle cycle, User user) { [...] }
>    public Integer addItem(IRequestCycle cycle, Integer key) { [...] }
>    public void deleteItem(IRequestCycle cycle, User user) { [...] }
> }
>
> I get a ClassCastException though because Tapestry tries to convert the
> numeric user-input for the key-field into a Long, while an Integer is
> expected by the subclass.
> Tapestry is not written for Java 5, so I'm guessing it won't look at the
> generic type and thus only sees an 'Object' as the return-type, which
> might confuse things (please correct me if I'm wrong).
>
> I was hoping I could somehow tell Tapestry to use an Integer in classes
> where the key is an Integer, Strings where the key is a String, etc.
>
> In Tapestry 3 I could at least provide a 'type' in a
> <property-specification> of the page-file, which is not possible with
> the new <property> tag anymore. Has anyone else done something like this
> with Tapestry 4?
>
> Regards,
>
> Onno Scheffers
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>


--
Howard M. Lewis Ship
Independent J2EE / Open-Source Java Consultant
Creator, Jakarta Tapestry
Creator, Jakarta HiveMind

Professional Tapestry training, mentoring, support
and project work.  http://howardlewisship.com

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