我在Wildfly应用程序服务器上将Vaadin7 com.vaadin.ui.CheckBox
与Java 1.8一起使用。
我有一个具有以下复选框配置的PopUpDialog:
checkBox1.addValueChangeListener(event -> // Java 8
LOGGER.info("property Value: "+ event.getProperty().getValue().toString()+
" getValue Value: "+checkBox1.getValue()));
当我在WebBrowser的用户界面中单击checkBox1
时,将调用ValueChangeListener
。
第一个property Value "event.getProperty().getValue().toString()"
返回复选框的正确true/false
状态。
但是我想在我的PopUpDialog类方法中使用的checkBox1.getValue()
访问复选框的true/false == clicked/not clicked
状态始终返回false
,即使我在ValueChangeListener
中调用它也是如此
有人可以帮我为什么“ getValue()”方法不能返回正确的状态吗?
----------------- EDIT ---------------
一种解决方案是使用ValueChangeListener设置复选框的值:
checkBox1.addValueChangeListener(event ->
checkBox1.setValue(
(Boolean) event.getProperty().getValue()
));
但是通常应该在没有监听器手动设置的情况下设置该值,对吗?
什么是PopUpDialog
类?是一些附加组件吗? (没有通过短暂的谷歌搜索找到自己)
我已经尝试过使用PopupView
的情况,并且总是正确返回值。 Vaadin版本为7.7.13
CheckBox cb=new CheckBox();
cb.addValueChangeListener(e->{
System.out.println("Event value" + e.getProperty().getValue());
System.out.println("cb value: " + cb.getValue());
});
VerticalLayout popupContent = new VerticalLayout();
Button getValue=new Button("Value", e->{
Notification.show("CB value:" + cb.getValue());
});
popupContent.addComponents(cb,getValue);
PopupView popup = new PopupView("Pop it up", popupContent);
layout.addComponent(popup);
setContent(layout);
示例中有什么我想念的吗?
编辑:当然,复选框应该返回正确的值。否则,是个错误