Vaadin 7.6.5。 我想弄清楚为什么在下面的情况下值更改侦听器失败? CheckBox正在观察addValueChangeListener OptionGroup。OptionGroup addValueChangeListener CheckBox
@Theme("vaadindemo")
public class VaadindemoUI extends UI {
@WebServlet(value = "/*", asyncSupported = true)
@VaadinServletConfiguration(productionMode = false, ui = VaadindemoUI.class)
public static class Servlet extends VaadinServlet {
}
@Override
protected void init(VaadinRequest request) {
final VerticalLayout layout = new VerticalLayout();
layout.setMargin(true);
setContent(layout);
OptionGroup group = new OptionGroup();
group.addItem("01");
group.setItemCaption("01", "ONE");
group.addItem("02");
group.setItemCaption("02", "TWO");
group.addItem("03");
group.setItemCaption("03", "THREE");
group.addValueChangeListener(new ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
System.out.println("group getValue " + event.getProperty().getValue());
System.out.println("group getType " + event.getProperty().getType());
}
});
CheckBox box = new CheckBox();
box.setCaption("Check Me");
//Notify CheckBox of value change of radio button
//group.addValueChangeListener(box); -- // Code Fails
//box.addValueChangeListener(group); // Selected Radio Button is removed
TextField field = new TextField();
field.addValueChangeListener(new ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
System.out.println("field getValue " + event.getProperty().getValue());
System.out.println("field getType " + event.getProperty().getType());
System.out.println("field getType " + field.getValue());
}
});
group.addValueChangeListener(field);// The value is reflected. How do i get only the event without over writing the value
//group.addValueChangeListener(box);
layout.addComponent(group);
layout.addComponent(box);
layout.addComponent(field);
Button button = new Button("Click Me");
button.addClickListener(new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
layout.addComponent(new Label("Thank you for clicking"));
}
});
layout.addComponent(button);
}
}
它记录:
com.vaadin.data.util.converter.Converter$ConversionException: Unable to convert value of type java.lang.String to presentation type class java.lang.Boolean. No converter is set and the types are not compatible. at com.vaadin.data.util.converter.ConverterUtil.convertFromModel(ConverterUtil.java:116) at com.vaadin.ui.AbstractField.convertFromModel(AbstractField.java:736) at com.vaadin.ui.AbstractField.convertFromModel(AbstractField.java:721) at ...
我想知道是什么你是在试图达到那种约束力?如你所见,绑定一个OptionGroup和一个CheckBox是不可能的。 –
嗨,亨利,我看着观察者模式。我需要一个表单中的所有组件来查找OptionGroup的值更改。 OptionGroup的值更改应该触发其他组件更新其状态。 addValueChangeListener适用于TextBox。我不知道为什么值属性试图映射到CheckBox(布尔值),因为CheckBox只对接收事件感兴趣。 – Ravi
代替CheckBox,我添加了一个TextField。当我点击CheckBox时,CheckBox的值显示在TextField中。我正在寻找的是事件并且对价值不感兴趣。 – Ravi