I have problem with displaying multiple panels which contain for example a label and a button. I want to listen for button click and display label value from the panel.
Code looks something like this:
for(int i=0; i < 5;i++){
Panel p = new Panel("panel "+i);
Label l = new Label("label "+ i);
p.addComponent(l);
Button show = new Button("Show Label in subWindow", new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
Window sub = new Window("testing "+label);
getMainWindow().addWindow(sub);
}
});
}
I know that this code on every button remember the last value of label.
How can i in loop for every pass bind specific button to display value of specific label?
I am trying to achive something like PageableListView control in wicket.
I want in every pass to make different button ID. But, there is no method such as setButtonID(Object o).
Abstract Component has variable “description” :smug:
I could make different identify by description.
Code something like this:
ArrayList<Product> products = PData.getProducts();
for(int i = 0; i < products.size(); i++) {
Panel p = new Panel("ID "+products.get(i).getID());
Label l = new Label("Name "+ products.get(i).getName());
Button b = new Button("Details");
b.setDescription("ID "+products.get(i).getID());
b.addListener((ClickListener) this);
}
...
public void buttonClick(ClickEvent event) {
for(int i=0;i<products.size();i++){
if(event.getButton().getDescription().equals("ID: "+products.get(i).getID()))
{
Window sub = new Window("Product "+event.getButton().getDescription());
Label name = new Label("Name: "+products.get(i).getName());
sub.addComponent(name);
getMainWindow().addWindow(sub);
}
}
}
I’m not entirely sure if I understand your question, but from the looks of it you might want to try setting button.setData(product) when creating the button so you can then get a reference to the button in the listener with event.getButton().getData().