You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Stephan Windmüller <st...@cs.tu-dortmund.de> on 2009/09/15 09:33:48 UTC

Wrong context for submit button in loop

Hello!

I am creating multiple submit buttons in a loop component, each of them
has its own context. But when I submit the form, I always get the
context of the last submit button.

Is this a bug in Tapestry or did I misunderstand the submit context?

TIA
 Stephan

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


Re: Wrong context for submit button in loop

Posted by Norman Franke <no...@myasd.com>.
WHat I do is to have the button call a JavaScript function that stores  
the context/value in a hidden field (a normal TextField with display:  
none, since Tapestry's hidden field type is broken. Then call  
form.submit(). That works well.

Norman Franke
Answering Service for Directors, Inc.
www.myasd.com



On Sep 16, 2009, at 6:27 AM, Felix Gonschorek wrote:

> Same problem here: I have a delete button which removes an object  
> from a list. Changes to other fields in the form get currently lost,  
> as i have to use a event link. Using a submit button inside the loop  
> with custom context and event would be great - but it does not work  
> as always the last item in the loop emits the event and gets removed.
>
> Another option would be to add a checkbox to each row and one  
> "add"/"remove" button outside of the loop. Checked rows are being  
> removed (in my case) or a job is added (stephans case) - i will try  
> this out and report here.
>
> felix
>
> Stephan Windmüller schrieb:
>> Thiago H. de Paula Figueiredo schrieb:
>>
>>
>>>> What I need is a button which does some change to an object. I do  
>>>> not
>>>> want the user to lose data he entered for other objects, so I  
>>>> decided to
>>>> use a form submit.
>>>>
>>> If you don't need to submit a form, just to fire an event in the  
>>> server,  an EventLink is the best solution.
>>>
>>
>> But an EventLink will call a GET instead of a POST, so the changes in
>> all other objects on that page are lost.
>>
>> Perhaps I should give a more detailed example:
>>
>> The page lists a couple of jobs. Each job has a title, description  
>> and a
>> list of assigned users. I want to edit more than one job, so I am
>> looping over all jobs, displaying title, description and users for  
>> each
>> of them in one big form.
>>
>> Now I want to add a user to a job, so I add an "Add user" button to  
>> each
>> job. But if this is realized as an EventLink or ActionLink, all  
>> changes
>> to title and description for each job on the page are lost when I  
>> click
>> on them.
>>
>> What I tried was a submit button which receives the current job in  
>> its
>> context. The form was submitted, changes saved and with the context I
>> would be able to add another user. But the context is (as stated in  
>> my
>> first post) every time the same.
>>
>> Regards
>> Stephan
>>
>> ---------------------------------------------------------------------
>> 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: Wrong context for submit button in loop

Posted by Felix Gonschorek <fe...@ggmedia.net>.
Same problem here: I have a delete button which removes an object from a 
list. Changes to other fields in the form get currently lost, as i have 
to use a event link. Using a submit button inside the loop with custom 
context and event would be great - but it does not work as always the 
last item in the loop emits the event and gets removed.

Another option would be to add a checkbox to each row and one 
"add"/"remove" button outside of the loop. Checked rows are being 
removed (in my case) or a job is added (stephans case) - i will try this 
out and report here.

felix

Stephan Windmüller schrieb:
> Thiago H. de Paula Figueiredo schrieb:
>
>   
>>> What I need is a button which does some change to an object. I do not
>>> want the user to lose data he entered for other objects, so I decided to
>>> use a form submit.
>>>       
>> If you don't need to submit a form, just to fire an event in the server,  
>> an EventLink is the best solution.
>>     
>
> But an EventLink will call a GET instead of a POST, so the changes in
> all other objects on that page are lost.
>
> Perhaps I should give a more detailed example:
>
> The page lists a couple of jobs. Each job has a title, description and a
> list of assigned users. I want to edit more than one job, so I am
> looping over all jobs, displaying title, description and users for each
> of them in one big form.
>
> Now I want to add a user to a job, so I add an "Add user" button to each
> job. But if this is realized as an EventLink or ActionLink, all changes
> to title and description for each job on the page are lost when I click
> on them.
>
> What I tried was a submit button which receives the current job in its
> context. The form was submitted, changes saved and with the context I
> would be able to add another user. But the context is (as stated in my
> first post) every time the same.
>
> Regards
>  Stephan
>
> ---------------------------------------------------------------------
> 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: Wrong context for submit button in loop

Posted by Stephan Windmüller <st...@cs.tu-dortmund.de>.
Stephan Windmüller wrote:

> What I tried was a submit button which receives the current job in its
> context. The form was submitted, changes saved and with the context I
> would be able to add another user. But the context is (as stated in my
> first post) every time the same.

Update for this: It is now a known bug:

https://issues.apache.org/jira/browse/TAP5-869

Workaround: Setting the "defer" parameter of the Submit component to "false"

- Stephan

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


Re: Wrong context for submit button in loop

Posted by Stephan Windmüller <st...@cs.tu-dortmund.de>.
Thiago H. de Paula Figueiredo schrieb:

>> What I need is a button which does some change to an object. I do not
>> want the user to lose data he entered for other objects, so I decided to
>> use a form submit.
> If you don't need to submit a form, just to fire an event in the server,  
> an EventLink is the best solution.

But an EventLink will call a GET instead of a POST, so the changes in
all other objects on that page are lost.

Perhaps I should give a more detailed example:

The page lists a couple of jobs. Each job has a title, description and a
list of assigned users. I want to edit more than one job, so I am
looping over all jobs, displaying title, description and users for each
of them in one big form.

Now I want to add a user to a job, so I add an "Add user" button to each
job. But if this is realized as an EventLink or ActionLink, all changes
to title and description for each job on the page are lost when I click
on them.

What I tried was a submit button which receives the current job in its
context. The form was submitted, changes saved and with the context I
would be able to add another user. But the context is (as stated in my
first post) every time the same.

Regards
 Stephan

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


Re: Wrong context for submit button in loop

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Tue, 15 Sep 2009 12:12:41 -0300, Stephan Windmüller  
<st...@cs.tu-dortmund.de> escreveu:

> What I need is a button which does some change to an object. I do not
> want the user to lose data he entered for other objects, so I decided to
> use a form submit.

If you don't need to submit a form, just to fire an event in the server,  
an EventLink is the best solution.
The Select component is meant to be used when the same form has more than  
one action (save, delete, etc) and you need to know which one the user  
chose.

> Will this be possible with ActionLinks and EventLinks? Do they work
> without JavaScript?

Yes. Yes.

-- 
Thiago H. de Paula Figueiredo
Consultor, desenvolvedor e instrutor em Java
Coordenador e professor da Especialização em Engenharia de Software com  
Ênfase em Java da Faculdade Pitágoras
http://www.arsmachina.com.br/thiago

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


Re: Wrong context for submit button in loop

Posted by Stephan Windmüller <st...@cs.tu-dortmund.de>.
Thiago H. de Paula Figueiredo wrote:

>> <t:loop t:source="objetcs" t:value="current" t:formState="iteration">
>>  <t:submit t:id="toggleState" t:context="[another, current]"/>
>> </t:loop>
> I'm not sure, but maybe we can't use the Submit component this way. Take a  
> look at the generated HTML (specially the submit buttons and hidden  
> fields) and post it here please.

For a loop over two objects, the submit buttons look like this:


<input value="Change" name="submit_0" type="submit"></input>
[...]
<input value="Change" name="submit_0_0" type="submit"></input>


Within the loop there are no hidden fields. In the whole page there are
only two of them, one for the ActivationContext and one formData.

> I've been using ActionLinks or EventLinks inside Loops and Grids  
> successfully.

What I need is a button which does some change to an object. I do not
want the user to lose data he entered for other objects, so I decided to
use a form submit.

Will this be possible with ActionLinks and EventLinks? Do they work
without JavaScript?

Thanks for your help!
 Stephan

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


Re: Wrong context for submit button in loop

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Tue, 15 Sep 2009 10:45:33 -0300, Stephan Windmüller  
<st...@cs.tu-dortmund.de> escreveu:

> <t:loop t:source="objetcs" t:value="current" t:formState="iteration">
>  <t:submit t:id="toggleState" t:context="[another, current]"/>
> </t:loop>

I'm not sure, but maybe we can't use the Submit component this way. Take a  
look at the generated HTML (specially the submit buttons and hidden  
fields) and post it here please.
I've been using ActionLinks or EventLinks inside Loops and Grids  
successfully.

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

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


Re: Wrong context for submit button in loop

Posted by Stephan Windmüller <st...@cs.tu-dortmund.de>.
Thiago H. de Paula Figueiredo wrote:

>> I am creating multiple submit buttons in a loop component, each of them
>> has its own context. But when I submit the form, I always get the
>> context of the last submit button.
> Please post your code so we can try to help you.

Here is a simplified version of what I am trying to do:


<t:loop t:source="objetcs" t:value="current" t:formState="iteration">
 <t:submit t:id="toggleState" t:context="[another, current]"/>
</t:loop>

@OnEvent(EventConstants.SELECTED)
public void onSelectedFromEditButton(Object1 another, Object2 current) {
 ...
}


When the method is called, it always gets the context of the last
button. I am using Tapestry 5.1.0.5

Regards
 Stephan

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


Re: Wrong context for submit button in loop

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Tue, 15 Sep 2009 04:33:48 -0300, Stephan Windmüller  
<st...@cs.tu-dortmund.de> escreveu:

> Hello!

Hi!

> I am creating multiple submit buttons in a loop component, each of them
> has its own context. But when I submit the form, I always get the
> context of the last submit button.

Please post your code so we can try to help you.

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

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