DateField problem with Locale

Hallo is my first post and if i mistake with the English language … don’t be hard with me … i know is not so good.

I have a problem about the DateField when i open the calendar.
If i set Locale to ENGLISH and i open the calendar all things are ok i see the calendar in english language.
If i click one button i set the Locale to Italian and the field switch correctly to italian format, but if i open the calendar i see english language.

But if i restart application i click the italian button i see the calendar with italian language.

I’m 'doing something wrong or is a bug?


public class TestVaadin extends Application implements ClickListener{


        DateField dtField;
    @Override
    public void init() {
	Window mainWindow = new Window("TestVaadin");
        VerticalLayout vl = new VerticalLayout();
        dtField = new DateField("Date");
        dtField.setLocale(Locale.ENGLISH);
        Button itButton = new Button("It",this);
        vl.addComponent(dtField);
        vl.addComponent(itButton);
	mainWindow.addComponent(vl);
	setMainWindow(mainWindow);
    }

    public void buttonClick(ClickEvent event) {
        dtField.setLocale(Locale.ITALIAN);
    }

Thanks,
Marco

There seems to be indeed a bug in the client-side DateField implementation. Once the date picker popup has been opened, the locale seems to be baked into the popup. It cannot be changed to any locale after that. You can’t even change it back to English if the popup has been opened with the Italian locale. But there is a workaround for this problem. Each time you want to change the locale of the DateField, you could remove the current DateField instance from the layout and add a new one. This solution is a bit awkward, but it works :slight_smile: I have adapted your example with this workaround:


public class TestVaadin extends Application implements ClickListener {

  DateField dtField;
  VerticalLayout vl;
  Button itButton;
  Button enButton;

  @Override
  public void init() {
    Window mainWindow = new Window("TestVaadin");
    vl = new VerticalLayout();
    dtField = new DateField("Date");
    dtField.setLocale(Locale.ENGLISH);
    itButton = new Button("It", this);
    enButton = new Button("En", this);
    vl.addComponent(dtField);
    vl.addComponent(itButton);
    vl.addComponent(enButton);
    mainWindow.addComponent(vl);
    setMainWindow(mainWindow);
  }

  public void buttonClick(ClickEvent event) {
    vl.removeComponent(dtField);
    dtField = new DateField("Date");
    vl.addComponent(dtField, 0);

    if (event.getSource() == itButton) {
      dtField.setLocale(Locale.ITALIAN);
    } else if (event.getSource() == enButton) {
      dtField.setLocale(Locale.ENGLISH);
    }
  }
}

Thank’s, that work for me.
Which i don’t know if i must open a ticket for the bug or if the programmers see this thread.
Marco

Good question, as I don’t know if this can be really classified as a bug. I’m not sure if setting the locale of a component in a user event is supported at all. It could be that setting the locale is only supported during construction of the components. Maybe a Vaadin developer can help us with that. There’s a good chance that one of them will read this thread, they are really active and supportive in this forum :slight_smile:

I’ve tested this Locale issue with the latest nightly build for Vaadin 7. I got the same effect here. Interestingly enough, there is a very old ticked that deals with a similar (or same?) problem:
#3935

Sounds like a bug to me. The other ticket mentions “The popup contents is properly updated but not the field contents.”, which in this case is wrong as the popup contents is not properly updated. Please create a ticket about this.

Ok, I will take care of that.

Edit: Ticket
#9621
created.