getItemProperty返回非null - Vaadin bug?

时间:2014-10-02 15:16:07

标签: containers vaadin

我需要帮助,也许我是盲人。这是我的代码片段:

System.out.println("itemPropertyIDS="+item.getItemPropertyIds().toString());
System.out.println("argname="+argName);
Property<?> p = item.getItemProperty(argName);
if (p != null) {
    System.out.println("p="+p.toString());
    return p.getValue();
}

// Continue ...

即使propertyId不存在,它也会返回一个currious null值而不是continue 这是写在我的控制台上的:

itemPropertyIDS=[iconName, iconResource, nodeType, nodeValue, nodeName, handler, nodeData]
argname=Lab
p=com.vaadin.data.util.IndexedContainer$IndexedContainerProperty@12967

第一行显示属性名称列表 我希望getTtemProperty必须返回null,但不是。

该项目来自IndexedContainer。

你能帮帮我吗?任何的想法?谢谢你。

2 个答案:

答案 0 :(得分:4)

我测试了你的代码,确实 - 即使属性在IndexedContainer中不存在,属性p也不是null。阅读kris54321粘贴的Vaadin票证的评论,因为某些应用程序可能依赖于该功能,因此无法修复该错误。修复错误可能会破坏这些应用程序。

此问题的可能解决方法:

如果容器中存在属性,请直接检查propertyId-collection:

if(item.getItemPropertyIds().contains(argName) {
    Property<?> p = item.getItemProperty(argName);
    System.out.println("p="+p.toString());
    return p.getValue()
}

更改逻辑以检查属性值

if(item.getItemProperty(argname).getValue() != null) }
    //Do things
{

答案 1 :(得分:0)

我被迫使用“item.getItemPropertyIds()。contains(argName)”来解决方法。对我来说,优先级是检查项目是否包含值(可能为null)。如果是,那么我使用该值(可以为null),否则完成另一项活动
如果他们不想修复因应用程序使用bug而导致的错误,那么应该修复文档,否则Vaadin中的所有新手(因为我都会)会感到困惑。
IndexedContainer $ IndexedContainer中的实现是错误的:

 @Override
 public Property getItemProperty(Object id) {
        return new IndexedContainerProperty(itemId, id);
 }

如文档所述,这永远不会返回null。