Some URIFragmentUtility troubles

Hi Guys,
I’m trying to use the URIFragmentUtility but it doesn’t work somehow in my case. Let me explain the situation:

  • the main Window contains custom layout. In the template I have a menu hard coded with for example #about, #home links. I’d like to change the content of the page by clicking on the links. But I click on the link the FragmentChangedListener doesn’t work. :frowning:

  • I think the problem is the use of the CustomLayout and URIFragmentUtility together.

   
    @Override
    public void init() {
        buildMainLayout();
        setMainWindow(mainWindow);
    }

    private void buildMainLayout() {
        setTheme("theme");
        CustomLayout custom = new CustomLayout("mainLayout");
        custom.addStyleName("customLayout");
        mainWindow.setContent(custom);

        final ProblemsTable table = new ProblemsTable(this);

        custom.addComponent(table, "pagecontent");
        Link link = new Link("link to a resource", new ExternalResource(
                "/MathAlg/test/"));
        link.setStyleName("menuButton");
        custom.addComponent(link, "homeButton");

        UriFragmentUtility urifu = new UriFragmentUtility();
        custom.addComponent(urifu);
        urifu.addListener(new FragmentChangedListener() {

            private static final long serialVersionUID = 1L;

            public void fragmentChanged(FragmentChangedEvent source) {
                String fragment =
                          source.getUriFragmentUtility().getFragment();
//                if (fragment != null){
//                    custom.addComponent(table, "pagecontent");                    
//                }else if(fragment.equals("about")){
//                    System.out.println("TUkss");
//                    Label test = new Label("tuka ima, tuka nema !!");
//                    custom.removeComponent(custom);
//                    custom.addComponent(test,"pagecontent");
//                }
                System.out.println("fragment changed ?!"+fragment);
            }
        });
        
     
    }

I’ve found solution to my problem. To use the UriFragmentUtility with CustomLayout I made the following:



private CustomLayout custom = new CustomLayout("mainLayout");
custom.addComponent(urifu, "urifu");

 urifu.addListener(new FragmentChangedListener() {
            /**
             * 
             */
            private static final long serialVersionUID = 6392103138173536750L;

            public void fragmentChanged(FragmentChangedEvent source) {
                ....
            }
        });

In the template:

<li><div id="button" location="urifu"></div></li> 

Yes, the URIFU component needs to be somewhere in the layout of the window - either the CustomLayout or its parent layout.

Usually, the element with the location tag can be a (possibly hidden) or

- might be a little simpler than a button.

Yes, u are right about that.

<div id="button" location="urifu"></div>

would be enought somewhere in the template code.