Skip to main content

JSF2 ajax navigation

2 replies [Last post]
istls
Offline
Joined: 2010-09-01
Points: 0

I'm attempting to create a menu component in jsf that uses ajax to navigate between pages. The menu contains client side state in javascript (eg. expanded sections and folders).

The following code is what I'm working with right now. The problem I have is that clicking on a link to navigate between pages refreshes the whole page which resets the state of the menu. I would like the state of the menu to be kept the same. Is there some way to do this in jsf?

layout.xhtml:

</p>
<p>        $(function() {<br />
            $(window).delegate('li.folder a', 'click',<br />
            function(){<br />
                var $ul = $(this).siblings('ul');<br />
                if ($ul.is(':visible')) {<br />
                    $ul.hide();<br />
                } else {<br />
                    $ul.show();<br />
                }<br />
            });<br />
        });</p>
<ul>
<li></li>
<li class="folder">
                        Folder (click to expand)</p>
<ul>
<li></li>
<li></li>
</ul>
</li>
</ul>
<p>

page1.xhtml:

</p>
<p>        page1</p>
<p>

page2.xhtml:

</p>
<p>        page2</p>
<p>

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
dwuysan
Offline
Joined: 2009-08-27
Points: 0

Perhaps you can achieve this by creating a request scoped bean, say call it 'breadcrumbsBean' and then for each of your commandLink, add f:setPropertyActionListener.

so for example:

also add

, as well as some onload javascript to manage the hide and show based on the value of document.getElementById("menu:hiddenMnuCurrentPage").

Let me know your thoughts on this.

Message was edited by: dwuysan

Message was edited by: dwuysan

istls
Offline
Joined: 2010-09-01
Points: 0

Thanks for the reply, dwuysan. I was hoping to not store any state on the server, but after spending some time looking at the mojarra code I have realised that it will not work the way I was hoping...

I will need to provide state on the server.