fraaanz
fraaanz

Reputation: 117

click handler on bottom vaadin

I need to add a click Handler for a column in a table, so if the table has 3 row I need to add a clickhandeler for every row; But I need also to add a value (to allow me to distinguish between rows) to the click handeler; In other words:

I have this clickHandler:

btnElimina.addClickListener(new Button.ClickListener() {

                @Override
                public void buttonClick(ClickEvent event) {
                    System.out.println( "nell handler  " );
                }
            }); 

and I should want some thing, like this:

btnElimina.addClickListener(new Button.ClickListener(String Val) {

                @Override
                public void buttonClick(ClickEvent event) {
                    System.out.println( "nell handler con "+ val );
                }           });

Is that possible? I've googled on it but didn't find a solution; Also If I try to use the ClickEvent there seems nothing that I can use to distinguish between rows;

thanks for help

Upvotes: 0

Views: 82

Answers (2)

fraaanz
fraaanz

Reputation: 117

I resolved the issue in this way:

public class TableListe extends CustomComponent implements Button.ClickListener{
    
    private String istituto;
    
    public TableListe(String ista) {
        //super();      
        this.istituto = ista;
    }

    @Override
    public void buttonClick(ClickEvent event) {
        System.out.println( "  nell handler con this.istituto " + this.istituto);   
    }
}

It seems to work for now;

Upvotes: 1

ollitietavainen
ollitietavainen

Reputation: 4275

For Vaadin 7, you can find an example in the official documentation in the "Components Inside a Table" section. TLDR: you can use setData() / getData() from the Component to pass identifying information.

The relevant pieces are here:

Table table = new Table();
table.addStyleName("components-inside");

table.addContainerProperty("Details",        Button.class,    null);

/* Add a few items in the table. */
for (int i=0; i<100; i++) {
    // The Table item identifier for the row.
    Integer itemId = new Integer(i);

    // Create a button and handle its click. A Button does not
    // know the item it is contained in, so we have to store the
    // item ID as user-defined data.
    Button detailsField = new Button("show details");
    detailsField.setData(itemId);
    detailsField.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            // Get the item identifier from the user-defined data.
            Integer iid = (Integer)event.getButton().getData();
            Notification.show("Link " +
                              iid.intValue() + " clicked.");
        }
    });
    // Create the table row.
    table.addItem(new Object[] {detailsField},
                  itemId);
}

Upvotes: 1

Related Questions