title: wicket refresh listView in different panel using ajax
body: <p>Hy guys I'm newbie in Wicket and I'm start playing this framework.
  I know will be a very useless example but I try to use that for learn wicket basics.
  This is my situation:</p>
  
  <p>I get a page <strong>IndexPage.java</strong> that is composed from basically 2 panel, the first one is <strong>ListCheesePanel.java</strong> ( it basically show a list of cheese with price,etc and a button for to add to the cart the selected cheese) and the second one is <strong>CartPanel.java</strong> that is essentially a cart wherein you have all the selected cheeses and you can proceed to checkOut.</p>
  
  <p>I would basically add on cheese from my list to the cart using ajax behaviour:</p>
  
  <p><strong>ListCheesePanel.java</strong></p>
  
  <pre><code>public abstract class ListCheesePanel extends GenericPanel&lt;List&lt;Cheese&gt;&gt;{
  
      private static final long serialVersionUID = 1L;
  
      public ListCheesePanel(String id,final IModel&lt;List&lt;Cheese&gt;&gt; listCheeseModel) {
          super(id,listCheeseModel);
          PageableListView&lt;Cheese&gt; cheeses = new PageableListView&lt;Cheese&gt;("cheeses", listCheeseModel, 4) {
  
              private static final long serialVersionUID = 1L;
  
              @Override
              protected void populateItem(final ListItem&lt;Cheese&gt; item) {
  
                  Cheese cheese = (Cheese) item.getModelObject();
                  item.addOrReplace(new Label("name", Model.of(cheese.getName())));
                  item.addOrReplace(new Label("description", Model.of(cheese.getDescription())));
                  item.addOrReplace(new Label("price", Model.of("$ " + cheese.getPrice())));
                  item.addOrReplace(new AjaxFallbackLink&lt;Cheese&gt;("add",item.getModel()) {
  
                      private static final long serialVersionUID = 1L;
  
                      @Override
                      public void onClick(AjaxRequestTarget target) {
                          elementClicked(target, item.getModelObject());
                      }
                  });
              }
          };
          addOrReplace(cheeses);
          addOrReplace(new PagingNavigator("navigator", cheeses));
      }
  
      protected abstract void elementClicked(AjaxRequestTarget target,Cheese cheese);
  }
  </code></pre>
  
  <p><code>elementClicked</code> is a method that must be ovverride in order to indicate the cheese and the target.</p>
  
  <p><strong>CartPanel.java</strong></p>
  
  <pre><code>public abstract class CartPanel extends GenericPanel&lt;Cart&gt;{
  
      private static final long serialVersionUID = 1L;
  
      private WebMarkupContainer cartContainer;
      private ListView&lt;Cheese&gt; cheesesList;   
      private Link&lt;Cart&gt; checkOutLink;
      private boolean checkOutButtonVisibility;
  
      public CartPanel(String id,final IModel&lt;Cart&gt; cartModel,final boolean checkOutButtonVisibility) {
          super(id,cartModel);
          this.checkOutButtonVisibility=checkOutButtonVisibility;
          cartContainer = new WebMarkupContainer("cartContainer");
          cartContainer.setOutputMarkupId(true);
          addOrReplace(cartContainer);
          cheesesList = new ListView&lt;Cheese&gt;("cart" , getModelObject().getCheeses()){
  
              private static final long serialVersionUID = 1L;
  
              @Override
              protected void populateItem(final ListItem&lt;Cheese&gt; item) {
                  Cheese cheese = item.getModelObject();
                  item.addOrReplace(new Label("name",cheese.getName()));
                  item.addOrReplace(new Label("price",cheese.getPrice()));
                  item.addOrReplace(new Link&lt;Cheese&gt;("remove",item.getModel()) {
  
                      private static final long serialVersionUID = 1L;
  
                      @Override
                      public void onClick() {
                          removeElement(item.getModelObject());
                      }
                  });
              }
          };
  
          cheesesList.setOutputMarkupId(true);        
          cartContainer.addOrReplace(cheesesList);
          cartContainer.addOrReplace(new Label("total",new PropertyModel&lt;Long&gt;(cartModel.getObject(), "total")));
  
          checkOutLink = new Link&lt;Cart&gt;("checkOut",getModel()){
  
              private static final long serialVersionUID = 1L;
  
              @Override
              public void onClick() {
                  setResponsePage(new CheckOutPage(getModel()));
              }
  
              @Override
              protected void onConfigure() {
                  super.onConfigure();
                  Cart cart = cartModel.getObject();
                  List&lt;Cheese&gt; cheeseList = cart.getCheeses();
                  setVisible(isCheckOutButtonVisibility() &amp;&amp; !cheeseList.isEmpty());
              }
  
         };    
  
         addOrReplace(checkOutLink);
      }
  
      protected abstract void removeElement(Cheese modelObject);
  
      /* Getters and Setters */
  
      public boolean isCheckOutButtonVisibility() {
          return checkOutButtonVisibility;
      }
  }
  </code></pre>
  
  <p><strong>IndePage.java</strong></p>
  
  <pre><code>public class IndexPage extends CheeseTemplate {
  
      private static final long serialVersionUID = 1L;
      private static List&lt;Cheese&gt; cheeses = Arrays.asList(
              new Cheese("Gouda", "Gouda is a yellowish Dutch[...]", 1.65),
              new Cheese("Edam", "Edam (Dutch Edammer) is a D[...]", 1.05),
              new Cheese("Maasdam", "Maasdam cheese is a Dutc[...]", 2.35),
              new Cheese("Brie", "Brie is a soft cows' milk c[...]", 3.15),
              new Cheese("Buxton Blue", "Buxton Blue cheese i[...]", 0.99),
              new Cheese("Parmesan", "Parmesan is a grana, a [...]", 1.99),
              new Cheese("Cheddar", "Cheddar cheese is a hard[...]", 2.95),
              new Cheese("Roquefort", "Roquefort is a ewe's-m[...]", 1.67),
              new Cheese("Boursin", "Boursin Cheese is a soft[...]", 1.33),
              new Cheese("Camembert", "Camembert is a soft, c[...]", 1.69),
              new Cheese("Emmental", "Emmental is a yellow, m[...]", 2.39),
              new Cheese("Reblochon", "Reblochon is a French [...]", 2.99));
  
      private IModel&lt;List&lt;Cheese&gt;&gt; allCheeseListModel;
      private IModel&lt;Cart&gt; cartModel;
      private Cart cart;
  
      public IndexPage() {
          super();
          allCheeseListModel = new ListModel&lt;Cheese&gt;(cheeses);
          cart=new Cart();
          cartModel = new Model&lt;Cart&gt;(cart);
      }
  
      public IndexPage(IModel&lt;Cart&gt; cartModel) {
          super();
          allCheeseListModel = new ListModel&lt;Cheese&gt;(cheeses);
          this.cartModel=cartModel;
      }
  
      @Override
      public Component getMainPanel() {
          System.out.println("getMainPanel started");
  
          return new ListCheesePanel(MAIN_PANEL_WICKET_ID,allCheeseListModel){
  
              private static final long serialVersionUID = 1L;
  
              @Override
              protected void elementClicked(AjaxRequestTarget target,Cheese cheese) {
                  Cart cart = cartModel.getObject();
                  cart.getCheeses().add(cheese);
                  target.add(?????); // How can i get the cart container to update????
              }
          };
      }
  
      @Override
      public Component getRightMenuPanel() {
          CartPanel cartPanel = new CartPanel(RIGHT_MENU_PANEL_WICKET_ID,cartModel,true) {
  
              private static final long serialVersionUID = 1L;
  
              @Override
              protected void removeElement(Cheese cheese) {
                  Cart cart = cartModel.getObject(); 
                  cart.getCheeses().remove(cheese);
              }
          };
          cartPanel.setOutputMarkupId(true);
          return cartPanel;
      }
  
  }
  </code></pre>
  
  <p>My question is:</p>
  
  <p><strong>How can I get the reference of the component to update(so I think is cartContainer in my example because I can't add directly a listView component to the target) if this component is located in another panel??</strong></p>
  
  <p>Thanks in advance</p>