UriFragmentUtility does work in Listeners, only?

Hello,

I’ve run into a problem applying the UriFragmentUtility to my application.

Basicly, I’m trying to set the fragment like that:

public class VaadinApplication extends Application {

	public void init() {
		final Window mainWindow = new Window("Vaadin Application");

		final Label label = new Label("Hello Vaadin users");
		mainWindow.addComponent(label);

		final UriFragmentUtility history = new UriFragmentUtility();
		mainWindow.addComponent(history);

		history.setFragment("hello");

		this.setMainWindow(mainWindow);
	}
}

When called in a browser, nothing happens. Of course, the label is rendered, but the URL is not appended with “#hello”.

But if I add a Button and set the fragmet onClick, it works:

public class VaadinApplication extends Application {

	public void init() {
		final Window mainWindow = new Window("Vaadin Application");

		final Label label = new Label("Hello Vaadin users");
		mainWindow.addComponent(label);

		final UriFragmentUtility history = new UriFragmentUtility();
		mainWindow.addComponent(history);

		final Button button = new Button("Click me");
		button.addListener(new ClickListener() {

			@Override
			public void buttonClick(final ClickEvent event) {
				history.setFragment("clicked");
			}
		});

		mainWindow.addComponent(button);

		this.setMainWindow(mainWindow);
	}
}

Where is the difference? As far as I understand, the setFragment is called within a Vaadin Transaction both times, and the UFU is added to the main window.

Any hints?

Thanks in advance!
Kind regards,
Michael

By “added to the main window” it actually means “already in the client browser”
When you call it directly from init, it is not yet in the client browser, only once the function has returned it will work.
The listener is run after the init function has returned so there is no problem here.

Hello Mathias,

thanks for your reply, this making things more clear.

Now I’ve found this
discussion
, and I understand that the UFU will be removed or at least reworked in Vaadin 7. I’m looking forward :slight_smile:

Regards, Michael.

A small addition for the ensuing ages:

If I call

window.addComponent(new UriFragmentUtility()) , exactly nothing happens. I won’t get any FragmentChangedEvent ever.

Then I’ve found
this
ticket. My Window uses a CustomLayout with a HTML template. I had to create an extra DIV inside my template and add the UFU to that location. Now it works as expected…

It’s nice, isn’t it?

grumble