In this simple application uri events are generated infinitely after once triggered by pressing the button - why ?
No explicit URI changes are posted (apart from the initial push).
It is a simplified extract from a larger application where I have problem with phantom uri events after replacing components.
The URIFragmentUtility is at the same level as replaced components. Can it be the reason ?
package com.example.urierror;
import java.util.Date;
import com.vaadin.Application;
import com.vaadin.ui.Button;
import com.vaadin.ui.UriFragmentUtility;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.UriFragmentUtility.FragmentChangedEvent;
import com.vaadin.ui.UriFragmentUtility.FragmentChangedListener;
public class UrierrorApplication extends Application
{
@Override
public void init()
{
AppWindow mainWindow = new AppWindow();
setMainWindow(mainWindow);
}
}
class AppWindow extends Window implements FragmentChangedListener
{
VerticalLayout layout1 = new VerticalLayout();
VerticalLayout layout2 = new VerticalLayout();
VerticalLayout layoutCurrent = null;
Button button;
UriFragmentUtility uriFragmentUtility;
Integer i = 0;
public AppWindow()
{
super();
uriFragmentUtility = new UriFragmentUtility();
uriFragmentUtility.addListener(this);
layout1.setCaption("1");
layout2.setCaption("2");
addComponent(layout1);
layoutCurrent = layout1;
addComponent(button = new Button("0 uri events", new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
uriFragmentUtility.setFragment("F" + (new Date()).getTime());
}
}));
addComponent(uriFragmentUtility);
}
@Override
public void fragmentChanged(FragmentChangedEvent source)
{
button.setCaption(++i + " uri events");
VerticalLayout layoutNew = (layoutCurrent == layout1 ? layout2 : layout1);
replaceComponent(layoutCurrent, layoutNew);
layoutCurrent = layoutNew;
}
}