简体   繁体   中英

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

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);
}

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM