Vaadin 7.6.5. I am trying to figure out why a value change listener fails in the below case? The CheckBox is observing for addValueChangeListener OptionGroup.
@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);
}
}
It logs:
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 ...
答案 0 :(得分:0)
我认为你想要像...这样的东西。
runtimes.txt
而不是......
group.addValueChangeListener(new ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
//Do something with box here? e.g...
box.setValue(!box.getValue());
}
});