Frage

I have two fields binded with a fieldgroup. I need to make the second field change when the first field loses focus.

What I have so far:

class MyBean {
    private String first;
    private String second;

    //getters, setters
}

class MasterData extends CustomComponent{
     private TextField first;
     private TextField second;

     //add to layout, other tasks
 }

//the calling code

FieldGroup fieldgroup = new FieldGroup(new MyBean());
fieldgroup.bindMemberFields(new MasterData());
((AbstractComponent)fg.getField("first")).setImmediate(true);
fg.getField("first").addValueChangeListener(new ValueChangeListener() {

    @Override
    public void valueChange(ValueChangeEvent event) {
        MyBean bean = fg.getItemDataSource().getBean();
        bean.setSecond((String) event.getProperty().getValue());
        try {
            fg.commit();
        } catch (CommitException e) { }
    }

});

The value change event is called but the second field never gets updated on the screen. How canI force the fieldgroup to repaint its field?

War es hilfreich?

Lösung

You might want to take a look at BlurListener.

Also, I think you need to update the value of the TextField "manually". Changing it in the bean might no update the TextField. When you call commit() on the FieldGroup it commits the values in the field to the bean, not the other way around. So in the listener's implementation, it might look something like this:

second.setValue(event.getProperty().getValue());
try {
    fg.commit();
} catch (CommitException e) { }
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top