About This Tag
The TabSet renders a set of Tab children. It keeps track of the currently
selected child Tab as well as applying any specified ActionListener.
Configuring the TabSet Tag
The TabSet can currently be used in one of two ways: via a component binding to a
TabSet and group of child Tab components (defined in a backing bean); or by specifying the
TabSet and child Tabs directly in your JSP. Examples of both are shown in the Examples
section below. It is anticipated that the component binding method will be more
common as this allows a single set of Tabs to be easily shared among many pages. In
either case, the initial selection for the TabSet component can be specified using the
"selected" property. Note that if an ActionListener is applied to the TabSet
component, it adds the specified ActionListener to each of its child Tab components action
listener lists.
Facets
None at this time
Client Side Javascript Functions
None at this time
Examples
Example 1: Define the TabSet via a component binding
One way a TabSet component can be specified is via a JSF component binding to an instance
defined in a backing bean. The contents of the JSP in this case will simply be something
like:
<ui:tabSet binding="#{TabSetBean.sportsTabSet}" />
The code in the corresponding backing bean instance would look something like:
import java.util.List;
import java.lang.Class;
import javax.faces.FactoryFinder;
import javax.faces.el.MethodBinding;
import javax.faces.event.ActionEvent;
import javax.faces.application.Application;
import javax.faces.application.ApplicationFactory;
import com.sun.rave.web.ui.component.Tab;
import com.sun.rave.web.ui.component.TabSet;
public class TabSetBean {
private TabSet sportsTabSet = null;
// Creates a new instance of TabSetBean //
public TabSetBean() {
sportsTabSet = new TabSet();
List kids = sportsTabSet.getChildren();
Tab level1Tab = new Tab("Baseball");
level1Tab.setId("Baseball");
Tab level2Tab = addTab(level1Tab,
"National");
addTab(level2Tab, "Mets");
addTab(level2Tab, "Pirates");
addTab(level2Tab, "Cubs");
level2Tab = addTab(level1Tab,
"American");
addTab(level2Tab, "Yankees");
addTab(level2Tab, "Tigers");
addTab(level2Tab, "Mariners");
level2Tab = addTab(level1Tab, "AAA");
addTab(level2Tab, "Spinners");
addTab(level2Tab, "Renegades");
addTab(level2Tab, "Clippers");
kids.add(level1Tab);
level1Tab = new Tab("Football");
level1Tab.setId("Football");
level2Tab = addTab(level1Tab, "NFC");
addTab(level2Tab, "Giants");
addTab(level2Tab, "Bears");
addTab(level2Tab, "Falcons");
level2Tab = addTab(level1Tab, "AFC");
addTab(level2Tab, "Jets");
addTab(level2Tab, "Patriots");
addTab(level2Tab, "Colts");
level2Tab = addTab(level1Tab,
"College");
addTab(level2Tab, "Wolverines");
addTab(level2Tab, "Hurricanes");
addTab(level2Tab, "Buckeyes");
kids.add(level1Tab);
Class[] args = new Class[] { ActionEvent.class
};
MethodBinding binding =
createBinding("#{TabSetBean.tabClicked}", args);
sportsTabSet.setActionListener(binding);
sportsTabSet.setSelected("Jets");
}
private MethodBinding createBinding(String expr, Class[] args) {
ApplicationFactory factory =
(ApplicationFactory)
FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
Application app = factory.getApplication();
return app.createMethodBinding(expr, args);
}
private Tab addTab(Tab parent, String newTabLabel) {
Tab tab = new Tab(newTabLabel);
tab.setId(newTabLabel);
parent.getChildren().add(tab);
return tab;
}
public void tabClicked(ActionEvent event) {
String clickedTabId = event.getComponent().getId():
String selectedTabId = sportsTabSet.getSelected();
// ... do sometehing based upon the clicked or
selected tab id ...
}
public TabSet getSportsTabSet() {
return sportsTabSet;
}
public void setSportsTabSet(TabSet tabs) {
sportsTabSet = tabs;
}
}
Example 2: Define the TabSet in your JSP
A tabSet can also be defined directly in your JSP. The following example defines a set of tabs with
three level one tabs (labelled "One", "Two" and "Three"). Each
level one tab also has two level two tab childeren (labelled "XxxA" and
"XxxB" where X is the top level tab number. The initially selected Tab for this
TabSet will be "TwoA".
<ui:tabSet selected="TwoA">
<ui:tab id="One" text="One">
<ui:tab id="OneA" text="One
A" />
<ui:tab id="OneB" text="One
B" />
</ui:tab>
<ui:tab id="Two" text="Two">
<ui:tab id="TwoA" text="Two
A" />
<ui:tab id="TwoB" text="Two
B" />
</ui:tab>
<ui:tab id="Three" text="Three">
<ui:tab id="ThreeA"
text="Three A" />
<ui:tab id="ThreeB"
text="Three B" />
</ui:tab>
</ui:tabSet>
Auto-generated component class.
Do NOT modify; all changes
will be lost!
|