• Menu
  • Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

JavaBeat

Java Tutorial Blog

  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us

How to set selected tab in rich:tabPanel tag?

April 12, 2008 //  by Krishna Srinivasan

  • Topic : Java Server Faces (JSF), RichFaces, Ajax4Jsf
  • Environment : J2EE 5.0, MyFaces 1.1.5, RichFaces 3.1.0

rich:tabPanel

also read:

  • Introduction to JSF
  • JSF Interview Questions
  • Request Processing Lifecycle phases in JSF

This example illustrates how to set the selected tab in rich:tabPanel. This tag is used for creating the multiple tabs
with in same page and allowing user to populate the each tab with different data. RichFaces provides three types of mechanism to fetch the data from server. They are: client,server and ajax. These values are used in the attribute called switchType. Our example uses switchType as client.

switchType=”client”

If the switchType is “client”, then all the data will be reterived from the server and stored in the client. When you select different tabs, javascript is used for dsiplaying the data. This is the fastest solution compare to other approaches.

switchType=”server”

If the switchType is “server”, then the data will be reterived from the server for every request. The page will be refreeshed for
the each request.

switchType=”ajax”

If the switchType is “ajax”, then the data will be reterived from the server for ever request. The page will not be refreeshed for the
each request because we are using ajax call to the server.

selectedTab attribute

selectedTab attribute is used for setting the default selected tab in the rich:tabPanel. If you are not providing the
correct tab name to this attribute, it will throw java.lang.IllegalStateException: No active tabs!.

specifies the default tab as “Tabname1”. The “TabName1” is
the name of the tabs used in rich:tab.

selectedTab.jsp


<!--
   Source : www.javabeat.net
-->




<html>
    <body>
          <f:view>
              <h:form id="select">
                  <rich:tabPanel selectedTab="TabName1" switchType="client">
                      <rich:tab name="TabName1" label="Java">
                          <!-- Tab content here -->
                          <h:outputText value="Sample Text 1"/>
                      </rich:tab>
                      <rich:tab name="TabName2" label="J2EE">
                          <!-- Tab content here -->
                          <h:outputText value="Sample Text 2"/>
                      </rich:tab>
                      <rich:tab name="TabName3" label="Java Server Faces">
                          <!-- Tab content here -->
                          <h:outputText value="Sample Text 3"/>
                      </rich:tab>
                  </rich:tabPanel>
              </h:form>
          </f:view>
    </body>
</html>

Category: JavaTag: Richfaces

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Previous Post: « Customizing Dragging and Dropping for Swing Components
Next Post: How to use Resource Bundle in JSF? »

Primary Sidebar

Follow Us

  • Facebook
  • Pinterest

FEATURED TUTORIALS

How to Initialize an Array in Java

Introduction to Java Server Faces (JSF)

Introduction to Java 6.0 New Features, Part–1

Java 6.0 Features Part – 2 : Pluggable Annotation Processing API

Introduction to Java Server Faces(JSF) HTML Tags

JavaBeat

Copyright © by JavaBeat · All rights reserved
Privacy Policy | Contact