You can put a Form inside a Loop (over a Person list I presume in your
case), and Tapestry will take care of rendering multiple forms.  You will
have a single t:id for the form, and Tapestry will take care of generating
unique id's based on that.  Look in to the "context" parameter of the form
as an alternative to your hidden field idea.


On Sun, Aug 7, 2011 at 8:39 AM, dkeenan <david_siedle...@yahoo.co.uk> wrote:

> Hi there. I have a page on which I want to have a number of forms, one for
> each person. The forms will have forename, surname, etc... the usual
> fields.
>
> However, I wont know how many person forms I want on the page until
> runtime.
> At the moment it seems that I need to have a @Component on my page class
> for
> each form like this...
>
>        @Component
>        private Form personForm;
>
> And also a property for each form field...
>
> @Property
> @Validate("required")
> private String surname;
>
> If I add two person forms to my page, it looks like I will need to add
> extra
> components to my page class code. But this won't work if I want to make the
> number of forms on the page flexible as it will be hard coded wont it?
>
> Is there no way that I can have many forms on the same TML template, with
> the same name... and which ever one gets submitted, is the one that gets
> processed by the page class?
>
> If I could do this, all I need to do is add a hidded ID field to each form
> to determine which user to update in the database. But this doesnt seem
> possible. If I try to add 2 forms with the same t:id values in the TML
> file,
> I get this error...
>
> Exception assembling embedded component 'personForm' (of type
> org.apache.tapestry5.corelib.components.Form, within MyPage): Component
> MyPage already contains a child component with id 'personForm'
>
>
> Here is my page class code...
>
> public class MyPage {
>
>        @Component
>        private Form personForm;
>
>        @Property
>        @Validate("required")
>        private String forename;
>
>        @Property
>        @Validate("required")
>        private String surname;
>
>        @Property
>        private String personId; //Hidden form field to determine which
> person to
> update
>
>
>
> Here is the TML that I am using...
>
>  <form name="personForm" id="personForm" t:id="personForm">
>              <p>
>                <input type="hidden" name="personid" id="personid"
> t:id="personid" t:type="personid" t:value="//value set as person id" />
>              </p>
>              <p>
>                <label for="forename" class="label">Forename:</label>
>                <input type="text" name="forename" id="forename"
> t:id="forename" t:type="TextField" t:value="forename" />
>              </p>
> <p>
>                <label for="surname" class="label">Surname:</label>
>                <input type="text" name="surname" id="surname"
> t:id="surname" t:type="TextField" t:value="surname" />
>              </p>
>  </form>
>
>
> Any help or alternative suggestions would be much appreciated.
>
> Cheers!!!
>
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/How-do-I-add-a-dynamic-number-of-forms-to-a-page-tp4674893p4674893.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>


-- 
Jonathan Barker
ITStrategic

Reply via email to