繁体   English   中英

单击底部 vaadin 上的处理程序

[英]click handler on bottom vaadin

我需要为表格中的一列添加一个点击处理程序,所以如果表格有 3 行,我需要为每一行添加一个点击处理程序; 但我还需要向点击处理程序添加一个值(以允许我区分行); 换句话说:

我有这个clickHandler:

btnElimina.addClickListener(new Button.ClickListener() {

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

我应该想要一些东西,像这样:

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

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

那可能吗? 我用谷歌搜索了它,但没有找到解决方案; 此外,如果我尝试使用 ClickEvent,似乎没有什么可以用来区分行;

感谢帮助

对于 Vaadin 7,您可以在“表中的组件”部分的官方文档中找到示例。 TLDR:您可以使用组件中的setData() / getData()来传递识别信息。

相关部分在这里:

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

我以这种方式解决了这个问题:

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

它现在似乎有效;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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