Hi,

I haven't used AjaxFormLoop, but with simple loop inside a form I use
SubmitNotifier, like this:

<t:form>

  <t:loop source="items" value="item">

    <t:submitnotifier t:id="main">

      <a t:type="linksubmit">Submit</a>

    </t:submitnotifier>

  </t:loop>

</t:form>


Then in your code declare:


public void onAfterSubmitFromMain() {

  //  work with current item here

}


Haven't tried with submit in nested component though, but I can imagine
AfterSubmit won't be triggered in nested component because of event
bubbling -- it bubbles up, not down. But I might be wrong here.


On Tue, May 20, 2014 at 9:45 PM, Ilya Obshadko <ilya.obsha...@gmail.com>wrote:

> On Tue, May 20, 2014 at 7:55 PM, Thiago H de Paula Figueiredo <
> thiag...@gmail.com> wrote:
>
>  Well, that makes sense (as well as explains why providing variable
> >> instance in submit context doesn't help). Event is handled by an
> instance
> >> of the
> >> component with state corresponding to the last iteration of the loop.
> >>
> >
> > The point here is that you just cannot rely on a loop variable after
> > rendering or in event (including form submission) requests. So, in this
> > case, you need to pass it to the context of the Submit component so you
> can
> > set it again. Something like this, supposing the loop variable is an
> entity:
> >
> > <t:submit t:id="submitControl" value=".." t:context="loopVariable.id"/>
> >
> > void onSelectedFromSubmitControl(Long id) {
> >         loopVariable = findById(id); // retrive the original object from
> > the id
> >         ...
> > }
> >
> > Is this what you tried? If not, could you at least provide an overview of
> > that? Otherwise, I cannot help you further.
>
>
> Yes, this is it. I have a component which is looped over.
>
> class MyComponent {
>    @Parameter
>    private MyObject obj; // assigned inside a loop
>
>    void onSelectedFromSubmitControl ( ... ) {
>    }
> }
>
> 1) initially I tried to simply use MyObject instance passed as a parameter
> inside AjaxFormLoop;
> 2) then, I tried to pass this instance as t:submit context, getting the
> same results
> 3) finally, I tried to use obj.id as a context parameter instead - again,
> onSelectedFromSubmitControl was being called with context parameter
> belonging to the last iteration of the outside loop
>
> At this point I gave up and solved the problem otherwise, without having to
> rely on t:submit context.
>
> I guess I understand your point, but t:submit does not encode context
> inside submission URL (unlike t:actionlink or t:eventlink). Probably that's
> the reason why my initial approach didn't work.
>
> In fact, when t:submit is being used inside a loop and IS NOT ENCLOSED BY
> OTHER COMPONENT, this scheme works. For example, in the same application I
> have constructs like:
>
> <t:ajaxformloop>
>   <t:submit t:id="someId" p:context="loopContext"/>
> </t:ajaxformloop>
>
> That works as expected (and just like you described it should work).
>
> But, if we replace it with
>
> <t:ajaxformloop>
>   <t:mycomponent/>
> </t:ajaxformloop>
>
> and t:submit is placed INSIDE t:mycomponent, we have a problem I've just
> described. I'm not sure if it's indeed a Tapestry bug or it's just not
> intended to work this way.
>
> --
> Ilya Obshadko
>



-- 
Dmitry Gusev

AnjLab Team
http://anjlab.com

Reply via email to