如何在vaadin中将单击侦听器添加到表的单元格中?
我在vaadin中创建了一个多选表,但是当我单击它时,我不能只选择该表中的一个单元格,而是选择所有行如何在vaadin中将单击侦听器添加到表的单元格中?,vaadin,cell,clicklistener,Vaadin,Cell,Clicklistener,我在vaadin中创建了一个多选表,但是当我单击它时,我不能只选择该表中的一个单元格,而是选择所有行 有没有办法只选择一行中的一个单元格?问题的标题不能反映问题的实际内容 有没有办法只选择一行中的一个单元格 不。Vaadin表格的全部要点是以表格形式反映数据行。将表格设置为“可选”可跟踪表格中选定行的ItemID 您可以通过使用表中的,并向生成的组件添加侦听器来模拟选择单元格。然而,删除侦听器可能很棘手 或者,您可能希望简单地在中生成组件,并自己跟踪所选单元格 归根结底,这里的方法实际上取决于你
有没有办法只选择一行中的一个单元格?问题的标题不能反映问题的实际内容 有没有办法只选择一行中的一个单元格 不。Vaadin表格的全部要点是以表格形式反映数据行。将表格设置为“可选”可跟踪表格中选定行的ItemID 您可以通过使用表中的,并向生成的组件添加侦听器来模拟选择单元格。然而,删除侦听器可能很棘手 或者,您可能希望简单地在中生成组件,并自己跟踪所选单元格
归根结底,这里的方法实际上取决于你想要实现的目标。它取决于你想要实现的目标。您的问题标题和问题详细信息针对两个不同的问题。如果您想知道是否可以针对特定单元格并向其添加单击侦听器,那么当然可以:
//initial layout setup
final VerticalLayout layout = new VerticalLayout();
layout.setMargin(true);
setContent(layout);
//Create a table and add a style to allow setting the row height in theme.
final Table table = new Table();
table.addStyleName("components-inside");
//Define the names and data types of columns.
//The "default value" parameter is meaningless here.
table.addContainerProperty("Sum", Label.class, null);
table.addContainerProperty("Is Transferred", CheckBox.class, null);
table.addContainerProperty("Comments", TextField.class, null);
table.addContainerProperty("Details", Button.class, null);
//Add a few items in the table.
for (int i=0; i<100; i++) {
// Create the fields for the current table row
Label sumField = new Label(String.format(
"Sum is <b>$%04.2f</b><br/><i>(VAT incl.)</i>",
new Object[] {new Double(Math.random()*1000)}),
Label.CONTENT_XHTML);
CheckBox transferredField = new CheckBox("is transferred");
//Multiline text field. This required modifying the
//height of the table row.
TextField commentsField = new TextField();
//commentsField.setRows(3);
//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.addListener(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.");
}
});
detailsField.addStyleName("link");
//Create the table row.
table.addItem(new Object[] {sumField, transferredField,
commentsField, detailsField},
itemId);
}
//Show just three rows because they are so high.
table.setPageLength(3);
layout.addComponent(table);
检查一下可能会有好处。谢谢您的回答。我搜索了ColumnGenerator并编写了一个代码,但它不起作用。我正在尝试执行table7X24,当我单击某个单元格时,该行中的其他单元格将不会被选中。如果你能给我举个简单的例子,我会很高兴的。@Hasan:你试过把表格设置为SelectableFalse吗?没有。代码在这里。程序只创建表,不加载内容。表像表模型一样反映容器。由于没有添加行/项,因此没有内容。查看Vaadin论坛上的这篇文章,了解ColumnGenerator的工作示例亲爱的Charles,此代码不起作用。类型异常报告消息:描述服务器遇到内部错误,无法满足此请求异常:javax.servlet.ServletException:java.lang.ClassCastException:com.example.testwindow.testwindow不能强制转换为com.vaadin.Application com.vaadin.terminal.gwt.server.AbstractApplicationServlet.HandleServiceException AbstractApplicationServlet.java:1004 com.vaadin.terminal.gwt.server.AbstractApplicationServlet.ServiceStratApplicationServlet.java:548javaservlet.http.HttpServlet.serviceHttpServlet.java:717