tapestry-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From psy...@t-online.de (John Meredith)
Subject Blocks and polymorphism
Date Mon, 01 Sep 2003 14:24:57 GMT
[This is a little OT ie. java related]


Whilst going through the list archives for something, I came across a
couple of references with regards to using blocks and polymorphism (most
notably from mindbridge). This got me thinking if I could use this to
maybe make things a little easier ... here's a brief description:

I have two classes called Product1 and Product2, both of which extend a
base class BaseProduct. In addition to the properties provided by
BaseProduct, each subclass naturally also has additional properties.

To enter in a new product, what I've been doing is creating a page for
each BaseProduct subclass. So far so good .. but a bit of a pain.

What I'd like to be able to do, is have one CreateProduct page which has
input fields for the BaseProduct properties and input fields for the
given subclass displayed depending on the given product subclass.
Something along the lines of:

<!-- HTML -->
<form jwcid="@Form">
    <input jwcid="baseProperty"/>

    <span jwcid="@RenderBlock" block="ognl:productType"/>

    <span jwcid="product1@block">
        <input jwcid="product1Field"/>

    <span jwcid="product2@block">
        <input jwcid="product2Field"/>

    <input type="@Submit"/>

<!-- Page spec -->
<property-specification name="product" type="BaseProduct"/>

<component id="product1Field" type="ValidField">
    <binding name="value" expression="product.propertyA"/>
    <binding name="validator" expression="beans.requiredString"/>
    <message-binding name="displayName" key="expires"/>

<component id="product2Field" type="ValidField">
    <binding name="value" expression="product.propertyB"/>
    <binding name="validator" expression="beans.requiredString"/>
    <message-binding name="displayName" key="expires"/>

I've tried implementing this, but run into the problem that Tapestry
(rightly) tries to parse the expression in the block, but "product"
doesn't have the associated property. Obviously, this is not a viable
solution :-)

So my 2 inexperienced-java-tapestry questions are:

1. Is something similar to this at all possible and if so could anyone
give me any pointers?
2. If not possible, why the reference to using blocks and polymorphism? 

Just curious. TIA,


John Meredith <psynix@t-online.de>

View raw message