You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by "Offiah Raymond, Slough" <Ra...@aniteps.com> on 2005/05/11 16:21:03 UTC

Foreach and dynamic forms

Hi there.

 

Wonder if someone could help me out with a small code problem.

 

I'm trying to build a dynamic form using Tapestry. Nothing to difficult; the
page can have any number of address blocks, that the user can add to, by
clicking on a 'more' button.

 

This submits the form, and adds a new entry to the list of entries, which
the user can then fill in.

 

When the page is rendered, the new address fields should appear on the page.

 

The code looks something like this:

 

--page-

 

    <component id="repeatingAddressSection" type="Foreach">

        <binding name="source" expression="postalAddresses"/>

        <binding name="index" expression="counter"/>

    </component>

 

As I said, after a submission, I add an empty element to the list of postal
addresses, then render it again

 

The HTML template section, looks like this ... :-)

 

<span jwcid="repeatingAddressSection">

    <span jwcid="@PostcodeSearch"
postalAddress="ognl:postalAddress[counter]"/>

</span>

<span jwcid="more"/>

 

The PostcodeSearch component, is just a series of fields for the address,
with a button for doing search lookups based on Postcode.

 

 

Now, what I've found is that if I have two PostcodeSearch components mounted
on a page, then they work OK. Pressing the postcode button will create a
list under the correct postcode field, from which I can select an address.

 

But if I add the components to the page using the @Foreach component; then
clicking on one postcode button, displays a list for every PostcodeSearch
component generated in the loop.

 

I had a look around the mailing list, and it looks like the problem is
caused by the way the @Foreach component works. I was expecting a separate
instance of Postcode object for each iteration of the loop. But apparently,
@Foreach generates ONE instance and just adds the same one three times.

 

It seems that the way I'm trying to do this, disagrees with the Tapestry
way; so could someone point me in the right direction? How should I go about
generating a dynamic form, where the number of elements cannot be fixed?

 

Thanks in advance.

 

 

Ray

 

 



Scanned for viruses by MessageLabs. The integrity and security of this message cannot be guaranteed. This email is intended for the named recipient only, and may contain confidential information and proprietary material. Any unauthorised use or disclosure is prohibited.