Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7801939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:06:16+00:00 2026-06-02T01:06:16+00:00

I want to create JSF page with tabs. Something like this . But I

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T01:06:18+00:00Added an answer on June 2, 2026 at 1:06 am

    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 :

    JSF + Jquery Lazy Loading Tabs

    You can look at the web server console for the print outs of @PostConstruct and the @PreDestroy when 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.js and jquery-ui-1.8.18.custom.min.js in WebContent\resources\js and jquery-ui-1.8.18.custom.css in WebContent\resources\css

    Now to the other files…

    myTabs.xhtml

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:c="http://java.sun.com/jsp/jstl/core">
    <h:head>
     <h:outputScript library="js" name="jquery-1.7.1_.min.js" target="head" />
     <h:outputScript library="js" name="jquery-ui-1.8.18.custom.min.js" target="head" />
     <h:outputStylesheet library="css" name="jquery-ui-1.8.18.custom.css" target="head"     />
     <h:outputScript library="js" name="mytabs.js" target="head" />
    </h:head>
    <h:body>
    
    <f:view>
        <h:form prependId="false">
            <h:panelGroup id="tabs" layout="block">
                <ul>
                    <c:forEach items="#{myTabs.tabs}" var="tab">
                        <li><a href="##{tab.tabid}" onclick="$('#button_#{tab.tabid}').click()">#{tab.tabid}</a></li>
                        <h:commandButton id="button_#{tab.tabid}" value="TabClick" action="#{myTabs.switchPages(tab.tabid)}" style="display:none">
                            <f:ajax render="tabs"></f:ajax>
                        </h:commandButton>  
                    </c:forEach>
                </ul>
    
                <c:forEach items="#{myTabs.tabs}" var="tab">
                    <h:panelGroup id="#{tab.tabid}" layout="block" rendered="#{tab.tabid eq myTabs.selectedTab}">
                        <ui:include src="#{tab.tabfilename}"></ui:include>
                    </h:panelGroup>
                </c:forEach>
            </h:panelGroup>
        </h:form>
    </f:view>
    </h:body>
    </html>
    

    MyTabs.java

    package pack;
    
    import java.util.ArrayList;
    import java.util.List;
    
    import javax.annotation.PostConstruct;
    import javax.faces.bean.ManagedBean;
    import javax.faces.bean.SessionScoped;
    
    @ManagedBean
    @SessionScoped
    public class MyTabs{
    
    @PostConstruct
    public void init(){
        tabs = new ArrayList<MyTabObject>();
        tabs.add(new MyTabObject("tab1.xhtml", "tab1"));
        tabs.add(new MyTabObject("tab2.xhtml", "tab2"));
        tabs.add(new MyTabObject("tab3.xhtml", "tab3"));
    
    }
    String selectedTab="tab1";
    
    public String getSelectedTab() {
        return selectedTab;
    }
    
    public void setSelectedTab(String selectedTab) {
        this.selectedTab = selectedTab;
    }
    
    public String switchPages(String selTab) {
        selectedTab = selTab;
        return "myTabs.xhtml";
    }
    
    
    List<MyTabObject> tabs;
    
    
    public List<MyTabObject> getTabs() {
        return tabs;
    }
    
    public void setTabs(List<MyTabObject> tabs) {
        this.tabs = tabs;
    }
    
    
    }
    

    MyTabObject

    package pack;
    
    
    
    public class MyTabObject{
    
    
    String tabfilename;
    String tabid;
    public String getTabfilename() {
        return tabfilename;
    }
    public void setTabfilename(String tabfilename) {
        this.tabfilename = tabfilename;
    }
    public String getTabid() {
        return tabid;
    }
    public void setTabid(String tabid) {
        this.tabid = tabid;
    }
    public MyTabObject(String tabfilename, String tabid) {
        super();
        this.tabfilename = tabfilename;
        this.tabid = tabid;
    }
    
    }
    

    Tab1Page , (Tab2Page and Tab3Page are exactly the same , just change the number in all places)

    package pack;
    
    import java.io.Serializable;
    import java.text.Format;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    import javax.annotation.PostConstruct;
    import javax.annotation.PreDestroy;
    import javax.faces.bean.ManagedBean;
    import javax.faces.bean.ViewScoped;
    
    @ManagedBean
    @ViewScoped
    public class Tab1Page implements Serializable{
    
    /**
     * 
     */
    private static final long serialVersionUID = 254415216070877770L;
    // Constants
    public final static String hashKey = "tab1PageTab";
    public String actionString = "";
    
    @PostConstruct
    public void post(){
      Format formatter;
      Date date = new Date();
    
      // Time formate 01:12:53 AM
      formatter = new SimpleDateFormat("hh:mm:ss a");
      tabName = formatter.format(date);
        System.out.println("Tab1Page\t"+tabName+"\t@PostConstruct...");
    }
    
    @PreDestroy
    public void destroy(){
      Format formatter;
      Date date = new Date();
    
      // Time formate 01:12:53 AM
      formatter = new SimpleDateFormat("hh:mm:ss a");
      tabName = formatter.format(date);
        System.out.println("Tab1Page\t"+tabName+"\t@PreDestroy...");
    }
    
    
    String tabName;
    
    public String getTabName() {
        return this.getClass().getName().substring(this.getClass().getName().lastIndexOf("."))+"\t"+tabName;
    }
    public void setTabName(String tabName) {
        this.tabName = tabName;
    }
    
    public String getActionString() {
        return actionString;
    }
    
    public void setActionString(String actionString) {
        this.actionString = actionString;
    }
    
    }
    

    tab1.xhtml (tab2.xhtml and tab3.xhtml are exactly the same – just replace the numbers)

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <ui:composition xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:c="http://java.sun.com/jsp/jstl/core">
    
    <h:panelGroup>
        <h:form>
            <h:outputText value="#{tab1Page.tabName}" />
        </h:form>
    </h:panelGroup>
    </ui:composition>
    

    and to the last file

    mytabs.js (place it in WebContent\resources\js)

    $(document).ready(function () { 
        $("#tabs").tabs();
    });
    
    $(window).load(function() {
        jsf.ajax.addOnEvent(function (data) {
            if (data.status === "success") {
                    $("#tabs").tabs();
            }
        });
    });
    

    In order to use Session Scope Beans:

    The method switchPages in MyTabs.java should be void and not to return anything, like this

        public void switchPages(String selTab) {
        selectedTab = selTab;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a JSF table like this . But instead delete button
I want to implement Prime Faces example I created this JSF page: <?xml version='1.0'
I want to create this JSF table with paging and sorting. This is JSF
I want to create JSF page which displays Oracle connections. The web page will
I want to create JSF page which displays Glassfish connections. The web page will
I want to create user authentication (login) and security page in jsf, that manages
I want to create JSF table which has select all button and check box
In my JSF web-app, I want to create a URL for the user to
I want to dynamically create object of HtmlDivElement in my jsf managed bean and
I want to dynamically create controls in my bean. I am using JSF 2.0

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.