When a ValueChangeEvent is fired in a PopupDateField?

Hello, I’m using Vaadin 6.8.8 and I have an issue with PopupDateField.

I have two PopupDateField objects in a form and I want to update the value of the second PopupDateField when the user changes the first PopupDateField value. I mean, when the user selects a date in the first PopupDateField then the second PopupDateField automatically changes the date to first PopupDateField value + 3 days.

This is how I create the PopupDateField:

dateIn = createPopupDateField(msg.getMessage("avail.form.dateIn.title"), new GregorianCalendar());
dateOut = createPopupDateField(msg.getMessage("avail.form.dateOut.title"), new GregorianCalendar());
private PopupDateField createPopupDateField(String title, Calendar date) {
	PopupDateField popup = new PopupDateField();

	popup.setCaption(title);
	popup.setDateFormat("dd/MM/yyyy");
	popup.setValue(date.getTime());
	popup.setResolution(PopupDateField.RESOLUTION_DAY);
	popup.setSizeFull();

	return popup;
}

I try to add to dateIn (first PopupDateField) the ValueChangeListner and update the value of dateOut (second PopupDateField). It works but it isn’t automatic, I mean, it works when I click another button, another combo box, etc. It seems that the listener is waiting to another action.

dateIn.addListener(new ValueChangeListener() {
	private static final long serialVersionUID = 1L;

	@Override
	public void valueChange(ValueChangeEvent event) {
		Calendar date = new GregorianCalendar();
		date.setTime((Date) event.getProperty().getValue());
		date.add(Calendar.DATE, +3);
			
		dateOut.setValue(date.getTime());
	}
});

All what I can get is this workarround:

dateIn.addListener(new Listener() {
	private static final long serialVersionUID = 1L;

	@Override
	public void componentEvent(Event event) {
		if(event instanceof ValueChangeEvent) {
			Calendar date = new GregorianCalendar();
			date.setTime((Date) ((ValueChangeEvent) event).getProperty().getValue());
			date.add(Calendar.DATE, +3);

			dateOut.setValue(date.getTime());
		}
	}
});

But It only updates second date when first PopupDateField looses the focus.

Is it possible to change automatically a PopupDateField value when a date from another PopupDateField is selected?

Hi,

The only thing you need to do is set the dateIn to immediate, so it send the value change asap to the server, and does not get buffered on the client to wait some other immediate event (like a button click).

So in
createPopupDateField
method just use
popup.setImmeadiate(true);
and that should work.

Thank you so much!

It works perfectly.