【问题标题】:How does the Vaadin table work with Navigator?Vaadin 表如何与 Navigator 一起使用?
【发布时间】:2014-11-04 08:07:57
【问题描述】:

I'm writing a view which navigates to a table entry's page displayed on the left side when a table entry (on the right) is chosen.这类似于 Vaadin 网站上的地址簿教程,只是我使用了导航器和视图。

当我让导航工作时(单击 id #12 的条目导航到 localhost:8080/test/12)并且视图的 enter() 中的测试标签被更改以匹配 id,testTable.getItem(event .getParameters()) 出于某种原因返回 null,因此我无法访问该条目。

视图的 ValueChangeListener 和 enter() 如下所示。

    class ValueChangeListener implements Property.ValueChangeListener {
        Object testId;

        @Override
        public void valueChange(ValueChangeEvent event) {
            // Navigate to a chosen table entry
            this.testId = event.getProperty().getValue();
            navigator.navigateTo("test/" + testId);
        }
    }

    ...

    public void enter(ViewChangeEvent event) {
        Object tmp = event.getParameters();
        testName.setValue((String) tmp);    // is set to the id
        System.out.println(testTable.getItem(tmp) == null);    // DEBUG: always returns true
    }

【问题讨论】:

  • 如何创建testTable?你用的是什么类型的Container
  • @Krayo 我使用IndexedContainer 作为表格。 createTestTable() 将容器属性添加到 ic 并使用 for 循环填充它,该循环使用 ic.addItem() 将对象添加到表中,并在返回 ic 之前使用 setValue() 设置该对象的值。表创建类似于address book tutorial at Vaadin uses

标签: vaadin vaadin7


【解决方案1】:

我认为你应该改变这个:

System.out.println(testTable.getItem(tmp) == null);

到这里:

String str = (String) tmp;
if (str != null && !str.isEmpty()) {
    System.out.println(testTable.getItem(Integer.parseInt(str)) == null);
}

【讨论】:

  • 我试过了,但是 Eclipse 给了我错误 ´java.lang.NumberFormatException: For input string: ""´。测试表没有那么大,parseLong 报同样的错误,所以也不可能是 id 超过最大整数的情况。
  • @MarkusM。我编辑了我的答案。什么时候第一次显示异常?
  • isEmpty() 没有根据 Eclipse 为对象定义,它唯一的建议是将tmp 转换为AbstractField<Date>
  • 您的代码有效,现在我可以按应有的方式显示条目信息。谢谢。
【解决方案2】:

我认为您管理 Navigator 的方式有问题。 首先,当您使用 Navigator 更改视图时,您应该使用“#”添加适当的“URL 片段”。 例如 Vaadin 采样器使用: http://demo.vaadin.com/sampler/#foundation

如果您的 URL 中没有“#”,则 ViewChangeEvent.getParameters() 会为您提供 nullisEmpty()

【讨论】:

    猜你喜欢
    • 2017-12-27
    • 2013-12-11
    • 1970-01-01
    • 2014-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-11
    • 1970-01-01
    相关资源
    最近更新 更多