I want to create JSF page with tabs. Something like this. But I wonder if I choose to do this with Jquery can I implement lazy loading – when I click a tab on the JSF page the content is generated when the tab is opened. Is it possible to implement lazy loading of tabs in pure JSF? And I suppose that I can easily implement AJAX in both cases.
Best wishes
Note: If you want your tabs beans be Session Scope then read instructions in the buttom of the Answer…
Since you are don’t want to use any third party Libarary here is a PureJSF + jQuery example
JSF + Jquery + Ajax Lazy Loading + View Scope Beans Example…
B.T.W here is how it looks like eventually :
You can look at the web server console for the print outs of
@PostConstructand the@PreDestroywhen you click on each tab…The content of the tab – the xhtml page and its bean will be loaded upon tab click (Lazy Loading) and will be destroyed upon click on other tab,
I suggest you to create a new project and slowly place all the files inside it and start playing and looking into it… its 100% working , but I placed some print outs just to see that it is really working…
The Example is very simple and straight forward….
First Of all go to jQueryUI and download it(1.8.18)
and place
jquery-1.7.1_.min.jsandjquery-ui-1.8.18.custom.min.jsinWebContent\resources\jsandjquery-ui-1.8.18.custom.cssinWebContent\resources\cssNow to the other files…
myTabs.xhtml
MyTabs.java
MyTabObject
Tab1Page , (Tab2Page and Tab3Page are exactly the same , just change the number in all places)
tab1.xhtml (tab2.xhtml and tab3.xhtml are exactly the same – just replace the numbers)
and to the last file
mytabs.js (place it in WebContent\resources\js)
In order to use Session Scope Beans:
The method
switchPagesinMyTabs.javashould bevoidand not to return anything, like this