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 <[EMAIL PROTECTED]> 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: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
--
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]