I am a Wicket newbie and am currently struggling with
CompoundPropertyModel. I have found a lot on the list about
CompoundPropertyModel but not regarding this specific issue. I am
building a shopping cart. I have placed the cart's form inside a panel
and the cart items (via DataView) are inside the form. ShoppingCart is a
model that I would like to use to represent the current state of the
entire cart. It contains a array of ShoppingCartItem 's. However, when
running this, cartItems never gets set on the ShoppingCart model. While
debugging, cartItems is a child of the panelForm, but never gets
populated on the ShoppingCart pojo via CompoundPropertyModel. The form
does persist and if I traverse the panelForm object I could figure out
how to get to the ShoppingCartItem's...but I'd rather not. J

 

What am I missing? Is there a better way to do this? See code attached
below.

 

Thanks!!

 

<code>

...

public CartPanel(String id) {

      super(id);

      Form panelForm = new Form("panelForm", new
CompoundPropertyModel(new ShoppingCart())) {

            @Override

            protected void onSubmit() {

                  // need to rewrite cookie on update

                  ShoppingCart cart = (ShoppingCart) getModelObject();

                  System.out.println(cart.getCartItems());// check if
cart items got populated

            }

      };

      add(panelForm);

 

      IDataProvider dataProvider = new ShoppingCartItemsProvider();

      DataView dataView = new DataView("cartItems", dataProvider) {

            @Override

            protected void populateItem(final Item item) {

                  final ShoppingCartItem cartItem = (ShoppingCartItem)
item

                        .getModelObject();

                  item.add(new Label("itemName", cartItem.getName()));

                  item.add(new TextField("quantity", new
ShoppingCartItemModel(

                        new Model(cartItem),
ShoppingCartItemType.QUANTITY)));

            }

      };

      // add general text labels and buttons to the cart

      addFieldsAndButtons(panelForm);

      panelForm.add(dataView);

}...

</code>

 

Thanks!!

 


--------------------------------------------------------------------------
This e-mail and any attachments may contain confidential material for the sole 
use of the intended recipient. If you are not the intended recipient, please be 
aware that any disclosure, copying, distribution or use of this e-mail or any 
attachment is prohibited. If you have received this e-mail in error, please 
contact the sender and delete all copies.
Thank you for your cooperation.

Reply via email to