You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by dkeenan <da...@yahoo.co.uk> on 2011/08/07 14:39:48 UTC
How do I add a dynamic number of forms to a page?
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-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: How do I add a dynamic number of forms to a page?
Posted by Jonathan Barker <jo...@gmail.com>.
The down side of this approach (depending on your target user) is that many
users will expect all changes to all Persons to be submitted in a single
submit.
You could render a list of Person "views", with each view in a Zone, and
then have an Edit Person link that would update the Zone content with an
edit Form. If you go with this approach, a place to be careful is the
assignment of id's for the zones (not the t:id's), and making sure they
agree with the zone parameter on the action links.
On Sun, Aug 7, 2011 at 10:27 AM, dkeenan <da...@yahoo.co.uk>wrote:
> Yesss!. Tapestry seems to take care of it if I just create a loop. So I can
> loop through each person, create a form for each, and have one Form
> component with one set of field props in the page class that each generated
> HTML for can submit too. Brilliant.
>
>
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/How-do-I-add-a-dynamic-number-of-forms-to-a-page-tp4674893p4675090.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
--
Jonathan Barker
ITStrategic
Re: How do I add a dynamic number of forms to a page?
Posted by dkeenan <da...@yahoo.co.uk>.
Yesss!. Tapestry seems to take care of it if I just create a loop. So I can
loop through each person, create a form for each, and have one Form
component with one set of field props in the page class that each generated
HTML for can submit too. Brilliant.
--
View this message in context: http://tapestry.1045711.n5.nabble.com/How-do-I-add-a-dynamic-number-of-forms-to-a-page-tp4674893p4675090.html
Sent from the Tapestry - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: How do I add a dynamic number of forms to a page?
Posted by Jonathan Barker <jo...@gmail.com>.
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 <da...@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-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
--
Jonathan Barker
ITStrategic