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