I would like to be able to link to individual tabs in a PrimeFaces’ “tabView”. In other words, if my page “test.jsf” has a tabView with a tab entitled “Example”, I want to be able to click a link to “Test.jsf#Example” and have the “Example” tab loaded automatically. How can I do this?
Share
This can be done with a wee bit of JavaScript (using jQuery). I hope I have commented the following code well-enough that it can be understood.
All you have to do is insert that JavaScript in the page that has the tabs. Then you can get a link to a tab with the usual
<a href='test.jsf#Example>Click here!</a>. An added bonus is that the tab you were on becomes part of the browser history; i.e., if you navigate away from the page that has the tabs, then press the “back” button, you are brought back to the tab you were on.Note: if the tabView changes (e.g. you add or remove tabs), you will need to call setupTabFragmentLinks again.