You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Stephen Nutbrown <st...@gmail.com> on 2014/05/20 14:14:08 UTC

Displaying an ArrayList of strings in a form using TextFields

Hello,

I also posted this on StackOverflow (SO), but it seems that the forum
is more active for these questions than SO. I'd really appreciate any
help. Here is the SO question, and the problem below (the same as it
is on SO).

http://stackoverflow.com/questions/23756438/tapestry-5-edit-arraylist-of-strings


I have a Result object (named result), and inside that object is an
arraylist of strings (named action), as well as some other values.

I can make a text area to edit values of the Result object like this:

    <input t:type="TextArea" t:id="feedback" t:value="result.someValue" />

This works fine. However, I would like to show a text field for each
of the Strings in the ArrayList within the result object

I can create a loop like this:

    <t:loop t:source="result.action" t:value="currentAction"
index="indexProp" t:formstate="ITERATION">
       ${currentAction}
    </t:loop>

This will show me on the screen all of the actions (that is great,
half way there). However I want these to be editable using a
TextField.

I have tried several things, none of which have worked how I wanted.
However, to help explain and as an example of what I have tried, this
is what I have:


    <t:loop t:source="result.action" t:value="currentAction"
index="indexProp" t:formstate="ITERATION">
    <input t:type="TextField" t:value="result.action.indexProp"/>
    </t:loop>

This won't work because (as far as I know), this is the same as
getResult().getAction.getIndexProp. So I tried

    <input t:type="TextField" t:value="result.action.${indexProp}"/>


This doesn't work either, although it shows the correct number of
TextFields, it does not link them up properly (they just say inside
them "result.action.0" and "result.action.1".


Any help is much appreciated.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Displaying an ArrayList of strings in a form using TextFields

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Tue, 20 May 2014 10:50:08 -0300, Stephen Nutbrown <st...@gmail.com>  
wrote:

> Hello,

Hi!

> Thank you again Thiago, Thilo and Java Lance over on StackOverflow - I
> posted a link there to this mailing list thread so anyone can follow
> if they come searching for the same issue.
>
> Adding formState="interation" did the trick, the Result object was
> already persisted.

Yay!

> I have learnt a few things from this:
> 1- Putting things in components is generally very strongly advised. I
> have around 10 at the moment, but there are certainly a lot of things
> which I should move in to components to make the project easier to
> manage. It is rather likely that at some stage soon I will be
> re-factoring my whole project (which is rather large, consisting of 59
> classes (10 components,  18 pages, 9 entities, several "utility"
> classes and some services). I finally have some time to be working on
> this project rather than being pulled  in lots of directions, so now
> is the time (It has suffered from lots of "cheapo" solutions this last
> few months).

I suggest Tapestry-IoC services to replace the utility classes. You get a  
lot more flexibility with just some few minor changes.

> 2- I now know what formState="interaction" is. Following the advice I
> looked it up here:
> http://tapestry.apache.org/5.3/apidocs/org/apache/tapestry5/corelib/LoopFormState.html
>
> 3- I owe the community a great deal of thanks :)
>
> Thank you! You have made my day.

Nice! :D

I've just posted my answer in StackOverflow too. :)

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Displaying an ArrayList of strings in a form using TextFields

Posted by Stephen Nutbrown <st...@gmail.com>.
Hello,

Thank you again Thiago, Thilo and Java Lance over on StackOverflow - I
posted a link there to this mailing list thread so anyone can follow
if they come searching for the same issue.

Adding formState="interation" did the trick, the Result object was
already persisted.

I have learnt a few things from this:
1- Putting things in components is generally very strongly advised. I
have around 10 at the moment, but there are certainly a lot of things
which I should move in to components to make the project easier to
manage. It is rather likely that at some stage soon I will be
re-factoring my whole project (which is rather large, consisting of 59
classes (10 components,  18 pages, 9 entities, several "utility"
classes and some services). I finally have some time to be working on
this project rather than being pulled  in lots of directions, so now
is the time (It has suffered from lots of "cheapo" solutions this last
few months).

2- I now know what formState="interaction" is. Following the advice I
looked it up here:
http://tapestry.apache.org/5.3/apidocs/org/apache/tapestry5/corelib/LoopFormState.html

3- I owe the community a great deal of thanks :)

Thank you! You have made my day.
Steve

On 20 May 2014 14:32, Thiago H de Paula Figueiredo <th...@gmail.com> wrote:
> On Tue, 20 May 2014 10:23:22 -0300, Stephen Nutbrown <st...@gmail.com>
> wrote:
>
>> Hi Thiago, thanks for the help!
>
>
> Hi!
>
>
>> I appreciate your comments and thank you for taking the time to help.
>> The loop which you posted does show the text fields exactly as I want
>> them (and they are pre populated with the original values from the
>> array list of strings), but when I submit the form, the updated values
>> are not in the result object. When the user arrives at the page, there
>> are already values in the array list, the user may then edit them and
>> submit the form.
>
>
> Try adding formState="interation", so Loop will get the edited list from
> your code again. Of course, this list should be the exact same instance used
> when you're rendering the form. The form submission is in a different
> request from the page rendering, so you either need to get the list again or
> @Persist the list or the object to which this list belongs. See the JavaDoc
> for LoopFormState or more details.
>
>
> --
> Thiago H. de Paula Figueiredo
> Tapestry, Java and Hibernate consultant and developer
> http://machina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Displaying an ArrayList of strings in a form using TextFields

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Tue, 20 May 2014 10:23:22 -0300, Stephen Nutbrown <st...@gmail.com>  
wrote:

> Hi Thiago, thanks for the help!

Hi!

> I appreciate your comments and thank you for taking the time to help.
> The loop which you posted does show the text fields exactly as I want
> them (and they are pre populated with the original values from the
> array list of strings), but when I submit the form, the updated values
> are not in the result object. When the user arrives at the page, there
> are already values in the array list, the user may then edit them and
> submit the form.

Try adding formState="interation", so Loop will get the edited list from  
your code again. Of course, this list should be the exact same instance  
used when you're rendering the form. The form submission is in a different  
request from the page rendering, so you either need to get the list again  
or @Persist the list or the object to which this list belongs. See the  
JavaDoc for LoopFormState or more details.

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Displaying an ArrayList of strings in a form using TextFields

Posted by Stephen Nutbrown <st...@gmail.com>.
Hi Thiago, thanks for the help!

I appreciate your comments and thank you for taking the time to help.
The loop which you posted does show the text fields exactly as I want
them (and they are pre populated with the original values from the
array list of strings), but when I submit the form, the updated values
are not in the result object. When the user arrives at the page, there
are already values in the array list, the user may then edit them and
submit the form.

In my "OnSuccessFromSubmitResults" method, I check to see if the
result.action list has changed (at the moment I simply print these out
to the console so I can see which ones are there). It is showing me
the original values which were in the list, which suggests it didn't
set the value. If I was to do what I am wanting it to do in java, it
would have to be: result.getAction().set(index, somethingTheyEntered);

But i'm not sure if Tapestry can do that this easily?



Thanks,
Steve


On 20 May 2014 14:08, Thiago H de Paula Figueiredo <th...@gmail.com> wrote:
> On Tue, 20 May 2014 09:14:08 -0300, Stephen Nutbrown <st...@gmail.com>
> wrote:
>
>> Hello,
>
>
> Hi!
>
>
>>     <t:loop t:source="result.action" t:value="currentAction"
>> index="indexProp" t:formstate="ITERATION">
>>     <input t:type="TextField" t:value="result.action.indexProp"/>
>>     </t:loop>
>
>
> The prop binding (the default one) doesn't support using list or array
> indexes.
>
>
>> This won't work because (as far as I know), this is the same as
>> getResult().getAction.getIndexProp. So I tried
>>
>>     <input t:type="TextField" t:value="result.action.${indexProp}"/>
>
>
> Never, never, ever use ${} when passing parameters. In 100% of the times,
> it's either completely wrong or completely useless.
>
> Try this:
>
>
> <t:loop t:source="result.action" t:value="currentAction">
>      <input t:type="TextField" t:value="currentAction"/>
> </t:loop>
>
> --
> Thiago H. de Paula Figueiredo
> Tapestry, Java and Hibernate consultant and developer
> http://machina.com.br
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Displaying an ArrayList of strings in a form using TextFields

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Tue, 20 May 2014 09:14:08 -0300, Stephen Nutbrown <st...@gmail.com>  
wrote:

> Hello,

Hi!

>     <t:loop t:source="result.action" t:value="currentAction"
> index="indexProp" t:formstate="ITERATION">
>     <input t:type="TextField" t:value="result.action.indexProp"/>
>     </t:loop>

The prop binding (the default one) doesn't support using list or array  
indexes.

> This won't work because (as far as I know), this is the same as
> getResult().getAction.getIndexProp. So I tried
>
>     <input t:type="TextField" t:value="result.action.${indexProp}"/>

Never, never, ever use ${} when passing parameters. In 100% of the times,  
it's either completely wrong or completely useless.

Try this:

<t:loop t:source="result.action" t:value="currentAction">
      <input t:type="TextField" t:value="currentAction"/>
</t:loop>

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Displaying an ArrayList of strings in a form using TextFields

Posted by Stephen Nutbrown <st...@gmail.com>.
Hi Thilo,

Thanks for this. I tried Thiago's solution and had some problems with
it not remembering the values which were set. I'm not entirely sure
why that is.
I think creating a component is the ideal solution, but it seemed a
little overkill at first.

I also noticed on StackOverflow that someone (Lance Java) posted a
useful response that I need to try, but I do think it's going to have
to go into it's own component and I need to study ajax loops, although
being able to add/remove rows isn't entirely necessary for the project
at the moment.

Thanks,
Steve

On 20 May 2014 14:21, Thilo Tanner <th...@reprisk.com> wrote:
> Hi Stephen,
>
> I strongly encourage you to create a component for your result editor. This helps encapsulating the editor code, which de-clutter your page class / template. Tapestry components are very elegant and easy to re-use.
>
> If the number of values in your ArrayList is constant, you can use Thiago's approach and use the Loop component to create the text fields. In case the number of values should be adjustable, I think you're better off using AjaxFormLoop.
>
> Best,
> Thilo
>
> ________________________________________
> From: Stephen Nutbrown <st...@gmail.com>
> Sent: Tuesday, May 20, 2014 15:02
> To: Tapestry users
> Subject: Re: Displaying an ArrayList of strings in a form using TextFields
>
> Hi Thilo,
>
> Thank you for your reply and for taking the time - I really do appreciate it.
>
> I did come across that first link when I was searching, but the issue
> would be that it requires a lot more work for doing something which I
> thought would be straight forwards. However, if I do it properly, then
> this form can be used in several places in the application. I think
> the best way would be for me to create this as a component which
> handles everything to do with editing the result object, and pass the
> "result" object in, I can name it something along the lines of
> "resultEditor". I would then use the ajaxloop within the component.
> That way whenever I want to show the result objects details and allow
> it to be edited (this could be used in a few places), I can just use
> this component which will be responsible for updating the result
> object.
>
> I just wanted to check with you that doing that seems like a sensible
> way forwards?
>
> As for the cheapo idea, although I do like it, unfortunately the text
> fields may want changing to text areas (as they may not be short) so
> if they risk going on to two lines then it becomes a bit of a
> nightmare for users seeing where the end of lines really are.
>
> If you think the first way is the way to go, i'll put in the time to
> create it as a separate component with an ajax loop in it. It seems
> odd that it can't be done in a simpler way, just displaying each
> String in the ArrayList as a separate text field/area.
>
> Thanks,
> Steve
>
> On 20 May 2014 13:35, Thilo Tanner <th...@reprisk.com> wrote:
>> Hi Stephen,
>>
>> If you want one separate text field per ArrayList value, I suggest you take a look at the FormLoop component:
>>
>> http://jumpstart.doublenegative.com.au/jumpstart/examples/ajax/formloop1
>>
>> (The JumpStart sample app is a very good starting point to learn about T5 components)
>>
>> The component allows you to add and remove rows dynamically. If you store your values in the database, you either have to replace all values after the submit or you should keep track of the changes using a holder object:
>>
>> http://jumpstart.doublenegative.com.au/jumpstart/examples/ajax/formloopwithholders1
>>
>> Depending on your use case, you can also go for a cheapo solution and create a text area for your values. When you render the form, you fill it with one value per line and after the submit you split the user input line-by-line.
>>
>> Please feel free to ask, if you have questions concerning the FormLoop.
>>
>> Best,
>> Thilo
>>
>>
>> ________________________________________
>> From: Stephen Nutbrown <st...@gmail.com>
>> Sent: Tuesday, May 20, 2014 14:14
>> To: Tapestry users
>> Subject: Displaying an ArrayList of strings in a form using TextFields
>>
>> Hello,
>>
>> I also posted this on StackOverflow (SO), but it seems that the forum
>> is more active for these questions than SO. I'd really appreciate any
>> help. Here is the SO question, and the problem below (the same as it
>> is on SO).
>>
>> http://stackoverflow.com/questions/23756438/tapestry-5-edit-arraylist-of-strings
>>
>>
>> I have a Result object (named result), and inside that object is an
>> arraylist of strings (named action), as well as some other values.
>>
>> I can make a text area to edit values of the Result object like this:
>>
>>     <input t:type="TextArea" t:id="feedback" t:value="result.someValue" />
>>
>> This works fine. However, I would like to show a text field for each
>> of the Strings in the ArrayList within the result object
>>
>> I can create a loop like this:
>>
>>     <t:loop t:source="result.action" t:value="currentAction"
>> index="indexProp" t:formstate="ITERATION">
>>        ${currentAction}
>>     </t:loop>
>>
>> This will show me on the screen all of the actions (that is great,
>> half way there). However I want these to be editable using a
>> TextField.
>>
>> I have tried several things, none of which have worked how I wanted.
>> However, to help explain and as an example of what I have tried, this
>> is what I have:
>>
>>
>>     <t:loop t:source="result.action" t:value="currentAction"
>> index="indexProp" t:formstate="ITERATION">
>>     <input t:type="TextField" t:value="result.action.indexProp"/>
>>     </t:loop>
>>
>> This won't work because (as far as I know), this is the same as
>> getResult().getAction.getIndexProp. So I tried
>>
>>     <input t:type="TextField" t:value="result.action.${indexProp}"/>
>>
>>
>> This doesn't work either, although it shows the correct number of
>> TextFields, it does not link them up properly (they just say inside
>> them "result.action.0" and "result.action.1".
>>
>>
>> Any help is much appreciated.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


RE: Displaying an ArrayList of strings in a form using TextFields

Posted by Thilo Tanner <th...@reprisk.com>.
Hi Stephen,

I strongly encourage you to create a component for your result editor. This helps encapsulating the editor code, which de-clutter your page class / template. Tapestry components are very elegant and easy to re-use.

If the number of values in your ArrayList is constant, you can use Thiago's approach and use the Loop component to create the text fields. In case the number of values should be adjustable, I think you're better off using AjaxFormLoop.

Best,
Thilo

________________________________________
From: Stephen Nutbrown <st...@gmail.com>
Sent: Tuesday, May 20, 2014 15:02
To: Tapestry users
Subject: Re: Displaying an ArrayList of strings in a form using TextFields

Hi Thilo,

Thank you for your reply and for taking the time - I really do appreciate it.

I did come across that first link when I was searching, but the issue
would be that it requires a lot more work for doing something which I
thought would be straight forwards. However, if I do it properly, then
this form can be used in several places in the application. I think
the best way would be for me to create this as a component which
handles everything to do with editing the result object, and pass the
"result" object in, I can name it something along the lines of
"resultEditor". I would then use the ajaxloop within the component.
That way whenever I want to show the result objects details and allow
it to be edited (this could be used in a few places), I can just use
this component which will be responsible for updating the result
object.

I just wanted to check with you that doing that seems like a sensible
way forwards?

As for the cheapo idea, although I do like it, unfortunately the text
fields may want changing to text areas (as they may not be short) so
if they risk going on to two lines then it becomes a bit of a
nightmare for users seeing where the end of lines really are.

If you think the first way is the way to go, i'll put in the time to
create it as a separate component with an ajax loop in it. It seems
odd that it can't be done in a simpler way, just displaying each
String in the ArrayList as a separate text field/area.

Thanks,
Steve

On 20 May 2014 13:35, Thilo Tanner <th...@reprisk.com> wrote:
> Hi Stephen,
>
> If you want one separate text field per ArrayList value, I suggest you take a look at the FormLoop component:
>
> http://jumpstart.doublenegative.com.au/jumpstart/examples/ajax/formloop1
>
> (The JumpStart sample app is a very good starting point to learn about T5 components)
>
> The component allows you to add and remove rows dynamically. If you store your values in the database, you either have to replace all values after the submit or you should keep track of the changes using a holder object:
>
> http://jumpstart.doublenegative.com.au/jumpstart/examples/ajax/formloopwithholders1
>
> Depending on your use case, you can also go for a cheapo solution and create a text area for your values. When you render the form, you fill it with one value per line and after the submit you split the user input line-by-line.
>
> Please feel free to ask, if you have questions concerning the FormLoop.
>
> Best,
> Thilo
>
>
> ________________________________________
> From: Stephen Nutbrown <st...@gmail.com>
> Sent: Tuesday, May 20, 2014 14:14
> To: Tapestry users
> Subject: Displaying an ArrayList of strings in a form using TextFields
>
> Hello,
>
> I also posted this on StackOverflow (SO), but it seems that the forum
> is more active for these questions than SO. I'd really appreciate any
> help. Here is the SO question, and the problem below (the same as it
> is on SO).
>
> http://stackoverflow.com/questions/23756438/tapestry-5-edit-arraylist-of-strings
>
>
> I have a Result object (named result), and inside that object is an
> arraylist of strings (named action), as well as some other values.
>
> I can make a text area to edit values of the Result object like this:
>
>     <input t:type="TextArea" t:id="feedback" t:value="result.someValue" />
>
> This works fine. However, I would like to show a text field for each
> of the Strings in the ArrayList within the result object
>
> I can create a loop like this:
>
>     <t:loop t:source="result.action" t:value="currentAction"
> index="indexProp" t:formstate="ITERATION">
>        ${currentAction}
>     </t:loop>
>
> This will show me on the screen all of the actions (that is great,
> half way there). However I want these to be editable using a
> TextField.
>
> I have tried several things, none of which have worked how I wanted.
> However, to help explain and as an example of what I have tried, this
> is what I have:
>
>
>     <t:loop t:source="result.action" t:value="currentAction"
> index="indexProp" t:formstate="ITERATION">
>     <input t:type="TextField" t:value="result.action.indexProp"/>
>     </t:loop>
>
> This won't work because (as far as I know), this is the same as
> getResult().getAction.getIndexProp. So I tried
>
>     <input t:type="TextField" t:value="result.action.${indexProp}"/>
>
>
> This doesn't work either, although it shows the correct number of
> TextFields, it does not link them up properly (they just say inside
> them "result.action.0" and "result.action.1".
>
>
> Any help is much appreciated.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Displaying an ArrayList of strings in a form using TextFields

Posted by Stephen Nutbrown <st...@gmail.com>.
Hi Thilo,

Thank you for your reply and for taking the time - I really do appreciate it.

I did come across that first link when I was searching, but the issue
would be that it requires a lot more work for doing something which I
thought would be straight forwards. However, if I do it properly, then
this form can be used in several places in the application. I think
the best way would be for me to create this as a component which
handles everything to do with editing the result object, and pass the
"result" object in, I can name it something along the lines of
"resultEditor". I would then use the ajaxloop within the component.
That way whenever I want to show the result objects details and allow
it to be edited (this could be used in a few places), I can just use
this component which will be responsible for updating the result
object.

I just wanted to check with you that doing that seems like a sensible
way forwards?

As for the cheapo idea, although I do like it, unfortunately the text
fields may want changing to text areas (as they may not be short) so
if they risk going on to two lines then it becomes a bit of a
nightmare for users seeing where the end of lines really are.

If you think the first way is the way to go, i'll put in the time to
create it as a separate component with an ajax loop in it. It seems
odd that it can't be done in a simpler way, just displaying each
String in the ArrayList as a separate text field/area.

Thanks,
Steve

On 20 May 2014 13:35, Thilo Tanner <th...@reprisk.com> wrote:
> Hi Stephen,
>
> If you want one separate text field per ArrayList value, I suggest you take a look at the FormLoop component:
>
> http://jumpstart.doublenegative.com.au/jumpstart/examples/ajax/formloop1
>
> (The JumpStart sample app is a very good starting point to learn about T5 components)
>
> The component allows you to add and remove rows dynamically. If you store your values in the database, you either have to replace all values after the submit or you should keep track of the changes using a holder object:
>
> http://jumpstart.doublenegative.com.au/jumpstart/examples/ajax/formloopwithholders1
>
> Depending on your use case, you can also go for a cheapo solution and create a text area for your values. When you render the form, you fill it with one value per line and after the submit you split the user input line-by-line.
>
> Please feel free to ask, if you have questions concerning the FormLoop.
>
> Best,
> Thilo
>
>
> ________________________________________
> From: Stephen Nutbrown <st...@gmail.com>
> Sent: Tuesday, May 20, 2014 14:14
> To: Tapestry users
> Subject: Displaying an ArrayList of strings in a form using TextFields
>
> Hello,
>
> I also posted this on StackOverflow (SO), but it seems that the forum
> is more active for these questions than SO. I'd really appreciate any
> help. Here is the SO question, and the problem below (the same as it
> is on SO).
>
> http://stackoverflow.com/questions/23756438/tapestry-5-edit-arraylist-of-strings
>
>
> I have a Result object (named result), and inside that object is an
> arraylist of strings (named action), as well as some other values.
>
> I can make a text area to edit values of the Result object like this:
>
>     <input t:type="TextArea" t:id="feedback" t:value="result.someValue" />
>
> This works fine. However, I would like to show a text field for each
> of the Strings in the ArrayList within the result object
>
> I can create a loop like this:
>
>     <t:loop t:source="result.action" t:value="currentAction"
> index="indexProp" t:formstate="ITERATION">
>        ${currentAction}
>     </t:loop>
>
> This will show me on the screen all of the actions (that is great,
> half way there). However I want these to be editable using a
> TextField.
>
> I have tried several things, none of which have worked how I wanted.
> However, to help explain and as an example of what I have tried, this
> is what I have:
>
>
>     <t:loop t:source="result.action" t:value="currentAction"
> index="indexProp" t:formstate="ITERATION">
>     <input t:type="TextField" t:value="result.action.indexProp"/>
>     </t:loop>
>
> This won't work because (as far as I know), this is the same as
> getResult().getAction.getIndexProp. So I tried
>
>     <input t:type="TextField" t:value="result.action.${indexProp}"/>
>
>
> This doesn't work either, although it shows the correct number of
> TextFields, it does not link them up properly (they just say inside
> them "result.action.0" and "result.action.1".
>
>
> Any help is much appreciated.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


RE: Displaying an ArrayList of strings in a form using TextFields

Posted by Thilo Tanner <th...@reprisk.com>.
Hi Stephen,

If you want one separate text field per ArrayList value, I suggest you take a look at the FormLoop component:

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

(The JumpStart sample app is a very good starting point to learn about T5 components)

The component allows you to add and remove rows dynamically. If you store your values in the database, you either have to replace all values after the submit or you should keep track of the changes using a holder object:

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

Depending on your use case, you can also go for a cheapo solution and create a text area for your values. When you render the form, you fill it with one value per line and after the submit you split the user input line-by-line.

Please feel free to ask, if you have questions concerning the FormLoop.

Best,
Thilo


________________________________________
From: Stephen Nutbrown <st...@gmail.com>
Sent: Tuesday, May 20, 2014 14:14
To: Tapestry users
Subject: Displaying an ArrayList of strings in a form using TextFields

Hello,

I also posted this on StackOverflow (SO), but it seems that the forum
is more active for these questions than SO. I'd really appreciate any
help. Here is the SO question, and the problem below (the same as it
is on SO).

http://stackoverflow.com/questions/23756438/tapestry-5-edit-arraylist-of-strings


I have a Result object (named result), and inside that object is an
arraylist of strings (named action), as well as some other values.

I can make a text area to edit values of the Result object like this:

    <input t:type="TextArea" t:id="feedback" t:value="result.someValue" />

This works fine. However, I would like to show a text field for each
of the Strings in the ArrayList within the result object

I can create a loop like this:

    <t:loop t:source="result.action" t:value="currentAction"
index="indexProp" t:formstate="ITERATION">
       ${currentAction}
    </t:loop>

This will show me on the screen all of the actions (that is great,
half way there). However I want these to be editable using a
TextField.

I have tried several things, none of which have worked how I wanted.
However, to help explain and as an example of what I have tried, this
is what I have:


    <t:loop t:source="result.action" t:value="currentAction"
index="indexProp" t:formstate="ITERATION">
    <input t:type="TextField" t:value="result.action.indexProp"/>
    </t:loop>

This won't work because (as far as I know), this is the same as
getResult().getAction.getIndexProp. So I tried

    <input t:type="TextField" t:value="result.action.${indexProp}"/>


This doesn't work either, although it shows the correct number of
TextFields, it does not link them up properly (they just say inside
them "result.action.0" and "result.action.1".


Any help is much appreciated.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org