Search code examples
javaarraylisttapestry

Tapestry - Form element for list possible?


I tried my best to make the title represent the question, but it needs some explaining, and i'll try to do that in the simplest form I can.

Let's say I have a page with a class and a .tml file. The page has an ArrayList of Strings. I would like to make a form which allows the user to enter as many strings as they would like into that array list. I'd rather, if possible, not have the page refresh each and every time, but would rather have an "add new string" button.

So for example, if _ _ _ _ _ represents an input box, I would like this:

Form:
Input 1: _ _ _ _ _

[Button: Add new row] [Button: Submit]

If the user presses add new row, the form should update to:

Form:
Input 1: _ _ _ _ _
Input 2: _ _ _ _ _ 

[Button: Add new row] [Button: Submit]

When submitted, I would like to add all of those strings into the ArrayList.

Is there something out there already to do something similar to this? For my actual purpose, I would need to edit it a little as each new "row" actually has more options next to it in the form, but if someone can point me to the right place to work this out then I'm sure I can figure the rest out.


Solution

  • You can use the AjaxFormLoop

    http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/corelib/components/AjaxFormLoop.html

    http://jumpstart.doublenegative.com.au/jumpstart/examples/ajax/formloop1