【问题标题】:Unable to select table row by clicking on ui component inside a column of table in Vaadin无法通过单击 Vaadin 中表格列内的 ui 组件来选择表格行
【发布时间】:2016-04-27 08:46:52
【问题描述】:

我正在使用 Vaadin 框架创建一个 Web 应用程序,但遇到了一个表元素(过滤表)。我的表格有一列,每行都包含 ComboBox 组件,现在表格中的组合框可以正常工作,但是我无法单击该列来选择表格值。可以通过单击表格中的空格来选择行组合框和列边界但不能通过单击组合框本身来选择。 我搜索了很多,找到了https://vaadin.com/forum/#!/thread/988648/988647,尝试实现黑板插件,但没有成功。我的代码大致如下。

PagedFilterTable<IndexedContainer> filterTable;
     `public static PagedFilterTable<IndexedContainer> buildPagedFilterTable()
         {
                    filterTable = new PagedFilterTable<IndexedContainer>();
                    filterTable.setFilterBarVisible(true);
                    filterTable.setSelectable(true);
                    filterTable.setImmediate(true);
                    filterTable.setMultiSelect(true);
                    filterTable.setRowHeaderMode(RowHeaderMode.INDEX);
                    filterTable.setColumnCollapsingAllowed(true);
                    filterTable.setContainerDataSource(buildContainer());
                    filterTable.setVisibleColumns((Object[]) new String[] {
                            "Clear", "Name" });
                    return filterTable;
                }` 
          static int f=1;
                private static Container buildContainer() {
                    IndexedContainer cont = new IndexedContainer();


                    cont.addContainerProperty("Clear", Component.class, null);// added combobox component
                    cont.addContainerProperty("Name", String.class, null);


                    //populating table with database values (table rows will be = no. of rows in db)
                    Connection con;
                    ResultSet rs;
                    Statement cs;   
                    try {

                        Class.forName("oracle.jdbc.driver.OracleDriver");
                        con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","CGoracle");
                        cs=con.createStatement();
                        co=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
                        rs = cs.executeQuery("select * from ECS_CURRENT");  
                        while(rs.next())
                        {

                             ComboBox select_reason_return=new ComboBox();          
                            select_reason_return.setInputPrompt("Select");
                            select_reason_return.setVisible(true);
                            select_reason_return.setNullSelectionAllowed(false);
                            select_reason_return.setInvalidAllowed(false);
                            select_reason_return.addItem("1.A/c Closed/Transfered");
                            select_reason_return.addItem("2.No Such A/c");
                            select_reason_return.addItem("3.Clear");

                            select_reason_return.select("3.Clear");
                            select_reason_return.addListener(new Property.ValueChangeListener() {


                                @Override
                                public void valueChange(ValueChangeEvent event) {

                                    String reason=select_reason_return.getValue().toString();
                            rowId=FilterTable.getValue();
                            Notification.show("row id is ="+rowId);
            }
                        });

                             cont.addItem(f);

                                cont.getContainerProperty(f, "Clear").setValue(select_reason_return);
                                cont.getContainerProperty(f, "Name").setValue(rs.getString(10));

                            f++;

                        }

                    } 
                    catch (SQLException | ClassNotFoundException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } 

                    return cont; 
              }

If it helps, I'm posting screenshots, Image 1: if I select anywhere other than the combobox, it is returning row id properly.Image 2: Though I'm selecting an item from combobox, table row is not getting seleced, hence it's not returning me row id. 除了黑板插件还有其他选择吗?如果没有,那么请帮我解决这个问题。

【问题讨论】:

    标签: vaadin vaadin7


    【解决方案1】:

    这不是最好的方法,但是,您可以通过以下方式实现:在 ComboBox 上放置一个 Listener 以了解它何时被点击。然后,在这种情况下,您将获得与 ComboBox 关联的行,以最终获得与该行关联的 id。

    获得行 ID 后,使用 Table.select() 方法选择项目行。

    这不是最好的方法,如果您有很多行,您会感觉到它的响应速度很慢,但这是我发现的唯一使其工作的编程方式。希望对您有所帮助。

    【讨论】:

    • 我已经在上面的代码中实现了你建议的方法,但是它返回我的行 ID 为空,上面附上了屏幕截图以显示相同。
    猜你喜欢
    • 1970-01-01
    • 2017-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-09
    • 2021-06-25
    • 2018-10-10
    • 2012-04-02
    相关资源
    最近更新 更多