getItemProperty返回的值不为null-Vaadin错误? [英] getItemProperty returns not null - Vaadin bug?

查看:77
本文介绍了getItemProperty返回的值不为null-Vaadin错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助,也许我是盲人。这是我的代码的一部分:

I need help, maybe I am blind. Here is a fragment of my code:

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 ...

返回

这是在我的控制台上编写的:

It returns a currious null value instead of continue, even if the propertyId doesn't exists.
This is written on my console:

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

第一行显示属性名称列表。

我希望getTtemProperty必须返回null,但是

The first row shows list of property names.
I expected getTtemProperty must return null, but not.


该物品来自IndexedContainer。


The item comes from IndexedContainer.


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


Can you help me? Any idea? Thanky You.

推荐答案

我测试了你的代码,的确-即使IndexedContainer中不存在属性p,属性p也不为空。阅读kris54321粘贴的Vaadin票证的注释,不修复该错误很有意义,因为某些应用程序可能依赖该功能。

I tested your code and indeed - property p is not null even though property doesn't exist in IndexedContainer. Reading the comments of Vaadin ticket pasted by kris54321, it makes sense not fixing the bug as some applications may rely on that feature. Fixing the bug may break those apps.

此问题的可能解决方法:

Possible workarounds for this problem:

直接检查propertyId集合,如果容器中存在属性:

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
{

这篇关于getItemProperty返回的值不为null-Vaadin错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆