Accordion tab caption is not refreshing on ValueChangeEvent

Hello,

I have an accordion with some tabs, and I want to change the caption of the open tab on selecting an option from the optiongroup inside the tab.

Here some code ilustrate that:


public class MyApplication extends Application {
	@Override
	public void init() {
		setMainWindow(new Window("Acc-Test"));
		getMainWindow().setContent(new VerticalLayout() {

			@Override
			public void attach() {
				super.attach();

				List<String> cities = Arrays.asList(new String[] {"Berlin", "Brussels"});
				OptionGroup optionGroup = new OptionGroup("Select", cities);
				Button changeCaptionButton = new Button("changeCaption2");

				Accordion acc = new Accordion();
				addComponent(acc);
				final Tab tab1 = acc.addTab(optionGroup, "OptionGroup Tab - 1");
				final Tab tab2 = acc.addTab(changeCaptionButton, "Button Tab - 2");

				optionGroup.addListener(new ValueChangeListener() {
					@Override
					public void valueChange(ValueChangeEvent event) {
						tab1.setCaption("new Caption Tab1");			
					}
				});
			
				changeCaptionButton.addListener(new ClickListener() {
					@Override
					public void buttonClick(ClickEvent event) {
						tab2.setCaption("new Caption Tab2");
					}
				});

			}

		});
	}
}

When I click on an option the ValueChangeListener-Code is executed, but the caption of the tab is not refreshed. But on changing the tab, the new caption is shown.
BTW: Then same code in the Button.ClickListener works as expacted!

Is there anything wrong in my code, or may there be better ways to do things like this?

Thanks for Help! :slight_smile:

Hi,

the OptionGroup does not send the changes to the server immediately (like the Button does). Try adding the following to your code, after you create the optionGroup:

optionGroup.setImmediate(true);

-Tepi

Hi Tepi,

yes, that’s it!!!
Thanks a lot for your verry fast replay!

Andreas