You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Stefan Lindner <li...@visionet.de> on 2008/05/07 23:55:47 UTC

Ajax and Loop

Dear wicket wizzards,

I have a Loop on my page (creates Components from a List ot Objects).
Now I have an AjaxFallbackLink on my page. This link adds an Object to
my List and as a reaction to this action I want my Loop to be repainted
(showing the new object). What must I do? A simple
"target.addComponent(Loop.getParent())" has no effect.
The Components of the loop are created in the Constructor of the Loop's
parent. Do I have to overwrite some "beforeRender" methods? Of course, I
took a look at the Wicket In Action book and the Wiki and the List but I
did not find a hint. Can anybody help me?

Stefan

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


Re: Ajax and Loop

Posted by Eelco Hillenius <ee...@gmail.com>.
>  I have a Loop on my page (creates Components from a List ot Objects).
>  Now I have an AjaxFallbackLink on my page. This link adds an Object to
>  my List and as a reaction to this action I want my Loop to be repainted
>  (showing the new object). What must I do? A simple
>  "target.addComponent(Loop.getParent())" has no effect.
>  The Components of the loop are created in the Constructor of the Loop's
>  parent. Do I have to overwrite some "beforeRender" methods? Of course, I
>  took a look at the Wicket In Action book and the Wiki and the List but I
>  did not find a hint. Can anybody help me?

Repainting the loop won't have an effect because it is still the same
instance. If you want to keep using Loop, you'll have to replace it
with a new instance so that it will populate it's child components
based on the model now. Or use RefreshingView (consider using
ReuseIfModelsEqualStrategy if in a form) or ListView with reuseItems
== false.

Eelco

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


Re: Ajax and Loop

Posted by Stefan Lindner <li...@visionet.de>.
Thank you! The ListView did the trick! 

-----Ursprüngliche Nachricht-----
Von: Eelco Hillenius [mailto:eelco.hillenius@gmail.com] 
Gesendet: Donnerstag, 8. Mai 2008 00:35
An: users@wicket.apache.org; jeremy@thomersonfamily.com
Betreff: Re: Ajax and Loop

> Have you tried using a ListView in combination with a model (rather than passing a List to the constructor of ListView)?

That won't trigger a re-population of the child components (ListItem and everything you add to it). For that, you need to call setReuseItems(false). Note that this can cause problems in forms (particularly with updating feedback), so when using forms, things like RefreshingView are often preferable.

Eelco

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


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


Re: Ajax and Loop

Posted by Eelco Hillenius <ee...@gmail.com>.
> Have you tried using a ListView in combination with a model (rather than passing a List to the constructor of ListView)?

That won't trigger a re-population of the child components (ListItem
and everything you add to it). For that, you need to call
setReuseItems(false). Note that this can cause problems in forms
(particularly with updating feedback), so when using forms, things
like RefreshingView are often preferable.

Eelco

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


Re: Ajax and Loop

Posted by Jeremy Thomerson <je...@thomersonfamily.com>.
Hrmm...  I suspect that somewhere one of your components is holding on to a
copy of the list, and isn't modified.  Have you tried using a model, shared
between the component you want to refresh and the link that will modify the
list?  If the link modifies the list, then the component that has the same
model is added to the ajax target, it should know that the underlying list
has changed.  I shy away from any constructor that takes a list directly for
this reason - I'd rather have a model, and then use it any place that needs
access to that list.

BTW - With ListView, it would be real easy to make table rows....

add(new ListView<Foo>("list", new PropertyModel(myObject, "myListOfStuff"))
{
populateItem(ListItem<Foo> item) ....
});

HTML:
<table class="foo">
 <tr wicket:id="list">
  <td><span wicket:id="someLabelYouAddedToListItem"></span></td>
  <td><a wicket:id="someLinkYouAddedToListItem">click me</a></td>
 </tr>
</table>

Jeremy Thomerson
http://www.wickettraining.com

On Wed, May 7, 2008 at 5:21 PM, Stefan Lindner <li...@visionet.de> wrote:

> The Loop fills the rows of a table. I have no idea how a ListView can
> generate the <tr><td>..</td></tr> structure of a table. The examlpe code
> would be a little bit complex because I use Scriptaculous (self compiled for
> wicket 1.4 enriched by generics)). After a drag operation into a table
> (generated gy a Loop) I want to redraw the table (now having one more
> Component).
> I tried to investigate in the code of a Refreshing View (DataGrid), that
> supports this functionalits (add a line to a table, add the table to the
> AjaxRequestTarget and see a new line in the table) but I did not find a
> hint.
>
> Stefan
>
> -----Ursprüngliche Nachricht-----
> Von: jeremythomerson@gmail.com [mailto:jeremythomerson@gmail.com] Im
> Auftrag von Jeremy Thomerson
> Gesendet: Donnerstag, 8. Mai 2008 00:07
> An: users@wicket.apache.org
> Betreff: Re: Ajax and Loop
>
> Can you paste some code?  Have you tried using a ListView in combination
> with a model (rather than passing a List to the constructor of ListView)?
>
> Jeremy Thomerson
> http://www.wickettraining.com
>
> On Wed, May 7, 2008 at 4:55 PM, Stefan Lindner <li...@visionet.de>
> wrote:
>
> > Dear wicket wizzards,
> >
> > I have a Loop on my page (creates Components from a List ot Objects).
> > Now I have an AjaxFallbackLink on my page. This link adds an Object to
> > my List and as a reaction to this action I want my Loop to be
> > repainted (showing the new object). What must I do? A simple
> > "target.addComponent(Loop.getParent())" has no effect.
> > The Components of the loop are created in the Constructor of the
> > Loop's parent. Do I have to overwrite some "beforeRender" methods? Of
> > course, I took a look at the Wicket In Action book and the Wiki and
> > the List but I did not find a hint. Can anybody help me?
> >
> > Stefan
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Ajax and Loop

Posted by Stefan Lindner <li...@visionet.de>.
The Loop fills the rows of a table. I have no idea how a ListView can generate the <tr><td>..</td></tr> structure of a table. The examlpe code would be a little bit complex because I use Scriptaculous (self compiled for wicket 1.4 enriched by generics)). After a drag operation into a table (generated gy a Loop) I want to redraw the table (now having one more Component).
I tried to investigate in the code of a Refreshing View (DataGrid), that supports this functionalits (add a line to a table, add the table to the AjaxRequestTarget and see a new line in the table) but I did not find a hint.

Stefan

-----Ursprüngliche Nachricht-----
Von: jeremythomerson@gmail.com [mailto:jeremythomerson@gmail.com] Im Auftrag von Jeremy Thomerson
Gesendet: Donnerstag, 8. Mai 2008 00:07
An: users@wicket.apache.org
Betreff: Re: Ajax and Loop

Can you paste some code?  Have you tried using a ListView in combination with a model (rather than passing a List to the constructor of ListView)?

Jeremy Thomerson
http://www.wickettraining.com

On Wed, May 7, 2008 at 4:55 PM, Stefan Lindner <li...@visionet.de> wrote:

> Dear wicket wizzards,
>
> I have a Loop on my page (creates Components from a List ot Objects).
> Now I have an AjaxFallbackLink on my page. This link adds an Object to 
> my List and as a reaction to this action I want my Loop to be 
> repainted (showing the new object). What must I do? A simple 
> "target.addComponent(Loop.getParent())" has no effect.
> The Components of the loop are created in the Constructor of the 
> Loop's parent. Do I have to overwrite some "beforeRender" methods? Of 
> course, I took a look at the Wicket In Action book and the Wiki and 
> the List but I did not find a hint. Can anybody help me?
>
> Stefan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

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


Re: Ajax and Loop

Posted by Jeremy Thomerson <je...@thomersonfamily.com>.
Can you paste some code?  Have you tried using a ListView in combination
with a model (rather than passing a List to the constructor of ListView)?

Jeremy Thomerson
http://www.wickettraining.com

On Wed, May 7, 2008 at 4:55 PM, Stefan Lindner <li...@visionet.de> wrote:

> Dear wicket wizzards,
>
> I have a Loop on my page (creates Components from a List ot Objects).
> Now I have an AjaxFallbackLink on my page. This link adds an Object to
> my List and as a reaction to this action I want my Loop to be repainted
> (showing the new object). What must I do? A simple
> "target.addComponent(Loop.getParent())" has no effect.
> The Components of the loop are created in the Constructor of the Loop's
> parent. Do I have to overwrite some "beforeRender" methods? Of course, I
> took a look at the Wicket In Action book and the Wiki and the List but I
> did not find a hint. Can anybody help me?
>
> Stefan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>