Refreshing a repeater component via ajax

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Refreshing a repeater component via ajax

Andreas
Can't refresh a repeater component after removing an item.
Error:
Last cause: Component com.shop.ShoppingCartPanel$1 has been added to the target. This component is a repeater and cannot be repainted via ajax directly. Instead add its parent or another markup container higher in the hierarchy.

Who is the parent for the cartcomponent? A Panel? But using target.add(this); is also giving an error.

public class ShoppingCartPanel extends Panel {

    private Cart cart;
    private Label total;
    private ListView<Cheese> cartcomponent;

    public ShoppingCartPanel(String id, Cart cart) {

        super(id);
        this.cart=cart;

        cartcomponent = new ListView<Cheese>("cart", new PropertyModel<List<Cheese>>(this, "cart.cheeses")) {
            @Override
            protected void populateItem(ListItem<Cheese> item) {

                Cheese cheese = item.getModelObject();

                item.add(new Label("name", cheese.getName()));
                item.add(new Label("price", "$" +cheese.getPrice()));

                item.add(new AjaxFallbackLink<Cheese>("remove", item.getModel()) {
                    @Override
                    public void onClick(AjaxRequestTarget target) {
                        Cheese selected = (Cheese) getModelObject();
                        getCart().getCheeses().remove(selected);
                        if(target!=null){
                            target.add(cartcomponent);
                            target.add(total);
                        }
                    }
                });
            }
        };

        cartcomponent.setOutputMarkupId(true);
        add(cartcomponent);
Reply | Threaded
Open this post in threaded view
|

Re: Refreshing a repeater component via ajax

Ernesto Reinaldo Barreiro-4
Hi,

On Mon, May 11, 2015 at 11:49 AM, Andreas <[hidden email]> wrote:

> Can't refresh a repeater component after removing an item.
> Error:
> /Last cause: Component com.shop.ShoppingCartPanel$1 has been added to the
> target. This component is a repeater and cannot be repainted via ajax
> directly. Instead add its parent or another markup container higher in the
> hierarchy./
>
> Who is the parent for the cartcomponent? A *Panel*? But using
> *target.add(this)*; is also giving an error.
>

You might need to qualify this with a name: MyPanel.this and also make sure
your panel call setOutputMarkupId(true)

>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Refreshing-a-repeater-component-via-ajax-tp4670710.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


--
Regards - Ernesto Reinaldo Barreiro
Reply | Threaded
Open this post in threaded view
|

Re: Refreshing a repeater component via ajax

Andreas
This post was updated on .
Hi,
actualy I resolved it using a component wrapper, but I'm interesting in what you realy suggest.

> You might need to qualify this with a name: MyPanel.this and also make sure
> your panel call setOutputMarkupId(true)

What is MyPanel?
Maybe you mean Panel.this?
...
target.add(Panel.this);
...
this.setOutputMarkupId(true);
Reply | Threaded
Open this post in threaded view
|

Re: Refreshing a repeater component via ajax

Ernesto Reinaldo Barreiro-4
Mind that your code gets removed once it arrives to the list: a known
limitation of using nabble. I mean


 public ShoppingCartPanel(String id, Cart cart) {

        super(id);
        this.cart=cart;

        // make panel repaintable via AJAX.
        setOutputMarkupId(true)

        cartcomponent = new ListView<Cheese>("cart", new
PropertyModel<List<Cheese>>(this, "cart.cheeses")) {
            @Override
            protected void populateItem(ListItem<Cheese> item) {

                Cheese cheese = item.getModelObject();

                item.add(new Label("name", cheese.getName()));
                item.add(new Label("price", "$" +cheese.getPrice()));

                item.add(new AjaxFallbackLink<Cheese>("remove",
item.getModel()) {
                    @Override
                    public void onClick(AjaxRequestTarget target) {
                        Cheese selected = (Cheese) getModelObject();
                        getCart().getCheeses().remove(selected);
                        if(target!=null){
                            target.add(ShoppingCartPanel.this);
                        }
                    }
                });
            }
        };
        add(cartcomponent);


On Mon, May 11, 2015 at 12:48 PM, Andreas <[hidden email]> wrote:

> Hi,
> actualy I resolve it using a component wrapper, but I'm interesting in what
> you realy suggest.
>
> > You might need to qualify this with a name: MyPanel.this and also make
> > sure
> > your panel call setOutputMarkupId(true)
>
> What is MyPanel?
> Maybe you mean *Panel.this*?
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Refreshing-a-repeater-component-via-ajax-tp4670710p4670712.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


--
Regards - Ernesto Reinaldo Barreiro
Reply | Threaded
Open this post in threaded view
|

Re: Refreshing a repeater component via ajax

Ernesto Reinaldo Barreiro-4
If you use only this it would refer to the anonymous AjaxFallbackLink

On Mon, May 11, 2015 at 1:33 PM, Andreas <[hidden email]> wrote:

>
> Yes. it works, but what in the above *this* means? Is not it the same with
> next?
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Refreshing-a-repeater-component-via-ajax-tp4670710p4670714.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


--
Regards - Ernesto Reinaldo Barreiro