I saw a reference (http://mkblog.exadel.com/?p=115) to my blog on one of the Brazilian JSF forums. I translated the thread using Google and it looked like someone was asking how to create RichFaces tabs dynamically. So, here is quick example.
XHTML page:
RichFaces
Managed bean:
package tabs;
import javax.faces.application.Application;
import javax.faces.component.html.HtmlPanelGrid;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import org.richfaces.component.html.HtmlTab;
import org.richfaces.component.html.HtmlTabPanel;
public class TabsBean {
private HtmlPanelGrid panelGrid;
private Integer numOfTabs;
public Integer getNumOfTabs() {
return numOfTabs;
}
public void setNumOfTabs(Integer numOfTabs) {
this.numOfTabs = numOfTabs;
}
public TabsBean() {
}
public HtmlPanelGrid getPanelGrid() {
return panelGrid;
}
public void setPanelGrid(HtmlPanelGrid panelGrid) {
this.panelGrid = panelGrid;
}
public void createTabs (ActionEvent event){
FacesContext context = FacesContext.getCurrentInstance();
Application application = context.getApplication();
HtmlTabPanel tabPanel = (HtmlTabPanel)application.createComponent(HtmlTabPanel.COMPONENT_TYPE);
tabPanel.setSwitchType("ajax");
for (int i=0; i<numOfTabs; i++){
HtmlTab tab = (HtmlTab)application.createComponent(HtmlTab.COMPONENT_TYPE);
tab.setLabel("Nice Tab # "+(i+1));
tab.setName(i);
tabPanel.getChildren().add(tab);
}
panelGrid.getChildren().clear();
panelGrid.getChildren().add(tabPanel);
}
}
You will get this:


Leave a comment