Author: jjamrich
Date: 2011-06-06 18:02:38 -0400 (Mon, 06 Jun 2011)
New Revision: 22527
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/rich/RichTabPanelBean.java
modules/tests/metamer/trunk/application/src/main/webapp/components/richTabPanel/addTab2.xhtml
Log:
Add support for delete created tabs
Simulate issue from user forum:
http://community.jboss.org/thread/167372
JIRA:
https://issues.jboss.org/browse/RF-11054
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-06-06
12:47:30 UTC (rev 22526)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/rich/RichTabPanelBean.java 2011-06-06
22:02:38 UTC (rev 22527)
@@ -28,6 +28,7 @@
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
+import javax.faces.context.FacesContext;
import org.richfaces.component.UITab;
import org.richfaces.component.UITabPanel;
@@ -98,6 +99,31 @@
System.out.println(" Now is tabBeans list " + tabBeans.size() + "
long");
}
+
+ public void removeTab() throws Exception {
+ // setActiveTabId("TAB1");
+
+ String tabIdToRemove = FacesContext.getCurrentInstance().getExternalContext()
+ .getRequestParameterMap().get("removeTabId");
+
+ TabBean currentTab = getTabById(tabIdToRemove);
+
+ if (currentTab != null) {
+ tabBeans.remove(currentTab);
+ } else {
+ throw new Exception("Tab Id parameter is null");
+ }
+ }
+
+ private TabBean getTabById(String tabId) {
+ System.out.println(" #tabId to remove: '" + tabId +
"'");
+ for (TabBean currentTab : tabBeans) {
+ if (currentTab.getTabId().equals(tabId)) {
+ return currentTab;
+ }
+ }
+ return null;
+ }
public Attributes getAttributes() {
return attributes;
@@ -120,6 +146,7 @@
private String tabName;
private String tabHeader;
private String tabContentText;
+ private boolean closable;
public TabBean(String tabId, String tabName, String tabHeader,
String tabContentText){
@@ -127,6 +154,9 @@
this.tabName = tabName;
this.tabHeader = tabHeader;
this.tabContentText = tabContentText;
+
+ // default is closable
+ this.closable = true;
}
public String getTabId() {
@@ -160,6 +190,14 @@
public void setTabContentText(String tabContentText) {
this.tabContentText = tabContentText;
}
+
+ public boolean isClosable() {
+ return closable;
+ }
+
+ public void setClosable(boolean closable) {
+ this.closable = closable;
+ }
}
Modified:
modules/tests/metamer/trunk/application/src/main/webapp/components/richTabPanel/addTab2.xhtml
===================================================================
---
modules/tests/metamer/trunk/application/src/main/webapp/components/richTabPanel/addTab2.xhtml 2011-06-06
12:47:30 UTC (rev 22526)
+++
modules/tests/metamer/trunk/application/src/main/webapp/components/richTabPanel/addTab2.xhtml 2011-06-06
22:02:38 UTC (rev 22527)
@@ -85,13 +85,26 @@
</rich:tab>
<c:forEach items="#{richTabPanelBean.tabBeans}"
var="newTab">
- <rich:tab id="#{newTab.tabId}"
name="#{newTab.tabName}" header="#{newTab.tabHeader}">
+ <rich:tab id="#{newTab.tabId}"
name="#{newTab.tabName}">
#{newTab.tabContentText}
- </rich:tab>
+ <f:facet name="header">
+ <h:outputText value="#{newTab.tabHeader} " />
+ <h:commandLink value="[x]"
+ rendered="#{newTab.closable}"
+ onclick="removeTab('#{newTab.tabId}');" />
+ </f:facet>
+ </rich:tab>
</c:forEach>
-
+
</rich:tabPanel>
+ <a4j:jsFunction name="removeTab"
+ action="#{richTabPanelBean.removeTab}"
+ render="tabPanel"
+
oncomplete="#{rich:component('tabPanel')}.switchToItem('tab1');">
+ <a4j:param name="removeTabId"/>
+ </a4j:jsFunction>
+
<br/><br/>
<fieldset>
<legend>JavaScript API</legend>