Author: jjamrich
Date: 2011-05-16 10:43:51 -0400 (Mon, 16 May 2011)
New Revision: 22494
Added:
modules/tests/metamer/trunk/application/src/main/webapp/components/richTabPanel/addTab.xhtml
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/rich/RichTabPanelBean.java
Log:
Add example of dynamic tab creation into Metamer
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/rich/RichTabPanelBean.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/rich/RichTabPanelBean.java 2011-05-16
13:22:43 UTC (rev 22493)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/rich/RichTabPanelBean.java 2011-05-16
14:43:51 UTC (rev 22494)
@@ -21,16 +21,20 @@
*******************************************************************************/
package org.richfaces.tests.metamer.bean.rich;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.annotation.PostConstruct;
+import javax.faces.bean.ManagedBean;
+import javax.faces.bean.ViewScoped;
+
+import org.richfaces.component.UITab;
import org.richfaces.component.UITabPanel;
import org.richfaces.tests.metamer.Attributes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.annotation.PostConstruct;
-import javax.faces.bean.ManagedBean;
-import javax.faces.bean.ViewScoped;
-import java.io.Serializable;
-
/**
* Managed bean for rich:tabPanel.
*
@@ -44,6 +48,8 @@
private static final long serialVersionUID = -1L;
private static Logger logger;
private Attributes attributes;
+
+ private List<UITab> tabs = new ArrayList<UITab>();
/**
* Initializes the managed bean.
@@ -66,6 +72,19 @@
attributes.setAttribute("bypassUpdates", null);
attributes.get("bypassUpdates").setType(Boolean.class);
}
+
+ public void createNewTab() {
+
+ UITab tab = new UITab();
+ int index = tabs.size() + 6; // there is already 5 tabs
+
+ tab.setHeader("tab" + index + " header");
+ tab.setId("tab" + index);
+ tab.setName("tab" + index);
+ tab.setRender("tab" + index);
+
+ tabs.add(tab);
+ }
public Attributes getAttributes() {
return attributes;
@@ -74,4 +93,12 @@
public void setAttributes(Attributes attributes) {
this.attributes = attributes;
}
+
+ public List<UITab> getTabs() {
+ return tabs;
+ }
+
+ public void setTabs(List<UITab> tabs) {
+ this.tabs = tabs;
+ }
}
Added:
modules/tests/metamer/trunk/application/src/main/webapp/components/richTabPanel/addTab.xhtml
===================================================================
---
modules/tests/metamer/trunk/application/src/main/webapp/components/richTabPanel/addTab.xhtml
(rev 0)
+++
modules/tests/metamer/trunk/application/src/main/webapp/components/richTabPanel/addTab.xhtml 2011-05-16
14:43:51 UTC (rev 22494)
@@ -0,0 +1,144 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!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:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:metamer="http://java.sun.com/jsf/composite/metamer"
+
xmlns:rich="http://richfaces.org/rich"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:c="http://java.sun.com/jsp/jstl/core" >
+
+ <!--
+JBoss, Home of Professional Open Source
+Copyright 2010-2011, Red Hat, Inc. and individual contributors
+by the @authors tag. See the copyright.txt in the distribution for a
+full listing of individual contributors.
+
+This is free software; you can redistribute it and/or modify it
+under the terms of the GNU Lesser General Public License as
+published by the Free Software Foundation; either version 2.1 of
+the License, or (at your option) any later version.
+
+This software is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this software; if not, write to the Free
+Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ -->
+
+ <ui:composition template="/templates/template.xhtml">
+
+ <ui:define name="view">
+ <f:metadata>
+ <f:viewParam name="templates"
value="#{templateBean.templates}">
+ <f:converter converterId="templatesListConverter" />
+ </f:viewParam>
+ </f:metadata>
+ </ui:define>
+
+ <ui:define name="component">
+
+ <rich:tabPanel id="tabPanel"
+
activeItem="#{richTabPanelBean.attributes['activeItem'].value}"
+
cycledSwitching="#{richTabPanelBean.attributes['cycledSwitching'].value}"
+
dir="#{richTabPanelBean.attributes['dir'].value}"
+
headerAlignment="#{richTabPanelBean.attributes['headerAlignment'].value}"
+
headerPosition="#{richTabPanelBean.attributes['headerPosition'].value}"
+
immediate="#{richTabPanelBean.attributes['immediate'].value}"
+ itemChangeListener="#{richBean.itemChangeListener}"
+
lang="#{richTabPanelBean.attributes['lang'].value}"
+
onbeforeitemchange="#{richTabPanelBean.attributes['onbeforeitemchange'].value}"
+
onclick="#{richTabPanelBean.attributes['onclick'].value}"
+
ondblclick="#{richTabPanelBean.attributes['ondblclick'].value}"
+
onitemchange="#{richTabPanelBean.attributes['onitemchange'].value}"
+
onmousedown="#{richTabPanelBean.attributes['onmousedown'].value}"
+
onmousemove="#{richTabPanelBean.attributes['onmousemove'].value}"
+
onmouseout="#{richTabPanelBean.attributes['onmouseout'].value}"
+
onmouseover="#{richTabPanelBean.attributes['onmouseover'].value}"
+
onmouseup="#{richTabPanelBean.attributes['onmouseup'].value}"
+
rendered="#{richTabPanelBean.attributes['rendered'].value}"
+
style="#{richTabPanelBean.attributes['style'].value}"
+
styleClass="#{richTabPanelBean.attributes['styleClass'].value}"
+
switchType="#{richTabPanelBean.attributes['switchType'].value}"
+
tabActiveHeaderClass="#{richTabPanelBean.attributes['tabActiveHeaderClass'].value}"
+
tabContentClass="#{richTabPanelBean.attributes['tabContentClass'].value}"
+
tabDisabledHeaderClass="#{richTabPanelBean.attributes['tabDisabledHeaderClass'].value}"
+
tabHeaderClass="#{richTabPanelBean.attributes['tabHeaderClass'].value}"
+
tabInactiveHeaderClass="#{richTabPanelBean.attributes['tabInactiveHeaderClass'].value}"
+
title="#{richTabPanelBean.attributes['title'].value}"
+ >
+
+ <rich:tab id="tab1" name="tab1" header="tab1
header">
+ content of tab 1
+ </rich:tab>
+ <rich:tab id="tab2" name="tab2" header="tab2
header">
+ content of tab 2
+ </rich:tab>
+ <rich:tab id="tab3" name="tab3" header="tab3
header">
+ content of tab 3
+ </rich:tab>
+ <rich:tab id="tab4" name="tab4" header="tab4
header" disabled="true">
+ content of tab 4
+ </rich:tab>
+ <rich:tab id="tab5" name="tab5" header="tab5
header">
+ content of tab 5
+ </rich:tab>
+
+ <c:forEach items="#{richTabPanelBean.tabs}"
var="newTab">
+ <rich:tab binding="#{newTab}" >
+ content of tab
+ </rich:tab>
+ </c:forEach>
+
+ </rich:tabPanel>
+
+ <br/><br/>
+ <fieldset>
+ <legend>JavaScript API</legend>
+
+ <script type="text/javascript">
+ testedComponentId =
"#{rich:clientId('tabPanel')}";
+ </script>
+
+ <h:commandButton id="switchButton1" value="switch to
tab1">
+ <rich:componentControl event="click"
operation="switchToItem" target="tabPanel" >
+ <f:param value="tab1" />
+ </rich:componentControl>
+ </h:commandButton>
+ <h:commandButton id="switchButton2" value="switch to
tab2">
+ <rich:componentControl event="click"
operation="switchToItem" target="tabPanel" >
+ <f:param value="tab2" />
+ </rich:componentControl>
+ </h:commandButton>
+ <h:commandButton id="switchButton3" value="switch to
tab3">
+ <rich:componentControl event="click"
operation="switchToItem" target="tabPanel" >
+ <f:param value="tab3" />
+ </rich:componentControl>
+ </h:commandButton>
+ <h:commandButton id="switchButton4" value="switch to
tab4">
+ <rich:componentControl event="click"
operation="switchToItem" target="tabPanel" >
+ <f:param value="tab4" />
+ </rich:componentControl>
+ </h:commandButton>
+ <h:commandButton id="switchButton5" value="switch to
tab5">
+ <rich:componentControl event="click"
operation="switchToItem" target="tabPanel" >
+ <f:param value="tab5" />
+ </rich:componentControl>
+ </h:commandButton>
+
+ <h:commandButton id="hCreateTabButton" value="[h]
Create tab"
+ actionListener="#{richTabPanelBean.createNewTab}" />
+ <a4j:commandButton id="a4jCreateTabButton" value="[a4j]
Create tab"
+ render="tabPanel"
+ actionListener="#{richTabPanelBean.createNewTab}" />
+
+ </fieldset>
+
+ </ui:define>
+
+ <ui:define name="outOfTemplateAfter">
+ <metamer:attributes value="#{richTabPanelBean.attributes}"
id="attributes" render="log"/>
+ </ui:define>
+
+ </ui:composition>
+</html>
\ No newline at end of file