Combobox ValueChangeListener and TextArea

Hi,

I’m facing the following problem:

  • i have a comboxbox with a value change listener. When some option is selected the listener is invoked;

  • in this listener i set the value of some text area

  • after this, i modify the text in the text area and submit

  • after submit i commit the form and the listener of combobox is invoked again (the selected option in combobox was not modified) and replaced the modified text

How can i avoid this?


            final ComboBox comboBox = new ComboBox(createCaptionByPropertyId(fieldName));

	    comboBox.setWidth("50%");
	    comboBox.setImmediate(true);
	    comboBox.setContainerDataSource(new MyElementsContainer(parent, "fullName"));
	    comboBox.setItemCaptionPropertyId("fullName");
	    comboBox.setFilteringMode(ComboBox.FILTERINGMODE_CONTAINS);
	    comboBox.setNullSelectionAllowed(false);
	    comboBox.addListener(new MyListener());

And the listener code is:


  static private class MyListener implements Property.ValueChangeListener {

	static private final long serialVersionUID = 1L;

	private MyForm form;
	private String fieldName;

	public SelectFragmentoValueChangeListenter(final MyForm form, final String fieldName) {
	    this.form = form;
	    this.fieldName = fieldName;
	}

	@Override
	public void valueChange(com.vaadin.data.Property.ValueChangeEvent event) {

	    if (event.getProperty() == null) {
		return;
	    }

	    final Long selectedItem = Long.valueOf(event.getProperty().toString());
	    final Xpto element = Xpto.INFO.get(selectedItem);

            // modify value with element text
	    form.getField(fieldName).setValue(element.getTexto());

	}
    }

After commit in the form, the listener is invoked and replacing all modifications …

Any ideias, how to avoid this?

Thanks,
Joao.

Does the text area component have a listener registered?
Just a thought: could the same valueChange method be being called when the text area is updated?

No, the text area does not have any listener …

Sorry, I think I’m missing something here…


inside the valueChange listener:

Is that calling setValue on the ComboBox???
Is the intent to call the setValue on the text area???

If the listener is to change the value of the comboBox, then: turn off the listener, set the value, then turn the listener back on.

No, fieldName is different for combobox and text area. In the code i presented its not possible to check this …

I solve the problem with the solution presented in following post:

http://vaadin.com/forum/-/message_boards/message/91825

I created my own combobox and prevented calling fireEvent if commit value …

Thks.