implement getListItemModel of the listView and make a CompoundModel for that listitem
protected IModel getListItemModel(final IModel listViewModel, final int index)
{
return new CompoundPropertyModel(super.getListItemModel(listViewModel, index));
}
then in populate item:
listItem.add(new Label("name"));
listItem.add(new Label("description"));
listItem.add(new Label("sponser"));
listItem.add(new Label("price"));
listItem.add
(new Label("id"));
listItem.add(new Label("promotion"));
listItem.add(new TextField("amount"));
Link buyLink = new Link("buyLink")
{
public void onClick()
{
setResponsePage(new MyCart((ProductList)listItem.getModelObject()));
}
public boolean linksTo(Page page)
{
if (!(page instanceof MyCart))
return false;
return true;
}
};
listItem.add(buyLink);
Hay, Guys,
In my application, i use a table with TextField as Shopping Cart list. but i cannot get the value of the textfield. Help please. Code fragments followed.final ProductList value = (ProductList) listItem.getModelObject();
listItem.add(new Label("name", value.getName()));
listItem.add(new Label("description", value.getDescription()));
listItem.add(new Label("sponser", value.getSponser()));
listItem.add(new Label("price", value.getPrice()));
listItem.add(new Label("id", value.getId()));
listItem.add(new Label("promotion", value.getPromotion()));
//I want to get the value of the textField ,but i cannot
listItem.add(new TextField("amount",new PropertyModel(value,"amount")));Link buyLink = new Link("buyLink")
{
public void onClick()
{
parameters.setParameter("name", value.getName().toString());
parameters.setParameter("description", value.getDescription().toString());
parameters.setParameter("sponser", value.getSponser().toString());
parameters.setParameter("price", value.getPrice().toString());
parameters.setParameter("id", value.getId().toString());
parameters.setParameter("promotion", value.getPromotion().toString());
//NullPointerException will be thrown, because value.getAmount() is Null
parameters.setParameter("amount", value.getAmount().toString());setResponsePage(new MyCart(parameters));
}
public boolean linksTo(Page page)
{
if (!(page instanceof MyCart))
return false;
return true;
}
};
listItem.add(buyLink);
