JBoss Rich Faces SVN: r20313 - in modules/tests/metamer/trunk/application/src/main: webapp/components/richInputNumberSpinner and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: ppitonak(a)redhat.com
Date: 2010-12-02 11:33:17 -0500 (Thu, 02 Dec 2010)
New Revision: 20313
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichInputNumberSpinnerBean.java
modules/tests/metamer/trunk/application/src/main/webapp/components/richInputNumberSpinner/simple.xhtml
Log:
https://jira.jboss.org/browse/RFPL-857
* slider sample fixed
Modified: modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichInputNumberSpinnerBean.java
===================================================================
--- modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichInputNumberSpinnerBean.java 2010-12-02 16:17:46 UTC (rev 20312)
+++ modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichInputNumberSpinnerBean.java 2010-12-02 16:33:17 UTC (rev 20313)
@@ -54,17 +54,17 @@
logger = LoggerFactory.getLogger(getClass());
logger.debug("initializing bean " + getClass().getName());
- attributes = Attributes.getUIComponentAttributes(HtmlInputNumberSpinner.class, getClass());
+ attributes = Attributes.getUIComponentAttributes(HtmlInputNumberSpinner.class, getClass(), false);
attributes.setAttribute("enableManualInput", true);
attributes.setAttribute("maxValue", 10);
attributes.setAttribute("minValue", -10);
attributes.setAttribute("rendered", true);
+ attributes.get("rendered").setType(boolean.class);
attributes.setAttribute("step", 1);
attributes.setAttribute("value", 2);
// TODO has to be tested in another way
- attributes.remove("validator");
attributes.remove("valueChangeListener");
}
Modified: modules/tests/metamer/trunk/application/src/main/webapp/components/richInputNumberSpinner/simple.xhtml
===================================================================
--- modules/tests/metamer/trunk/application/src/main/webapp/components/richInputNumberSpinner/simple.xhtml 2010-12-02 16:17:46 UTC (rev 20312)
+++ modules/tests/metamer/trunk/application/src/main/webapp/components/richInputNumberSpinner/simple.xhtml 2010-12-02 16:33:17 UTC (rev 20313)
@@ -45,16 +45,11 @@
<ui:define name="component">
<rich:inputNumberSpinner id="spinner"
accesskey="#{richInputNumberSpinnerBean.attributes['accesskey'].value}"
- converter="#{richInputNumberSpinnerBean.attributes['converter'].value}"
- converterMessage="#{richInputNumberSpinnerBean.attributes['converterMessage'].value}"
cycled="#{richInputNumberSpinnerBean.attributes['cycled'].value}"
disabled="#{richInputNumberSpinnerBean.attributes['disabled'].value}"
enableManualInput="#{richInputNumberSpinnerBean.attributes['enableManualInput'].value}"
- immediate="#{richInputNumberSpinnerBean.attributes['immediate'].value}"
inputClass="#{richInputNumberSpinnerBean.attributes['inputClass'].value}"
inputSize="#{richInputNumberSpinnerBean.attributes['inputSize'].value}"
- localValue="#{richInputNumberSpinnerBean.attributes['localValue'].value}"
- localValueSet="#{richInputNumberSpinnerBean.attributes['localValueSet'].value}"
maxValue="#{richInputNumberSpinnerBean.attributes['maxValue'].value}"
minValue="#{richInputNumberSpinnerBean.attributes['minValue'].value}"
onblur="#{richInputNumberSpinnerBean.attributes['onblur'].value}"
@@ -81,18 +76,13 @@
onselect="#{richInputNumberSpinnerBean.attributes['onselect'].value}"
onupclick="#{richInputNumberSpinnerBean.attributes['onupclick'].value}"
rendered="#{richInputNumberSpinnerBean.attributes['rendered'].value}"
- required="#{richInputNumberSpinnerBean.attributes['required'].value}"
- requiredMessage="#{richInputNumberSpinnerBean.attributes['requiredMessage'].value}"
step="#{richInputNumberSpinnerBean.attributes['step'].value}"
style="#{richInputNumberSpinnerBean.attributes['style'].value}"
styleClass="#{richInputNumberSpinnerBean.attributes['styleClass'].value}"
- submittedValue="#{richInputNumberSpinnerBean.attributes['submittedValue'].value}"
tabindex="#{richInputNumberSpinnerBean.attributes['tabindex'].value}"
- valid="#{richInputNumberSpinnerBean.attributes['valid'].value}"
- validatorMessage="#{richInputNumberSpinnerBean.attributes['validatorMessage'].value}"
- validators="#{richInputNumberSpinnerBean.attributes['validators'].value}"
value="#{richInputNumberSpinnerBean.attributes['value'].value}"
- valueChangeListeners="#{richInputNumberSpinnerBean.attributes['valueChangeListeners'].value}">
+ valueChangeListener="#{richBean.valueChangeListener}"
+ >
<a4j:ajax render="output" action="#{richBean.dummyAction}" actionListener="#{richBean.dummyActionListener}" />
13 years, 5 months
JBoss Rich Faces SVN: r20312 - modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean.
by richfaces-svn-commits@lists.jboss.org
Author: ppitonak(a)redhat.com
Date: 2010-12-02 11:17:46 -0500 (Thu, 02 Dec 2010)
New Revision: 20312
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/A4JCommandButtonBean.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/A4JCommandLinkBean.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/CommandButtonBean.java
Log:
* scope of beans changed from session to view
Modified: modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/A4JCommandButtonBean.java
===================================================================
--- modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/A4JCommandButtonBean.java 2010-12-02 14:57:21 UTC (rev 20311)
+++ modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/A4JCommandButtonBean.java 2010-12-02 16:17:46 UTC (rev 20312)
@@ -19,18 +19,14 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*******************************************************************************/
-
package org.richfaces.tests.metamer.bean;
import java.io.Serializable;
-
-
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
-import javax.faces.bean.SessionScoped;
+import javax.faces.bean.ViewScoped;
import javax.faces.event.ActionEvent;
import org.richfaces.component.UICommandButton;
-
import org.richfaces.tests.metamer.Attribute;
import org.richfaces.tests.metamer.Attributes;
import org.slf4j.Logger;
@@ -43,7 +39,7 @@
* @version $Revision$
*/
@ManagedBean(name = "a4jButtonBean")
-@SessionScoped
+@ViewScoped
public class A4JCommandButtonBean implements Serializable {
private static final long serialVersionUID = -2556026843426776944L;
Modified: modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/A4JCommandLinkBean.java
===================================================================
--- modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/A4JCommandLinkBean.java 2010-12-02 14:57:21 UTC (rev 20311)
+++ modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/A4JCommandLinkBean.java 2010-12-02 16:17:46 UTC (rev 20312)
@@ -19,17 +19,14 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*******************************************************************************/
-
package org.richfaces.tests.metamer.bean;
import java.io.Serializable;
-
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
-import javax.faces.bean.SessionScoped;
+import javax.faces.bean.ViewScoped;
import javax.faces.event.ActionEvent;
import org.richfaces.component.UICommandLink;
-
import org.richfaces.tests.metamer.Attributes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -41,7 +38,7 @@
* @version $Revision$
*/
@ManagedBean(name = "a4jLinkBean")
-@SessionScoped
+@ViewScoped
public class A4JCommandLinkBean implements Serializable {
private static final long serialVersionUID = -2556076843426776944L;
@@ -214,5 +211,4 @@
input3 = input.toUpperCase();
}
}
-
}
Modified: modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/CommandButtonBean.java
===================================================================
--- modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/CommandButtonBean.java 2010-12-02 14:57:21 UTC (rev 20311)
+++ modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/CommandButtonBean.java 2010-12-02 16:17:46 UTC (rev 20312)
@@ -19,17 +19,14 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*******************************************************************************/
-
package org.richfaces.tests.metamer.bean;
import java.io.Serializable;
-
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
-import javax.faces.bean.SessionScoped;
+import javax.faces.bean.ViewScoped;
import javax.faces.component.html.HtmlCommandButton;
import javax.faces.event.ActionEvent;
-
import org.richfaces.tests.metamer.Attributes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -41,7 +38,7 @@
* @version $Revision$
*/
@ManagedBean(name = "buttonBean")
-@SessionScoped
+@ViewScoped
public class CommandButtonBean implements Serializable {
private static final long serialVersionUID = -2576526843426776944L;
@@ -211,5 +208,4 @@
input3 = input.toUpperCase();
}
}
-
}
13 years, 5 months
JBoss Rich Faces SVN: r20311 - in modules/tests/metamer/trunk: ftest-source/src/main/java/org/richfaces/tests/metamer/ftest and 1 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: ppitonak(a)redhat.com
Date: 2010-12-02 09:57:21 -0500 (Thu, 02 Dec 2010)
New Revision: 20311
Added:
modules/tests/metamer/trunk/application/src/main/webapp/components/richToggleControl/accordion.xhtml
modules/tests/metamer/trunk/application/src/main/webapp/components/richToggleControl/tabPanel.xhtml
modules/tests/metamer/trunk/application/src/main/webapp/components/richToggleControl/togglePanel.xhtml
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richToggleControl/
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richToggleControl/AbstractTestToggleControl.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richToggleControl/TestRichTCAccordion.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richToggleControl/TestRichTCTabPanel.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richToggleControl/TestRichTCTogglePanel.java
Removed:
modules/tests/metamer/trunk/application/src/main/webapp/components/richToggleControl/simple.xhtml
Modified:
modules/tests/metamer/trunk/application/src/main/webapp/components/richToggleControl/list.xhtml
Log:
https://jira.jboss.org/browse/RFPL-742
* added 2 new samples for rich:toggleControl - with accordion and tab panel
* added 12 tests for toggle control
Added: modules/tests/metamer/trunk/application/src/main/webapp/components/richToggleControl/accordion.xhtml
===================================================================
--- modules/tests/metamer/trunk/application/src/main/webapp/components/richToggleControl/accordion.xhtml (rev 0)
+++ modules/tests/metamer/trunk/application/src/main/webapp/components/richToggleControl/accordion.xhtml 2010-12-02 14:57:21 UTC (rev 20311)
@@ -0,0 +1,118 @@
+<?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">
+
+ <!--
+JBoss, Home of Professional Open Source
+Copyright 2010, 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="head">
+ <f:metadata>
+ <f:viewParam name="templates" value="#{templateBean.templates}">
+ <f:converter converterId="templatesListConverter" />
+ </f:viewParam>
+ </f:metadata>
+ </ui:define>
+
+ <ui:define name="outOfTemplateBefore">
+ </ui:define>
+
+ <ui:define name="component">
+
+ <h:panelGrid id="panel1Controls" columns="6">
+ panel1:
+ <h:commandButton id="tc11" value="Item 1">
+ <rich:toggleControl targetPanel="panel1" targetItem="item1" />
+ </h:commandButton>
+ <h:outputText value=" | " />
+ <h:commandButton id="tc12" value="Item 2">
+ <rich:toggleControl targetPanel="panel1" targetItem="item2" />
+ </h:commandButton>
+ <h:outputText value=" | " />
+ <h:commandButton id="tc13" value="Item 3">
+ <rich:toggleControl targetPanel="panel1" targetItem="item3" />
+ </h:commandButton>
+ </h:panelGrid>
+
+ <h:panelGrid id="panel2Controls" columns="6">
+ panel2:
+ <h:commandButton id="tc21" value="Item 1">
+ <rich:toggleControl targetPanel="panel2" targetItem="item1" />
+ </h:commandButton>
+ <h:outputText value=" | " />
+ <h:commandButton id="tc22" value="Item 2">
+ <rich:toggleControl targetPanel="panel2" targetItem="item2" />
+ </h:commandButton>
+ <h:outputText value=" | " />
+ <h:commandButton id="tc23" value="Item 3">
+ <rich:toggleControl targetPanel="panel2" targetItem="item3" />
+ </h:commandButton>
+ </h:panelGrid>
+
+ universal toggle control (settings below)
+ <h:commandButton id="tcCustom" value="#{richToggleControlBean.attributes['targetPanel'].value} #{richToggleControlBean.attributes['targetItem'].value}">
+ <rich:toggleControl targetPanel="#{richToggleControlBean.attributes['targetPanel'].value}"
+ targetItem="#{richToggleControlBean.attributes['targetItem'].value}"
+ />
+ </h:commandButton>
+
+ <br/><br/>
+
+ <rich:accordion id="panel1" activeItem="item1">
+ <rich:accordionItem id="item11" name="item1">
+ <p>content of item 1</p>
+ </rich:accordionItem>
+ <rich:accordionItem id="item12" name="item2">
+ <p>content of item 2</p>
+ </rich:accordionItem>
+ <rich:accordionItem id="item13" name="item3">
+ <p>content of item 3</p>
+ </rich:accordionItem>
+ </rich:accordion>
+
+ <br/>
+
+ <rich:accordion id="panel2" activeItem="item1">
+ <rich:accordionItem id="item21" name="item1">
+ <p>content of item 1</p>
+ </rich:accordionItem>
+ <rich:accordionItem id="item22" name="item2">
+ <p>content of item 2</p>
+ </rich:accordionItem>
+ <rich:accordionItem id="item23" name="item3">
+ <p>content of item 3</p>
+ </rich:accordionItem>
+ </rich:accordion>
+ </ui:define>
+
+ <ui:define name="outOfTemplateAfter">
+ <br/>
+ Attributes for the first toggle control:
+ <br/><br/>
+ <metamer:attributes value="#{richToggleControlBean.attributes}" id="attributes" />
+ </ui:define>
+
+ </ui:composition>
+</html>
\ No newline at end of file
Modified: modules/tests/metamer/trunk/application/src/main/webapp/components/richToggleControl/list.xhtml
===================================================================
--- modules/tests/metamer/trunk/application/src/main/webapp/components/richToggleControl/list.xhtml 2010-12-02 14:47:41 UTC (rev 20310)
+++ modules/tests/metamer/trunk/application/src/main/webapp/components/richToggleControl/list.xhtml 2010-12-02 14:57:21 UTC (rev 20311)
@@ -31,10 +31,18 @@
<ui:define name="links">
- <metamer:testPageLink id="simple" outcome="simple" value="Simple">
- Page containing a toggle panel, three <b>rich:toggleControl</b>s and inputs for all attributes.
+ <metamer:testPageLink id="accordion" outcome="accordion" value="Accordion">
+ Page containing two accordions, three <b>rich:toggleControl</b>s for each and inputs for all toggle control's attributes.
</metamer:testPageLink>
+ <metamer:testPageLink id="tabPanel" outcome="tabPanel" value="Tab Panel">
+ Page containing two tab panels, three <b>rich:toggleControl</b>s for each and inputs for all toggle control's attributes.
+ </metamer:testPageLink>
+
+ <metamer:testPageLink id="togglePanel" outcome="togglePanel" value="Toggle Panel">
+ Page containing two toggle panels, three <b>rich:toggleControl</b>s for each and inputs for all toggle control's attributes.
+ </metamer:testPageLink>
+
</ui:define>
</ui:composition>
Deleted: modules/tests/metamer/trunk/application/src/main/webapp/components/richToggleControl/simple.xhtml
===================================================================
--- modules/tests/metamer/trunk/application/src/main/webapp/components/richToggleControl/simple.xhtml 2010-12-02 14:47:41 UTC (rev 20310)
+++ modules/tests/metamer/trunk/application/src/main/webapp/components/richToggleControl/simple.xhtml 2010-12-02 14:57:21 UTC (rev 20311)
@@ -1,125 +0,0 @@
-<?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">
-
- <!--
-JBoss, Home of Professional Open Source
-Copyright 2010, 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="head">
- <f:metadata>
- <f:viewParam name="templates" value="#{templateBean.templates}">
- <f:converter converterId="templatesListConverter" />
- </f:viewParam>
- </f:metadata>
- </ui:define>
-
- <ui:define name="outOfTemplateBefore">
- </ui:define>
-
- <ui:define name="component">
-
- <h:panelGrid id="panel1Controls" columns="6">
- panel1:
- <h:commandLink id="tcLink11" value="Toggle Panel Item 1">
- <rich:toggleControl targetPanel="panel1" targetItem="item1" />
- </h:commandLink>
- <h:outputText value=" | " />
- <h:commandLink id="tcLink12" value="Toggle Panel Item 2">
- <rich:toggleControl targetPanel="panel1" targetItem="item2" />
- </h:commandLink>
- <h:outputText value=" | " />
- <h:commandLink id="tcLink13" value="Toggle Panel Item 3">
- <rich:toggleControl targetPanel="panel1" targetItem="item3" />
- </h:commandLink>
- </h:panelGrid>
-
- <h:panelGrid id="panel2Controls" columns="6">
- panel2:
- <h:commandLink id="tcLink21" value="Toggle Panel Item 1">
- <rich:toggleControl targetPanel="panel2" targetItem="item1" />
- </h:commandLink>
- <h:outputText value=" | " />
- <h:commandLink id="tcLink22" value="Toggle Panel Item 2">
- <rich:toggleControl targetPanel="panel2" targetItem="item2" />
- </h:commandLink>
- <h:outputText value=" | " />
- <h:commandLink id="tcLink23" value="Toggle Panel Item 3">
- <rich:toggleControl targetPanel="panel2" targetItem="item3" />
- </h:commandLink>
- </h:panelGrid>
-
- universal toggle control (settings below)
- <h:commandLink id="toggleControlLink" value="Toggle Panel Item">
- <rich:toggleControl targetPanel="#{richToggleControlBean.attributes['targetPanel'].value}"
- targetItem="#{richToggleControlBean.attributes['targetItem'].value}"
- />
- </h:commandLink>
-
- <br/><br/>
-
- <fieldset>
- <legend>panel1</legend>
- <rich:togglePanel id="panel1" activeItem="item1">
- <rich:togglePanelItem id="item11" name="item1">
- <p>content of panel 1</p>
- </rich:togglePanelItem>
- <rich:togglePanelItem id="item12" name="item2">
- <p>content of panel 2</p>
- </rich:togglePanelItem>
- <rich:togglePanelItem id="item13" name="item3">
- <p>content of panel 3</p>
- </rich:togglePanelItem>
- </rich:togglePanel>
- </fieldset>
-
- <br/>
-
- <fieldset>
- <legend>panel2</legend>
- <rich:togglePanel id="panel2" activeItem="item1">
- <rich:togglePanelItem id="item21" name="item1">
- <p>content of panel 1</p>
- </rich:togglePanelItem>
- <rich:togglePanelItem id="item22" name="item2">
- <p>content of panel 2</p>
- </rich:togglePanelItem>
- <rich:togglePanelItem id="item23" name="item3">
- <p>content of panel 3</p>
- </rich:togglePanelItem>
- </rich:togglePanel>
- </fieldset>
-
- </ui:define>
-
- <ui:define name="outOfTemplateAfter">
- <br/>
- Attributes for the first toggle control:
- <br/><br/>
- <metamer:attributes value="#{richToggleControlBean.attributes}" id="attributes" />
- </ui:define>
-
- </ui:composition>
-</html>
\ No newline at end of file
Added: modules/tests/metamer/trunk/application/src/main/webapp/components/richToggleControl/tabPanel.xhtml
===================================================================
--- modules/tests/metamer/trunk/application/src/main/webapp/components/richToggleControl/tabPanel.xhtml (rev 0)
+++ modules/tests/metamer/trunk/application/src/main/webapp/components/richToggleControl/tabPanel.xhtml 2010-12-02 14:57:21 UTC (rev 20311)
@@ -0,0 +1,118 @@
+<?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">
+
+ <!--
+JBoss, Home of Professional Open Source
+Copyright 2010, 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="head">
+ <f:metadata>
+ <f:viewParam name="templates" value="#{templateBean.templates}">
+ <f:converter converterId="templatesListConverter" />
+ </f:viewParam>
+ </f:metadata>
+ </ui:define>
+
+ <ui:define name="outOfTemplateBefore">
+ </ui:define>
+
+ <ui:define name="component">
+
+ <h:panelGrid id="panel1Controls" columns="6">
+ panel1:
+ <h:commandButton id="tc11" value="Item 1">
+ <rich:toggleControl targetPanel="panel1" targetItem="item1" />
+ </h:commandButton>
+ <h:outputText value=" | " />
+ <h:commandButton id="tc12" value="Item 2">
+ <rich:toggleControl targetPanel="panel1" targetItem="item2" />
+ </h:commandButton>
+ <h:outputText value=" | " />
+ <h:commandButton id="tc13" value="Item 3">
+ <rich:toggleControl targetPanel="panel1" targetItem="item3" />
+ </h:commandButton>
+ </h:panelGrid>
+
+ <h:panelGrid id="panel2Controls" columns="6">
+ panel2:
+ <h:commandButton id="tc21" value="Item 1">
+ <rich:toggleControl targetPanel="panel2" targetItem="item1" />
+ </h:commandButton>
+ <h:outputText value=" | " />
+ <h:commandButton id="tc22" value="Item 2">
+ <rich:toggleControl targetPanel="panel2" targetItem="item2" />
+ </h:commandButton>
+ <h:outputText value=" | " />
+ <h:commandButton id="tc23" value="Item 3">
+ <rich:toggleControl targetPanel="panel2" targetItem="item3" />
+ </h:commandButton>
+ </h:panelGrid>
+
+ universal toggle control (settings below)
+ <h:commandButton id="tcCustom" value="#{richToggleControlBean.attributes['targetPanel'].value} #{richToggleControlBean.attributes['targetItem'].value}">
+ <rich:toggleControl targetPanel="#{richToggleControlBean.attributes['targetPanel'].value}"
+ targetItem="#{richToggleControlBean.attributes['targetItem'].value}"
+ />
+ </h:commandButton>
+
+ <br/><br/>
+
+ <rich:tabPanel id="panel1" activeItem="item1">
+ <rich:tab id="item11" name="item1">
+ <p>content of item 1</p>
+ </rich:tab>
+ <rich:tab id="item12" name="item2">
+ <p>content of item 2</p>
+ </rich:tab>
+ <rich:tab id="item13" name="item3">
+ <p>content of item 3</p>
+ </rich:tab>
+ </rich:tabPanel>
+
+ <br/>
+
+ <rich:tabPanel id="panel2" activeItem="item1">
+ <rich:tab id="item21" name="item1">
+ <p>content of item 1</p>
+ </rich:tab>
+ <rich:tab id="item22" name="item2">
+ <p>content of item 2</p>
+ </rich:tab>
+ <rich:tab id="item23" name="item3">
+ <p>content of item 3</p>
+ </rich:tab>
+ </rich:tabPanel>
+ </ui:define>
+
+ <ui:define name="outOfTemplateAfter">
+ <br/>
+ Attributes for the first toggle control:
+ <br/><br/>
+ <metamer:attributes value="#{richToggleControlBean.attributes}" id="attributes" />
+ </ui:define>
+
+ </ui:composition>
+</html>
\ No newline at end of file
Copied: modules/tests/metamer/trunk/application/src/main/webapp/components/richToggleControl/togglePanel.xhtml (from rev 20284, modules/tests/metamer/trunk/application/src/main/webapp/components/richToggleControl/simple.xhtml)
===================================================================
--- modules/tests/metamer/trunk/application/src/main/webapp/components/richToggleControl/togglePanel.xhtml (rev 0)
+++ modules/tests/metamer/trunk/application/src/main/webapp/components/richToggleControl/togglePanel.xhtml 2010-12-02 14:57:21 UTC (rev 20311)
@@ -0,0 +1,125 @@
+<?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">
+
+ <!--
+JBoss, Home of Professional Open Source
+Copyright 2010, 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="head">
+ <f:metadata>
+ <f:viewParam name="templates" value="#{templateBean.templates}">
+ <f:converter converterId="templatesListConverter" />
+ </f:viewParam>
+ </f:metadata>
+ </ui:define>
+
+ <ui:define name="outOfTemplateBefore">
+ </ui:define>
+
+ <ui:define name="component">
+
+ <h:panelGrid id="panel1Controls" columns="6">
+ panel1:
+ <h:commandButton id="tc11" value="Item 1">
+ <rich:toggleControl targetPanel="panel1" targetItem="item1" />
+ </h:commandButton>
+ <h:outputText value=" | " />
+ <h:commandButton id="tc12" value="Item 2">
+ <rich:toggleControl targetPanel="panel1" targetItem="item2" />
+ </h:commandButton>
+ <h:outputText value=" | " />
+ <h:commandButton id="tc13" value="Item 3">
+ <rich:toggleControl targetPanel="panel1" targetItem="item3" />
+ </h:commandButton>
+ </h:panelGrid>
+
+ <h:panelGrid id="panel2Controls" columns="6">
+ panel2:
+ <h:commandButton id="tc21" value="Item 1">
+ <rich:toggleControl targetPanel="panel2" targetItem="item1" />
+ </h:commandButton>
+ <h:outputText value=" | " />
+ <h:commandButton id="tc22" value="Item 2">
+ <rich:toggleControl targetPanel="panel2" targetItem="item2" />
+ </h:commandButton>
+ <h:outputText value=" | " />
+ <h:commandButton id="tc23" value="Item 3">
+ <rich:toggleControl targetPanel="panel2" targetItem="item3" />
+ </h:commandButton>
+ </h:panelGrid>
+
+ universal toggle control (settings below)
+ <h:commandButton id="tcCustom" value="#{richToggleControlBean.attributes['targetPanel'].value} #{richToggleControlBean.attributes['targetItem'].value}">
+ <rich:toggleControl targetPanel="#{richToggleControlBean.attributes['targetPanel'].value}"
+ targetItem="#{richToggleControlBean.attributes['targetItem'].value}"
+ />
+ </h:commandButton>
+
+ <br/><br/>
+
+ <fieldset>
+ <legend>panel1</legend>
+ <rich:togglePanel id="panel1" activeItem="item1">
+ <rich:togglePanelItem id="item11" name="item1">
+ <p>content of item 1</p>
+ </rich:togglePanelItem>
+ <rich:togglePanelItem id="item12" name="item2">
+ <p>content of item 2</p>
+ </rich:togglePanelItem>
+ <rich:togglePanelItem id="item13" name="item3">
+ <p>content of item 3</p>
+ </rich:togglePanelItem>
+ </rich:togglePanel>
+ </fieldset>
+
+ <br/>
+
+ <fieldset>
+ <legend>panel2</legend>
+ <rich:togglePanel id="panel2" activeItem="item1">
+ <rich:togglePanelItem id="item21" name="item1">
+ <p>content of item 1</p>
+ </rich:togglePanelItem>
+ <rich:togglePanelItem id="item22" name="item2">
+ <p>content of item 2</p>
+ </rich:togglePanelItem>
+ <rich:togglePanelItem id="item23" name="item3">
+ <p>content of item 3</p>
+ </rich:togglePanelItem>
+ </rich:togglePanel>
+ </fieldset>
+
+ </ui:define>
+
+ <ui:define name="outOfTemplateAfter">
+ <br/>
+ Attributes for the first toggle control:
+ <br/><br/>
+ <metamer:attributes value="#{richToggleControlBean.attributes}" id="attributes" />
+ </ui:define>
+
+ </ui:composition>
+</html>
\ No newline at end of file
Added: modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richToggleControl/AbstractTestToggleControl.java
===================================================================
--- modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richToggleControl/AbstractTestToggleControl.java (rev 0)
+++ modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richToggleControl/AbstractTestToggleControl.java 2010-12-02 14:57:21 UTC (rev 20311)
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.
+ *******************************************************************************/
+package org.richfaces.tests.metamer.ftest.richToggleControl;
+
+import static org.jboss.test.selenium.guard.request.RequestTypeGuardFactory.guardXhr;
+import static org.testng.Assert.assertFalse;
+
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
+
+/**
+ * Abstract test case for rich:toggleControl.
+ *
+ * @author <a href="mailto:ppitonak@redhat.com">Pavol Pitonak</a>
+ * @version $Revision$
+ */
+public abstract class AbstractTestToggleControl extends AbstractMetamerTest {
+
+ private JQueryLocator[] buttons1 = {pjq("input[id$=tc11]"), pjq("input[id$=tc12]"), pjq("input[id$=tc13]")};
+ private JQueryLocator[] buttons2 = {pjq("input[id$=tc21]"), pjq("input[id$=tc22]"), pjq("input[id$=tc23]")};
+ private JQueryLocator customButton = pjq("input[id$=tcCustom]");
+
+ public void testSwitchFirstPanel(JQueryLocator[] items) {
+ testSwitching(buttons1, items);
+ }
+
+ public void testSwitchSecondPanel(JQueryLocator[] items) {
+ testSwitching(buttons2, items);
+ }
+
+ public void testTargetItem(JQueryLocator[] items) {
+ selenium.click(pjq("input[name$=targetItemInput][value=item2]"));
+ selenium.waitForPageToLoad();
+
+ guardXhr(selenium).click(buttons1[2]);
+ waitGui.failWith("Item 3 is not displayed.").until(isDisplayed.locator(items[2]));
+ assertFalse(selenium.isVisible(items[0]), "Item 1 should not be visible.");
+ assertFalse(selenium.isVisible(items[1]), "Item 2 should not be visible.");
+
+ guardXhr(selenium).click(customButton);
+ waitGui.failWith("Item 2 is not displayed.").until(isDisplayed.locator(items[1]));
+ assertFalse(selenium.isVisible(items[0]), "Item 1 should not be visible.");
+ assertFalse(selenium.isVisible(items[2]), "Item 3 should not be visible.");
+ }
+
+ public void testTargetPanel(JQueryLocator[] items) {
+ selenium.click(pjq("input[name$=targetPanelInput][value=panel2]"));
+ selenium.waitForPageToLoad();
+
+ guardXhr(selenium).click(buttons2[2]);
+ waitGui.failWith("Item 3 is not displayed.").until(isDisplayed.locator(items[2]));
+ assertFalse(selenium.isVisible(items[0]), "Item 1 should not be visible.");
+ assertFalse(selenium.isVisible(items[1]), "Item 2 should not be visible.");
+
+ guardXhr(selenium).click(customButton);
+ waitGui.failWith("Item 1 is not displayed.").until(isDisplayed.locator(items[0]));
+ assertFalse(selenium.isVisible(items[1]), "Item 2 should not be visible.");
+ assertFalse(selenium.isVisible(items[2]), "Item 3 should not be visible.");
+ }
+
+ private void testSwitching(JQueryLocator[] buttons, JQueryLocator[] items) {
+ guardXhr(selenium).click(buttons[2]);
+ waitGui.failWith("Item 3 is not displayed.").until(isDisplayed.locator(items[2]));
+ assertFalse(selenium.isVisible(items[0]), "Item 1 should not be visible.");
+ assertFalse(selenium.isVisible(items[1]), "Item 2 should not be visible.");
+
+ guardXhr(selenium).click(buttons[1]);
+ waitGui.failWith("Item 2 is not displayed.").until(isDisplayed.locator(items[1]));
+ assertFalse(selenium.isVisible(items[0]), "Item 1 should not be visible.");
+ assertFalse(selenium.isVisible(items[2]), "Item 3 should not be visible.");
+
+ guardXhr(selenium).click(buttons[0]);
+ waitGui.failWith("Item 1 is not displayed.").until(isDisplayed.locator(items[0]));
+ assertFalse(selenium.isVisible(items[1]), "Item 2 should not be visible.");
+ assertFalse(selenium.isVisible(items[2]), "Item 3 should not be visible.");
+ }
+}
Property changes on: modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richToggleControl/AbstractTestToggleControl.java
___________________________________________________________________
Name: svn:keywords
+ Revision
Added: modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richToggleControl/TestRichTCAccordion.java
===================================================================
--- modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richToggleControl/TestRichTCAccordion.java (rev 0)
+++ modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richToggleControl/TestRichTCAccordion.java 2010-12-02 14:57:21 UTC (rev 20311)
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.
+ *******************************************************************************/
+package org.richfaces.tests.metamer.ftest.richToggleControl;
+
+import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
+
+import java.net.URL;
+
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.testng.annotations.Test;
+
+/**
+ * Test case for page /faces/components/richToggleControl/accordion.xhtml
+ *
+ * @author <a href="mailto:ppitonak@redhat.com">Pavol Pitonak</a>
+ * @version $Revision$
+ */
+public class TestRichTCAccordion extends AbstractTestToggleControl {
+
+ JQueryLocator[] items1 = {pjq("div[id$=item11:content]"), pjq("div[id$=item12:content]"), pjq("div[id$=item13:content]")};
+ JQueryLocator[] items2 = {pjq("div[id$=item21:content]"), pjq("div[id$=item22:content]"), pjq("div[id$=item23:content]")};
+
+ @Override
+ public URL getTestUrl() {
+ return buildUrl(contextPath, "faces/components/richToggleControl/accordion.xhtml");
+ }
+
+ @Test
+ public void testSwitchFirstPanel() {
+ testSwitchFirstPanel(items1);
+ }
+
+ @Test
+ public void testSwitchSecondPanel() {
+ testSwitchSecondPanel(items2);
+ }
+
+ @Test
+ public void testTargetItem() {
+ testTargetItem(items1);
+ }
+
+ @Test
+ public void testTargetPanel() {
+ testTargetPanel(items2);
+ }
+}
Property changes on: modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richToggleControl/TestRichTCAccordion.java
___________________________________________________________________
Name: svn:keywords
+ Revision
Added: modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richToggleControl/TestRichTCTabPanel.java
===================================================================
--- modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richToggleControl/TestRichTCTabPanel.java (rev 0)
+++ modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richToggleControl/TestRichTCTabPanel.java 2010-12-02 14:57:21 UTC (rev 20311)
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.
+ *******************************************************************************/
+package org.richfaces.tests.metamer.ftest.richToggleControl;
+
+import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
+
+import java.net.URL;
+
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.testng.annotations.Test;
+
+/**
+ * Test case for page /faces/components/richToggleControl/tabPanel.xhtml
+ *
+ * @author <a href="mailto:ppitonak@redhat.com">Pavol Pitonak</a>
+ * @version $Revision$
+ */
+public class TestRichTCTabPanel extends AbstractTestToggleControl {
+
+ JQueryLocator[] items1 = {pjq("div[id$=item11:content]"), pjq("div[id$=item12:content]"), pjq("div[id$=item13:content]")};
+ JQueryLocator[] items2 = {pjq("div[id$=item21:content]"), pjq("div[id$=item22:content]"), pjq("div[id$=item23:content]")};
+
+ @Override
+ public URL getTestUrl() {
+ return buildUrl(contextPath, "faces/components/richToggleControl/tabPanel.xhtml");
+ }
+
+ @Test
+ public void testSwitchFirstPanel() {
+ testSwitchFirstPanel(items1);
+ }
+
+ @Test
+ public void testSwitchSecondPanel() {
+ testSwitchSecondPanel(items2);
+ }
+
+ @Test
+ public void testTargetItem() {
+ testTargetItem(items1);
+ }
+
+ @Test
+ public void testTargetPanel() {
+ testTargetPanel(items2);
+ }
+}
Property changes on: modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richToggleControl/TestRichTCTabPanel.java
___________________________________________________________________
Name: svn:keywords
+ Revision
Added: modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richToggleControl/TestRichTCTogglePanel.java
===================================================================
--- modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richToggleControl/TestRichTCTogglePanel.java (rev 0)
+++ modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richToggleControl/TestRichTCTogglePanel.java 2010-12-02 14:57:21 UTC (rev 20311)
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.
+ *******************************************************************************/
+package org.richfaces.tests.metamer.ftest.richToggleControl;
+
+import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
+
+import java.net.URL;
+
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.testng.annotations.Test;
+
+/**
+ * Test case for page /faces/components/richToggleControl/togglePanel.xhtml
+ *
+ * @author <a href="mailto:ppitonak@redhat.com">Pavol Pitonak</a>
+ * @version $Revision$
+ */
+public class TestRichTCTogglePanel extends AbstractTestToggleControl {
+
+ JQueryLocator[] items1 = {pjq("div[id$=item11]"), pjq("div[id$=item12]"), pjq("div[id$=item13]")};
+ JQueryLocator[] items2 = {pjq("div[id$=item21]"), pjq("div[id$=item22]"), pjq("div[id$=item23]")};
+
+ @Override
+ public URL getTestUrl() {
+ return buildUrl(contextPath, "faces/components/richToggleControl/togglePanel.xhtml");
+ }
+
+ @Test
+ public void testSwitchFirstPanel() {
+ testSwitchFirstPanel(items1);
+ }
+
+ @Test
+ public void testSwitchSecondPanel() {
+ testSwitchSecondPanel(items2);
+ }
+
+ @Test
+ public void testTargetItem() {
+ testTargetItem(items1);
+ }
+
+ @Test
+ public void testTargetPanel() {
+ testTargetPanel(items2);
+ }
+}
Property changes on: modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richToggleControl/TestRichTCTogglePanel.java
___________________________________________________________________
Name: svn:keywords
+ Revision
13 years, 5 months
JBoss Rich Faces SVN: r20310 - in trunk/ui/iteration: ui/src/main/java/org/richfaces/component and 4 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2010-12-02 09:47:41 -0500 (Thu, 02 Dec 2010)
New Revision: 20310
Added:
trunk/ui/iteration/api/src/main/java/org/richfaces/model/TreeNode.java
trunk/ui/iteration/api/src/main/java/org/richfaces/model/TreeNodeImpl.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/convert/DeclarativeModelKeyConverter.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/convert/DeclarativeModelKeySequenceRowKeyConverter.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/convert/IntegerSequenceRowKeyConverter.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/convert/ObjectSequenceRowKeyConverter.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/convert/TreeConverterUtil.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/ClassicTreeNodeDataModelImpl.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/ClassicTreeNodeTuplesIterator.java
trunk/ui/iteration/ui/src/test/java/org/richfaces/convert/
trunk/ui/iteration/ui/src/test/java/org/richfaces/convert/TreeConverterUtilTest.java
Modified:
trunk/ui/iteration/api/src/main/java/org/richfaces/model/SwingTreeNodeImpl.java
trunk/ui/iteration/api/src/main/java/org/richfaces/model/TreeDataModel.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTree.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/TreeRange.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/convert/SequenceRowKeyConverter.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeModelKey.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeTreeDataModelCompositeTuplesIterator.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeTreeDataModelImpl.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeTreeDataModelTuplesIterator.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SequenceRowKey.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SwingTreeNodeDataModelImpl.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SwingTreeNodeTuplesIterator.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/TreeSequenceKeyModel.java
Log:
https://jira.jboss.org/browse/RF-9718
https://jira.jboss.org/browse/RF-9729
https://jira.jboss.org/browse/RF-9902
Modified: trunk/ui/iteration/api/src/main/java/org/richfaces/model/SwingTreeNodeImpl.java
===================================================================
--- trunk/ui/iteration/api/src/main/java/org/richfaces/model/SwingTreeNodeImpl.java 2010-12-02 14:32:03 UTC (rev 20309)
+++ trunk/ui/iteration/api/src/main/java/org/richfaces/model/SwingTreeNodeImpl.java 2010-12-02 14:47:41 UTC (rev 20310)
@@ -43,29 +43,29 @@
private static final long serialVersionUID = 8841984268370598781L;
private TreeNode parent;
-
+
private T data;
-
+
private Collection<TreeNode> children;
-
+
private boolean allowUpdateParents = true;
-
+
public SwingTreeNodeImpl() {
this(null);
}
-
- void setAllowUpdateParents(boolean allowUpdateParents) {
- this.allowUpdateParents = allowUpdateParents;
- }
-
+
public SwingTreeNodeImpl(Collection<TreeNode> children) {
this.children = wrapNull(children);
}
+ void setAllowUpdateParents(boolean allowUpdateParents) {
+ this.allowUpdateParents = allowUpdateParents;
+ }
+
private static Collection<TreeNode> wrapNull(Collection<TreeNode> src) {
return src != null ? src : Lists.<TreeNode>newArrayList();
}
-
+
public TreeNode getChildAt(int childIndex) {
return Iterables.get(children, childIndex);
}
@@ -81,7 +81,7 @@
public void setParent(TreeNode parent) {
this.parent = parent;
}
-
+
public int getIndex(TreeNode node) {
return Iterables.indexOf(children, Predicates.equalTo(node));
}
@@ -93,16 +93,16 @@
treeNodeImpl.setParent(this);
}
}
-
+
public void removeChild(TreeNode node) {
if (children.remove(node)) {
if (allowUpdateParents && node instanceof SwingTreeNodeImpl<?>) {
SwingTreeNodeImpl<?> treeNodeImpl = (SwingTreeNodeImpl<?>) node;
treeNodeImpl.setParent(null);
}
- }
+ }
}
-
+
public boolean getAllowsChildren() {
return true;
}
@@ -118,20 +118,20 @@
public T getData() {
return data;
}
-
+
public void setData(T data) {
this.data = data;
}
-
+
public Collection<TreeNode> getChildrenList() {
return children;
}
-
+
@Override
public String toString() {
ToStringHelper toStringHelper = Objects.toStringHelper(this);
toStringHelper.add("data", data);
-
+
return toStringHelper.toString();
}
}
Modified: trunk/ui/iteration/api/src/main/java/org/richfaces/model/TreeDataModel.java
===================================================================
--- trunk/ui/iteration/api/src/main/java/org/richfaces/model/TreeDataModel.java 2010-12-02 14:32:03 UTC (rev 20309)
+++ trunk/ui/iteration/api/src/main/java/org/richfaces/model/TreeDataModel.java 2010-12-02 14:47:41 UTC (rev 20310)
@@ -23,7 +23,9 @@
import java.util.Iterator;
+import javax.faces.convert.Converter;
+
/**
* @author Nick Belaevski
*
@@ -31,6 +33,8 @@
//TODO - add necessary methods for tree adaptors support
public interface TreeDataModel<E> {
+ public static final char SEPARATOR_CHAR = '.';
+
public Object getRowKey();
public void setRowKey(Object rowKey);
@@ -53,4 +57,6 @@
public void restoreFromSnapshot(TreeDataModelTuple tuple);
+ public Converter getRowKeyConverter();
+
}
Added: trunk/ui/iteration/api/src/main/java/org/richfaces/model/TreeNode.java
===================================================================
--- trunk/ui/iteration/api/src/main/java/org/richfaces/model/TreeNode.java (rev 0)
+++ trunk/ui/iteration/api/src/main/java/org/richfaces/model/TreeNode.java 2010-12-02 14:47:41 UTC (rev 20310)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.
+ */
+package org.richfaces.model;
+
+import java.util.Iterator;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public interface TreeNode {
+
+ public TreeNode getChild(Object key);
+
+ public int indexOf(Object key);
+
+ public Iterator<Object> getChildrenKeysIterator();
+
+ public boolean isLeaf();
+
+ public void addChild(Object key, TreeNode child);
+
+ public void insertChild(int idx, Object key, TreeNode child);
+
+ public void removeChild(Object key);
+
+}
Added: trunk/ui/iteration/api/src/main/java/org/richfaces/model/TreeNodeImpl.java
===================================================================
--- trunk/ui/iteration/api/src/main/java/org/richfaces/model/TreeNodeImpl.java (rev 0)
+++ trunk/ui/iteration/api/src/main/java/org/richfaces/model/TreeNodeImpl.java 2010-12-02 14:47:41 UTC (rev 20310)
@@ -0,0 +1,114 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.
+ */
+package org.richfaces.model;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import com.google.common.collect.Iterators;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class TreeNodeImpl implements TreeNode {
+
+ private List<Object> keysList = null;
+
+ private Map<Object, TreeNode> children = null;
+
+ private boolean leaf;
+
+ public TreeNodeImpl() {
+ this(false);
+ }
+
+ public TreeNodeImpl(boolean leaf) {
+ super();
+
+ this.leaf = leaf;
+
+ if (!leaf) {
+ keysList = Lists.newArrayList();
+ children = Maps.newHashMap();
+ }
+ }
+
+ public void addChild(Object key, TreeNode child) {
+ if (isLeaf()) {
+ throw new IllegalStateException("Cannot add children to leaf");
+ }
+
+ keysList.add(key);
+ children.put(key, child);
+ }
+
+ public void insertChild(int idx, Object key, TreeNode child) {
+ if (isLeaf()) {
+ throw new IllegalStateException("Cannot add children to leaf");
+ }
+
+ keysList.add(idx, key);
+ children.put(key, child);
+ }
+
+ public void removeChild(Object key) {
+ if (isLeaf()) {
+ return;
+ }
+
+ children.remove(key);
+ keysList.remove(key);
+ }
+
+ public TreeNode getChild(Object key) {
+ if (isLeaf()) {
+ return null;
+ }
+
+ return children.get(key);
+ }
+
+ public Iterator<Object> getChildrenKeysIterator() {
+ if (isLeaf()) {
+ return Iterators.emptyIterator();
+ }
+
+ return Iterators.unmodifiableIterator(keysList.iterator());
+ }
+
+ public int indexOf(Object key) {
+ if (isLeaf()) {
+ return -1;
+ }
+
+ return keysList.indexOf(key);
+ }
+
+ public boolean isLeaf() {
+ return leaf;
+ }
+
+}
Modified: trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTree.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTree.java 2010-12-02 14:32:03 UTC (rev 20309)
+++ trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTree.java 2010-12-02 14:47:41 UTC (rev 20310)
@@ -61,7 +61,6 @@
import org.richfaces.component.util.MessageUtil;
import org.richfaces.context.ExtendedVisitContext;
import org.richfaces.context.ExtendedVisitContextMode;
-import org.richfaces.convert.SequenceRowKeyConverter;
import org.richfaces.event.TreeSelectionChangeEvent;
import org.richfaces.event.TreeSelectionChangeListener;
import org.richfaces.event.TreeSelectionChangeSource;
@@ -126,8 +125,6 @@
}
};
- private static final Converter ROW_KEY_CONVERTER = new SequenceRowKeyConverter();
-
private enum PropertyKeys {
selection
}
@@ -231,7 +228,7 @@
public Converter getRowKeyConverter() {
Converter converter = super.getRowKeyConverter();
if (converter == null) {
- converter = ROW_KEY_CONVERTER;
+ converter = getTreeDataModel().getRowKeyConverter();
}
return converter;
}
@@ -255,6 +252,10 @@
}
public AbstractTreeNode findTreeNodeComponent() {
+ if (getRowKey() == null) {
+ return null;
+ }
+
FacesContext facesContext = getFacesContext();
String nodeType = getNodeType();
@@ -319,7 +320,7 @@
boolean newExpandedValue = toggleEvent.isExpanded();
FacesContext context = getFacesContext();
- ValueExpression expression = getValueExpression(AbstractTreeNode.PropertyKeys.expanded.toString());
+ ValueExpression expression = treeNodeComponent.getValueExpression(AbstractTreeNode.PropertyKeys.expanded.toString());
if (expression != null) {
ELContext elContext = context.getELContext();
Exception caught = null;
@@ -465,10 +466,6 @@
@Attribute(hidden = true)
public boolean isLeaf() {
- if (getRowKey() == null) {
- return false;
- }
-
return getTreeDataModel().isLeaf();
}
Modified: trunk/ui/iteration/ui/src/main/java/org/richfaces/component/TreeRange.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/component/TreeRange.java 2010-12-02 14:32:03 UTC (rev 20309)
+++ trunk/ui/iteration/ui/src/main/java/org/richfaces/component/TreeRange.java 2010-12-02 14:47:41 UTC (rev 20310)
@@ -41,10 +41,18 @@
}
public boolean shouldProcessNode() {
+ if (tree.getRowKey() == null) {
+ return true;
+ }
+
return tree.findTreeNodeComponent() != null;
}
public boolean shouldIterateChildren() {
+ if (tree.getRowKey() == null) {
+ return true;
+ }
+
if (tree.isLeaf()) {
return false;
}
Added: trunk/ui/iteration/ui/src/main/java/org/richfaces/convert/DeclarativeModelKeyConverter.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/convert/DeclarativeModelKeyConverter.java (rev 0)
+++ trunk/ui/iteration/ui/src/main/java/org/richfaces/convert/DeclarativeModelKeyConverter.java 2010-12-02 14:47:41 UTC (rev 20310)
@@ -0,0 +1,102 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.
+ */
+package org.richfaces.convert;
+
+import static org.richfaces.convert.TreeConverterUtil.escape;
+import static org.richfaces.convert.TreeConverterUtil.unescape;
+
+import java.util.Iterator;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UINamingContainer;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.convert.ConverterException;
+
+import org.richfaces.model.DeclarativeModelKey;
+
+import com.google.common.base.Joiner;
+import com.google.common.base.Splitter;
+import com.google.common.base.Strings;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class DeclarativeModelKeyConverter implements Converter {
+
+ private static final class StaticHolder {
+
+ static final Joiner JOINER;
+
+ static final Splitter SPLITTER;
+
+ static {
+ char separatorChar = UINamingContainer.getSeparatorChar(FacesContext.getCurrentInstance());
+ JOINER = Joiner.on(separatorChar);
+ SPLITTER = Splitter.on(separatorChar);
+ }
+
+ private StaticHolder() {}
+
+ }
+
+ private Converter delegateConverter;
+
+ public DeclarativeModelKeyConverter(Converter delegateConverter) {
+ super();
+ this.delegateConverter = delegateConverter;
+ }
+
+ public Object getAsObject(FacesContext context, UIComponent component, String value) {
+ if (Strings.isNullOrEmpty(value)) {
+ return null;
+ }
+
+ String s = unescape(value);
+
+ Iterator<String> split = StaticHolder.SPLITTER.split(s).iterator();
+
+ String modelId = (String) split.next();
+ Object modelKey = delegateConverter.getAsObject(context, component, split.next());
+
+ if (split.hasNext()) {
+ throw new ConverterException(value);
+ }
+
+ return new DeclarativeModelKey(modelId, modelKey);
+ }
+
+ public String getAsString(FacesContext context, UIComponent component, Object value) {
+ if (value == null) {
+ return "";
+ }
+
+ DeclarativeModelKey declarativeModelKey = (DeclarativeModelKey) value;
+
+ String convertedModelKey = delegateConverter.getAsString(context, component, declarativeModelKey.getModelKey());
+ String keyString = StaticHolder.JOINER.join(declarativeModelKey.getModelId(), convertedModelKey);
+
+ return escape(keyString);
+ }
+
+}
Added: trunk/ui/iteration/ui/src/main/java/org/richfaces/convert/DeclarativeModelKeySequenceRowKeyConverter.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/convert/DeclarativeModelKeySequenceRowKeyConverter.java (rev 0)
+++ trunk/ui/iteration/ui/src/main/java/org/richfaces/convert/DeclarativeModelKeySequenceRowKeyConverter.java 2010-12-02 14:47:41 UTC (rev 20310)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.
+ */
+package org.richfaces.convert;
+
+import javax.faces.convert.IntegerConverter;
+
+import org.richfaces.model.DeclarativeModelKey;
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class DeclarativeModelKeySequenceRowKeyConverter extends SequenceRowKeyConverter<DeclarativeModelKey> {
+
+ public DeclarativeModelKeySequenceRowKeyConverter() {
+ super(DeclarativeModelKey.class, new DeclarativeModelKeyConverter(new IntegerConverter()));
+ }
+
+
+}
Added: trunk/ui/iteration/ui/src/main/java/org/richfaces/convert/IntegerSequenceRowKeyConverter.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/convert/IntegerSequenceRowKeyConverter.java (rev 0)
+++ trunk/ui/iteration/ui/src/main/java/org/richfaces/convert/IntegerSequenceRowKeyConverter.java 2010-12-02 14:47:41 UTC (rev 20310)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.
+ */
+package org.richfaces.convert;
+
+import javax.faces.convert.IntegerConverter;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class IntegerSequenceRowKeyConverter extends SequenceRowKeyConverter<Integer> {
+
+ public IntegerSequenceRowKeyConverter() {
+ super(Integer.class, new IntegerConverter());
+ }
+
+}
Added: trunk/ui/iteration/ui/src/main/java/org/richfaces/convert/ObjectSequenceRowKeyConverter.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/convert/ObjectSequenceRowKeyConverter.java (rev 0)
+++ trunk/ui/iteration/ui/src/main/java/org/richfaces/convert/ObjectSequenceRowKeyConverter.java 2010-12-02 14:47:41 UTC (rev 20310)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.
+ */
+package org.richfaces.convert;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class ObjectSequenceRowKeyConverter extends SequenceRowKeyConverter<Object> {
+
+ private static final Converter NO_OP_CONVERTER = new Converter() {
+
+ public String getAsString(FacesContext context, UIComponent component, Object value) {
+ return (String) value;
+ }
+
+ public Object getAsObject(FacesContext context, UIComponent component, String value) {
+ return value;
+ }
+ };
+
+ public ObjectSequenceRowKeyConverter() {
+ super(Object.class, NO_OP_CONVERTER);
+ }
+
+}
Modified: trunk/ui/iteration/ui/src/main/java/org/richfaces/convert/SequenceRowKeyConverter.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/convert/SequenceRowKeyConverter.java 2010-12-02 14:32:03 UTC (rev 20309)
+++ trunk/ui/iteration/ui/src/main/java/org/richfaces/convert/SequenceRowKeyConverter.java 2010-12-02 14:47:41 UTC (rev 20310)
@@ -1,63 +1,52 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, 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.
- */
package org.richfaces.convert;
+import java.util.List;
+
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
-
+import javax.faces.convert.ConverterException;
+import static org.richfaces.model.TreeDataModel.*;
import org.richfaces.model.SequenceRowKey;
-import com.google.common.base.Function;
-import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
-import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+import com.google.common.collect.ObjectArrays;
/**
* @author Nick Belaevski
- *
+ * @since 3.3.1
*/
-public class SequenceRowKeyConverter implements Converter {
- private static final Joiner DOT_JOINER = Joiner.on('.');
+public class SequenceRowKeyConverter<T> implements Converter {
- private static final Splitter DOT_SPLITTER = Splitter.on('.');
+ private static final Splitter DOT_SPLITTER = Splitter.on(SEPARATOR_CHAR);
- private static final Function<String, Integer> INTEGER_PARSER = new Function<String, Integer>() {
- public Integer apply(String from) {
- return Integer.parseInt(from);
- };
- };
+ private Class<T> clazz;
- public Object getAsObject(FacesContext context, UIComponent component, String value) {
+ private Converter delegateConverter;
+
+ public SequenceRowKeyConverter(Class<T> clazz, Converter delegateConverter) {
+ super();
+ this.clazz = clazz;
+ this.delegateConverter = delegateConverter;
+ }
+
+ public Object getAsObject(FacesContext context, UIComponent component, String value) throws ConverterException {
if (Strings.isNullOrEmpty(value)) {
return null;
}
Iterable<String> split = DOT_SPLITTER.split(value);
-
- //TODO - handle another types
- return new SequenceRowKey<Integer>(Iterables.toArray(Iterables.transform(split, INTEGER_PARSER), Integer.class));
+ List<T> keysList = Lists.<T>newArrayList();
+
+ for (String s: split) {
+ T convertedKey = clazz.cast(delegateConverter.getAsObject(context, component, s));
+ keysList.add(convertedKey);
+ }
+
+ return new SequenceRowKey(keysList.toArray(ObjectArrays.newArray(clazz, keysList.size())));
}
public String getAsString(FacesContext context, UIComponent component, Object value) {
@@ -65,10 +54,20 @@
return "";
}
- SequenceRowKey<?> sequenceRowKey = (SequenceRowKey<?>) value;
- Object[] simpleKeys=sequenceRowKey.getSimpleKeys();
-
- return DOT_JOINER.join(simpleKeys);
+ SequenceRowKey sequenceRowKey = (SequenceRowKey) value;
+
+ StringBuilder result = new StringBuilder();
+
+ for (Object simpleKey: sequenceRowKey.getSimpleKeys()) {
+ String convertedKey = delegateConverter.getAsString(context, component, simpleKey);
+
+ if (result.length() > 0) {
+ result.append(SEPARATOR_CHAR);
+ }
+
+ result.append(convertedKey);
+ }
+
+ return result.toString();
}
-
}
Added: trunk/ui/iteration/ui/src/main/java/org/richfaces/convert/TreeConverterUtil.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/convert/TreeConverterUtil.java (rev 0)
+++ trunk/ui/iteration/ui/src/main/java/org/richfaces/convert/TreeConverterUtil.java 2010-12-02 14:47:41 UTC (rev 20310)
@@ -0,0 +1,264 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.
+ */
+package org.richfaces.convert;
+
+import java.text.MessageFormat;
+
+import javax.faces.component.UINamingContainer;
+import javax.faces.context.FacesContext;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public final class TreeConverterUtil {
+
+ private static final class SeparatorCharHolder {
+
+ static final char SEPARATOR_CHAR = UINamingContainer.getSeparatorChar(FacesContext.getCurrentInstance());
+
+ private SeparatorCharHolder() {}
+
+ }
+
+ private static final char ESCAPE_CHAR = '_';
+
+ private TreeConverterUtil() {}
+
+ private static boolean shouldEscape(char c) {
+ if ('a' <= c && c <= 'z') {
+ return false;
+ }
+
+ if ('A' <= c && c <= 'Z') {
+ return false;
+ }
+
+ if ('0' <= c && c <= '9') {
+ return false;
+ }
+
+ if (c == ESCAPE_CHAR || c == SeparatorCharHolder.SEPARATOR_CHAR) {
+ return true;
+ }
+
+ if ('-' == c || '\u00B7' == c) {
+ return false;
+ }
+
+ if ('\u00C0' <= c && c <= '\u00D6') {
+ return false;
+ }
+
+ if ('\u00D8' <= c && c <= '\u00F6') {
+ return false;
+ }
+
+ if ('\u00F8' <= c && c <= '\u02FF') {
+ return false;
+ }
+
+ if ('\u0370' <= c && c <= '\u037D') {
+ return false;
+ }
+
+ if ('\u037F' <= c && c <= '\u1FFF') {
+ return false;
+ }
+
+ if ('\u200C' <= c && c <= '\u200D') {
+ return false;
+ }
+
+ if ('\u2070' <= c && c <= '\u218F') {
+ return false;
+ }
+
+ if ('\u2C00' <= c && c <= '\u2FEF') {
+ return false;
+ }
+
+ if ('\u3001' <= c && c <= '\uD7FF') {
+ return false;
+ }
+
+ if ('\uF900' <= c && c <= '\uFDCF') {
+ return false;
+ }
+
+ if ('\uFDF0' <= c && c <= '\uFFFD') {
+ return false;
+ }
+
+ if ('\u0300' <= c && c <= '\u036F') {
+ return false;
+ }
+
+ if ('\u203F' <= c && c <= '\u2040') {
+ return false;
+ }
+
+ return true;
+ }
+
+ private static int parseHexString(String s) {
+ int result = 0;
+
+ for (int i = 0; i < s.length(); i++) {
+ result <<= 4;
+
+ char c = s.charAt(i);
+
+ int digitValue = Character.digit(c, 16);
+ if (digitValue < 0) {
+ throw new NumberFormatException();
+ }
+
+ result += digitValue;
+ }
+
+ return result;
+ }
+
+ private static void checkAvailable(String s, int idx, int len) {
+ if (s.length() < idx + len) {
+ throw new IllegalArgumentException(MessageFormat.format("Expected {0} available chars in ''{1}'' string starting from {2} index", len, s, idx));
+ }
+ }
+
+ private static char getNextChar(String s, int idx) {
+ checkAvailable(s, idx, 1);
+
+ return s.charAt(idx);
+ }
+
+ private static char readNextCharFromHexCode(String s, int idx, int len) {
+ checkAvailable(s, idx, len);
+
+ String numString = s.substring(idx, idx + len);
+ try {
+ int charValue = parseHexString(numString);
+ return (char) charValue;
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException(MessageFormat.format("Substring ''{0}'' of ''{1}'' string is not a valid hex number ", numString, s));
+ }
+ }
+
+ public static String unescape(String s) {
+ StringBuilder sb = new StringBuilder(s.length());
+
+ int startIdx = 0;
+
+ while (startIdx >= 0) {
+ int idx = s.indexOf(ESCAPE_CHAR, startIdx);
+
+ if (idx >= 0) {
+ sb.append(s.subSequence(startIdx, idx));
+
+ idx++; //skip escape char
+
+ char c = getNextChar(s, idx);
+
+ switch (c) {
+ case ESCAPE_CHAR:
+ idx++;
+ sb.append(c);
+ break;
+
+ case 'x':
+ idx++;
+ sb.append(readNextCharFromHexCode(s, idx, 2));
+ idx += 2;
+ break;
+
+ case 'u':
+ idx++;
+ sb.append(readNextCharFromHexCode(s, idx, 4));
+ idx += 4;
+ break;
+
+ default:
+ throw new IllegalArgumentException(MessageFormat.format("Unexpected char ''{0}'' in ''{1}'' string located at index {2}", c, s, idx));
+ }
+
+
+ } else {
+ sb.append(s.subSequence(startIdx, s.length()));
+ }
+
+ startIdx = idx;
+ }
+
+ return sb.toString();
+ }
+
+
+ public static String escape(String s) {
+ StringBuilder sb = new StringBuilder(s.length());
+
+ int start = 0;
+
+ char[] cs = s.toCharArray();
+ for (int idx = 0; idx < cs.length; idx++) {
+ char c = cs[idx];
+
+ if (shouldEscape(c)) {
+ sb.append(cs, start, idx - start);
+ sb.append(ESCAPE_CHAR);
+
+ if (c == ESCAPE_CHAR) {
+ sb.append(c); // ${escapeChar}
+ } else {
+ String asHex = Integer.toHexString(c);
+ switch (asHex.length()) {
+
+ case 1:
+ sb.append("x0"); // _x05
+ break;
+ case 2:
+ sb.append("x"); // _xef
+ break;
+ case 3:
+ sb.append("u0"); // _u0fed
+ break;
+ case 4:
+ sb.append("u"); // _ufcda
+ break;
+
+ default:
+ throw new IllegalArgumentException();
+ }
+
+ sb.append(asHex);
+ }
+
+ start = idx + 1;
+ }
+ }
+
+ if (start < s.length()) {
+ sb.append(cs, start, s.length() - start);
+ }
+
+ return sb.toString();
+ }
+}
Added: trunk/ui/iteration/ui/src/main/java/org/richfaces/model/ClassicTreeNodeDataModelImpl.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/model/ClassicTreeNodeDataModelImpl.java (rev 0)
+++ trunk/ui/iteration/ui/src/main/java/org/richfaces/model/ClassicTreeNodeDataModelImpl.java 2010-12-02 14:47:41 UTC (rev 20310)
@@ -0,0 +1,66 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.
+ */
+package org.richfaces.model;
+
+import java.util.Iterator;
+
+import javax.faces.convert.Converter;
+
+import org.richfaces.convert.ObjectSequenceRowKeyConverter;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class ClassicTreeNodeDataModelImpl extends TreeSequenceKeyModel<TreeNode> {
+
+ private static final Converter DEFAULT_CONVERTER = new ObjectSequenceRowKeyConverter();
+
+ private TreeNode rootNode;
+
+ public boolean isLeaf() {
+ return getData().isLeaf();
+ }
+
+ public Iterator<TreeDataModelTuple> children() {
+ return new ClassicTreeNodeTuplesIterator(getData(), getRowKey());
+ }
+
+ @Override
+ protected TreeNode setupChildContext(Object segment) {
+ return getData().getChild(segment);
+ }
+
+ @Override
+ public Object getWrappedData() {
+ return rootNode;
+ }
+
+ @Override
+ public void setWrappedData(Object data) {
+ this.rootNode = (TreeNode) data;
+ }
+
+ public Converter getRowKeyConverter() {
+ return DEFAULT_CONVERTER;
+ }
+}
Added: trunk/ui/iteration/ui/src/main/java/org/richfaces/model/ClassicTreeNodeTuplesIterator.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/model/ClassicTreeNodeTuplesIterator.java (rev 0)
+++ trunk/ui/iteration/ui/src/main/java/org/richfaces/model/ClassicTreeNodeTuplesIterator.java 2010-12-02 14:47:41 UTC (rev 20310)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.
+ */
+package org.richfaces.model;
+
+import java.util.Iterator;
+
+import com.google.common.collect.UnmodifiableIterator;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+final class ClassicTreeNodeTuplesIterator extends UnmodifiableIterator<TreeDataModelTuple> {
+
+ private TreeNode treeNode;
+
+ private SequenceRowKey baseKey;
+
+ private Iterator<Object> childrenKeysIterator = null;
+
+ public ClassicTreeNodeTuplesIterator(TreeNode treeNode, SequenceRowKey baseKey) {
+ super();
+ this.treeNode = treeNode;
+ this.baseKey = baseKey;
+ this.childrenKeysIterator = treeNode.getChildrenKeysIterator();
+ }
+
+ public boolean hasNext() {
+ return childrenKeysIterator.hasNext();
+ }
+
+ public TreeDataModelTuple next() {
+ Object nextChildKey = childrenKeysIterator.next();
+ Object rowKey = (baseKey != null ? baseKey.append(nextChildKey) : new SequenceRowKey(nextChildKey));
+
+ return new TreeDataModelTuple(rowKey, treeNode.getChild(nextChildKey));
+ }
+
+}
Modified: trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeModelKey.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeModelKey.java 2010-12-02 14:32:03 UTC (rev 20309)
+++ trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeModelKey.java 2010-12-02 14:47:41 UTC (rev 20310)
@@ -23,6 +23,8 @@
import java.io.Serializable;
+import com.google.common.base.Objects;
+
/**
* @author Nick Belaevski
*
@@ -89,6 +91,6 @@
@Override
public String toString() {
- return getModelId() + "." + getModelKey();
+ return Objects.toStringHelper(this).add("modelId", getModelId()).add("modelKey", getModelKey()).toString();
}
}
Modified: trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeTreeDataModelCompositeTuplesIterator.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeTreeDataModelCompositeTuplesIterator.java 2010-12-02 14:32:03 UTC (rev 20309)
+++ trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeTreeDataModelCompositeTuplesIterator.java 2010-12-02 14:47:41 UTC (rev 20310)
@@ -40,11 +40,11 @@
private UIComponent component;
- private SequenceRowKey<DeclarativeModelKey> key;
+ private SequenceRowKey key;
private Iterator<TreeDataModelTuple> iterator;
- public DeclarativeTreeDataModelCompositeTuplesIterator(UIComponent component, SequenceRowKey<DeclarativeModelKey> key) {
+ public DeclarativeTreeDataModelCompositeTuplesIterator(UIComponent component, SequenceRowKey key) {
super();
this.component = component;
this.key = key;
Modified: trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeTreeDataModelImpl.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeTreeDataModelImpl.java 2010-12-02 14:32:03 UTC (rev 20309)
+++ trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeTreeDataModelImpl.java 2010-12-02 14:47:41 UTC (rev 20310)
@@ -21,17 +21,17 @@
*/
package org.richfaces.model;
-import static com.google.common.base.Objects.firstNonNull;
-
import java.util.Iterator;
import java.util.Map;
import javax.faces.component.UIComponent;
+import javax.faces.convert.Converter;
import org.richfaces.component.AbstractTree;
import org.richfaces.component.ComponentPredicates;
import org.richfaces.component.TreeModelAdaptor;
import org.richfaces.component.TreeModelRecursiveAdaptor;
+import org.richfaces.convert.DeclarativeModelKeySequenceRowKeyConverter;
import org.richfaces.log.Logger;
import org.richfaces.log.RichfacesLogger;
@@ -42,11 +42,11 @@
* @author Nick Belaevski
*
*/
-public class DeclarativeTreeDataModelImpl extends TreeSequenceKeyModel<DeclarativeModelKey, Object> implements DeclarativeTreeModel<Object> {
+public class DeclarativeTreeDataModelImpl extends TreeSequenceKeyModel<Object> implements DeclarativeTreeModel<Object> {
private static final Logger LOGGER = RichfacesLogger.MODEL.getLogger();
- private static final SequenceRowKey<DeclarativeModelKey> EMPTY_KEY = new SequenceRowKey<DeclarativeModelKey>();
+ private static final Converter DEFAULT_CONVERTER = new DeclarativeModelKeySequenceRowKeyConverter();
private String var;
@@ -57,7 +57,6 @@
private UIComponent currentComponent;
public DeclarativeTreeDataModelImpl(AbstractTree tree, String var, Map<String, Object> contextMap) {
- super();
this.tree = tree;
this.currentComponent = tree;
this.var = var;
@@ -82,13 +81,9 @@
}
public Iterator<TreeDataModelTuple> children() {
- return new DeclarativeTreeDataModelCompositeTuplesIterator(currentComponent, safeGetRowKey());
+ return new DeclarativeTreeDataModelCompositeTuplesIterator(currentComponent, getRowKey());
}
- public Object getParentRowKey(Object rowKey) {
- return safeGetRowKey().getParent();
- }
-
@Override
public Object getWrappedData() {
throw new UnsupportedOperationException();
@@ -100,7 +95,7 @@
}
@Override
- protected void walkKey(SequenceRowKey<DeclarativeModelKey> key) {
+ protected void setupKey(SequenceRowKey key) {
Object initialContextValue = null;
if (var != null) {
@@ -110,7 +105,7 @@
try {
this.currentComponent = tree;
- super.walkKey(key);
+ super.setupKey(key);
} finally {
if (var != null) {
try {
@@ -121,24 +116,29 @@
}
}
}
-
+
@Override
- protected void walkNext(DeclarativeModelKey segment) {
+ protected Object setupChildContext(Object keyObject) {
+ DeclarativeModelKey segment = (DeclarativeModelKey) keyObject;
+ if (var != null) {
+ contextMap.put(var, getData());
+ }
+
String modelId = segment.getModelId();
-
+
UIComponent modelComponent;
-
+
if (currentComponent instanceof TreeModelRecursiveAdaptor && modelId.equals(currentComponent.getId())) {
modelComponent = currentComponent;
} else {
modelComponent = Iterables.find(currentComponent.getChildren(), ComponentPredicates.withId(modelId));
}
-
+
Object nodes = null;
-
+
if (modelComponent instanceof TreeModelRecursiveAdaptor) {
TreeModelRecursiveAdaptor recursiveAdaptor = (TreeModelRecursiveAdaptor) modelComponent;
-
+
if (currentComponent.equals(modelComponent)) {
nodes = recursiveAdaptor.getNodes();
} else {
@@ -147,20 +147,13 @@
} else {
nodes = ((TreeModelAdaptor) modelComponent).getNodes();
}
-
+
Object data = Iterables.get((Iterable<?>) nodes, (Integer) segment.getModelKey());
- setRowKeyAndData(safeGetRowKey().append(segment), data);
this.currentComponent = modelComponent;
-
- if (var != null) {
- contextMap.put(var, data);
- }
+
+ return data;
}
-
- private SequenceRowKey<DeclarativeModelKey> safeGetRowKey() {
- return firstNonNull(getRowKey(), EMPTY_KEY);
- }
-
+
public TreeDataModelTuple createSnapshot() {
return new DeclarativeTreeDataModelTuple(getRowKey(), getData(), getCurrentComponent());
}
@@ -172,4 +165,7 @@
this.currentComponent = declarativeModelTuple.getComponent();
}
+ public Converter getRowKeyConverter() {
+ return DEFAULT_CONVERTER;
+ }
}
Modified: trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeTreeDataModelTuplesIterator.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeTreeDataModelTuplesIterator.java 2010-12-02 14:32:03 UTC (rev 20309)
+++ trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeTreeDataModelTuplesIterator.java 2010-12-02 14:47:41 UTC (rev 20310)
@@ -25,17 +25,19 @@
import javax.faces.component.UIComponent;
-final class DeclarativeTreeDataModelTuplesIterator implements Iterator<TreeDataModelTuple> {
+import com.google.common.collect.UnmodifiableIterator;
+
+final class DeclarativeTreeDataModelTuplesIterator extends UnmodifiableIterator<TreeDataModelTuple> {
private UIComponent component;
- private SequenceRowKey<DeclarativeModelKey> baseKey;
+ private SequenceRowKey baseKey;
private int counter = 0;
private Iterator<?> dataIterator;
- public DeclarativeTreeDataModelTuplesIterator(UIComponent component, SequenceRowKey<DeclarativeModelKey> baseKey, Iterator<?> dataIterator) {
+ public DeclarativeTreeDataModelTuplesIterator(UIComponent component, SequenceRowKey baseKey, Iterator<?> dataIterator) {
super();
this.component = component;
this.baseKey = baseKey;
@@ -46,7 +48,7 @@
Object nextNode = dataIterator.next();
DeclarativeModelKey key = new DeclarativeModelKey(component.getId(), counter++);
- SequenceRowKey<DeclarativeModelKey> newKey = baseKey.append(key);
+ SequenceRowKey newKey = (baseKey != null ? baseKey.append(key) : new SequenceRowKey(key));
return new DeclarativeTreeDataModelTuple(newKey, nextNode, component);
}
@@ -55,8 +57,4 @@
return dataIterator.hasNext();
}
- public void remove() {
- throw new UnsupportedOperationException();
- }
-
}
\ No newline at end of file
Modified: trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SequenceRowKey.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SequenceRowKey.java 2010-12-02 14:32:03 UTC (rev 20309)
+++ trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SequenceRowKey.java 2010-12-02 14:47:41 UTC (rev 20310)
@@ -30,41 +30,33 @@
* @author Nick Belaevski
*
*/
-public class SequenceRowKey<T> implements Serializable {
+public class SequenceRowKey implements Serializable {
private static final long serialVersionUID = 5605581090240141910L;
- private T[] simpleKeys;
+ private Object[] simpleKeys;
- public SequenceRowKey(T... keys) {
+ public SequenceRowKey(Object... keys) {
super();
this.simpleKeys = keys;
}
- public T[] getSimpleKeys() {
+ public Object[] getSimpleKeys() {
return simpleKeys;
}
- public SequenceRowKey<T> append(T segment) {
- return new SequenceRowKey<T>(ObjectArrays.concat(simpleKeys, segment));
+ public SequenceRowKey append(Object segment) {
+ return new SequenceRowKey(ObjectArrays.concat(simpleKeys, segment));
}
- public T getLastKeySegment() {
+ public SequenceRowKey getParent() {
if (simpleKeys.length == 0) {
return null;
}
- return simpleKeys[simpleKeys.length - 1];
- }
-
- public SequenceRowKey<T> getParent() {
- if (simpleKeys.length == 0) {
- return null;
- }
-
- T[] parentSimpleKeys = ObjectArrays.newArray(simpleKeys, simpleKeys.length - 1);
+ Object[] parentSimpleKeys = ObjectArrays.newArray(simpleKeys, simpleKeys.length - 1);
System.arraycopy(simpleKeys, 0, parentSimpleKeys, 0, parentSimpleKeys.length);
- return new SequenceRowKey<T>(parentSimpleKeys);
+ return new SequenceRowKey(parentSimpleKeys);
}
@Override
@@ -86,7 +78,7 @@
if (getClass() != obj.getClass()) {
return false;
}
- SequenceRowKey<?> other = (SequenceRowKey<?>) obj;
+ SequenceRowKey other = (SequenceRowKey) obj;
if (!Arrays.equals(simpleKeys, other.simpleKeys)) {
return false;
}
@@ -97,4 +89,5 @@
public String toString() {
return getClass().getName() + Arrays.toString(simpleKeys);
}
-}
+
+}
\ No newline at end of file
Modified: trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SwingTreeNodeDataModelImpl.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SwingTreeNodeDataModelImpl.java 2010-12-02 14:32:03 UTC (rev 20309)
+++ trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SwingTreeNodeDataModelImpl.java 2010-12-02 14:47:41 UTC (rev 20310)
@@ -21,23 +21,24 @@
*/
package org.richfaces.model;
-import static com.google.common.base.Objects.firstNonNull;
-
import java.util.Collection;
import java.util.Enumeration;
import java.util.Iterator;
+import javax.faces.convert.Converter;
import javax.swing.tree.TreeNode;
+import org.richfaces.convert.IntegerSequenceRowKeyConverter;
+
import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
/**
* @author Nick Belaevski
*
*/
-public class SwingTreeNodeDataModelImpl extends TreeSequenceKeyModel<Integer, TreeNode> {
+public class SwingTreeNodeDataModelImpl extends TreeSequenceKeyModel<TreeNode> {
- private static final SequenceRowKey<Integer> EMPTY_KEY = new SequenceRowKey<Integer>();
+ private static final Converter DEFAULT_CONVERTER = new IntegerSequenceRowKeyConverter();
private boolean asksAllowsChildren = false;
@@ -61,10 +62,6 @@
return treeNodeImpl;
}
- public Object getParentRowKey(Object rowKey) {
- throw new UnsupportedOperationException();
- }
-
public void setWrappedData(Object data) {
this.wrappedData = data;
@@ -93,14 +90,11 @@
}
@Override
- protected void walkNext(Integer segment) {
- TreeNode child = findChild(getData(), segment);
- //TODO what if node is missing?
- //TODO - optimize - remove partial keys creation
- setRowKeyAndData(safeGetRowKey().append(segment), child);
+ protected TreeNode setupChildContext(Object segment) {
+ return findChild(getData(), (Integer) segment);
}
-
- private SequenceRowKey<Integer> safeGetRowKey() {
- return firstNonNull(getRowKey(), EMPTY_KEY);
+
+ public Converter getRowKeyConverter() {
+ return DEFAULT_CONVERTER;
}
}
\ No newline at end of file
Modified: trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SwingTreeNodeTuplesIterator.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SwingTreeNodeTuplesIterator.java 2010-12-02 14:32:03 UTC (rev 20309)
+++ trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SwingTreeNodeTuplesIterator.java 2010-12-02 14:47:41 UTC (rev 20310)
@@ -25,15 +25,17 @@
import javax.swing.tree.TreeNode;
-final class SwingTreeNodeTuplesIterator implements Iterator<TreeDataModelTuple> {
+import com.google.common.collect.UnmodifiableIterator;
- private SequenceRowKey<Integer> baseKey;
+final class SwingTreeNodeTuplesIterator extends UnmodifiableIterator<TreeDataModelTuple> {
+
+ private SequenceRowKey baseKey;
private Iterator<TreeNode> children;
private int counter = 0;
- SwingTreeNodeTuplesIterator(SequenceRowKey<Integer> baseKey, Iterator<TreeNode> children) {
+ SwingTreeNodeTuplesIterator(SequenceRowKey baseKey, Iterator<TreeNode> children) {
this.baseKey = baseKey;
this.children = children;
}
@@ -49,19 +51,15 @@
public TreeDataModelTuple next() {
TreeNode node = children.next();
- SequenceRowKey<Integer> key;
+ SequenceRowKey key;
if (baseKey != null) {
key = baseKey.append(getNextCounterValue());
} else {
- key = new SequenceRowKey<Integer>(getNextCounterValue());
+ key = new SequenceRowKey(getNextCounterValue());
}
return new TreeDataModelTuple(key, node);
}
- public void remove() {
- throw new UnsupportedOperationException();
- }
-
}
\ No newline at end of file
Modified: trunk/ui/iteration/ui/src/main/java/org/richfaces/model/TreeSequenceKeyModel.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/model/TreeSequenceKeyModel.java 2010-12-02 14:32:03 UTC (rev 20309)
+++ trunk/ui/iteration/ui/src/main/java/org/richfaces/model/TreeSequenceKeyModel.java 2010-12-02 14:47:41 UTC (rev 20310)
@@ -32,29 +32,35 @@
* @author Nick Belaevski
*
*/
-public abstract class TreeSequenceKeyModel<K, V> extends ExtendedDataModel<V> implements TreeDataModel<V> {
+public abstract class TreeSequenceKeyModel<V> extends ExtendedDataModel<V> implements TreeDataModel<V> {
private V rootNode;
private V data;
- private SequenceRowKey<K> rowKey;
+ private SequenceRowKey rowKey;
- public SequenceRowKey<K> getRowKey() {
+ public SequenceRowKey getRowKey() {
return rowKey;
}
public void setRowKey(Object rowKey) {
+ SequenceRowKey sequenceKey = (SequenceRowKey) rowKey;
+
if (this.rowKey == null || !this.rowKey.equals(rowKey)) {
- walkKey((SequenceRowKey<K>) rowKey);
+ setupKey(sequenceKey);
}
}
-
+
protected void resetRowKeyAndData() {
setRowKeyAndData(null, rootNode);
}
- protected void setRowKeyAndData(SequenceRowKey<K> key, V data) {
+ protected void setData(V data) {
+ this.data = data;
+ }
+
+ protected void setRowKeyAndData(SequenceRowKey key, V data) {
this.rowKey = key;
this.data = data;
}
@@ -71,17 +77,22 @@
return data;
}
- protected void walkKey(SequenceRowKey<K> key) {
+ protected void setupKey(SequenceRowKey key) {
resetRowKeyAndData();
if (key != null) {
- for (K simpleKey: key.getSimpleKeys()) {
- walkNext(simpleKey);
+ V data = getRootNode();
+
+ for (Object simpleKey: key.getSimpleKeys()) {
+ data = setupChildContext(simpleKey);
+ setData(data);
}
+
+ setRowKeyAndData(key, data);
}
}
- protected abstract void walkNext(K segment);
+ protected abstract V setupChildContext(Object segment);
protected V getRootNode() {
return rootNode;
@@ -132,6 +143,16 @@
}
public void restoreFromSnapshot(TreeDataModelTuple tuple) {
- setRowKeyAndData((SequenceRowKey<K>) tuple.getRowKey(), (V) tuple.getData());
+ setRowKeyAndData((SequenceRowKey) tuple.getRowKey(), (V) tuple.getData());
}
+
+ public Object getParentRowKey(Object rowKey) {
+ SequenceRowKey key = getRowKey();
+
+ if (key == null) {
+ return null;
+ }
+
+ return key.getParent();
+ }
}
Added: trunk/ui/iteration/ui/src/test/java/org/richfaces/convert/TreeConverterUtilTest.java
===================================================================
--- trunk/ui/iteration/ui/src/test/java/org/richfaces/convert/TreeConverterUtilTest.java (rev 0)
+++ trunk/ui/iteration/ui/src/test/java/org/richfaces/convert/TreeConverterUtilTest.java 2010-12-02 14:47:41 UTC (rev 20310)
@@ -0,0 +1,194 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.
+ */
+package org.richfaces.convert;
+
+import static org.easymock.EasyMock.expect;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+import static org.richfaces.convert.TreeConverterUtil.escape;
+import static org.richfaces.convert.TreeConverterUtil.unescape;
+
+import java.util.HashMap;
+
+import javax.faces.context.FacesContext;
+
+import org.jboss.test.faces.mock.Environment;
+import org.jboss.test.faces.mock.Mock;
+import org.jboss.test.faces.mock.MockFacesEnvironment;
+import org.jboss.test.faces.mock.MockTestRunner;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+(a)RunWith(MockTestRunner.class)
+public class TreeConverterUtilTest {
+
+ @Mock
+ private FacesContext context;
+
+ @Mock
+ @Environment({Environment.Feature.EXTERNAL_CONTEXT})
+ private MockFacesEnvironment environment;
+
+ @Before
+ public void setUp() throws Exception {
+ environment.resetToNice();
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ expect(facesContext.getAttributes()).andStubReturn(new HashMap<Object, Object>());
+ environment.replay();
+ }
+
+ @Test
+ public void testUnescape() throws Exception {
+ assertEquals("", unescape(""));
+ assertEquals("a", unescape("a"));
+ assertEquals("abc", unescape("abc"));
+
+
+ assertEquals("_", unescape("__"));
+ assertEquals("__", unescape("____"));
+
+ assertEquals("_a", unescape("__a"));
+ assertEquals("_abc", unescape("__abc"));
+
+ assertEquals("a_", unescape("a__"));
+ assertEquals("abc_", unescape("abc__"));
+
+ assertEquals("some_test", unescape("some__test"));
+
+ assertEquals("\u0000", unescape("_x00"));
+ assertEquals("\u0001", unescape("_x01"));
+ assertEquals("\u0010", unescape("_x10"));
+ assertEquals("\u0077", unescape("_x77"));
+ assertEquals("\u00A9", unescape("_xa9"));
+ assertEquals("\u00FF", unescape("_xFF"));
+ assertEquals("\u00FF", unescape("_xff"));
+
+ assertEquals(".", unescape("_x2e"));
+
+ assertEquals("\u0000", unescape("_u0000"));
+ assertEquals("\u0001", unescape("_u0001"));
+ assertEquals("\uE1A4", unescape("_ue1a4"));
+ assertEquals("\uF000", unescape("_uF000"));
+ assertEquals("\uFFFF", unescape("_uFFFF"));
+
+
+ assertEquals(".", unescape("_u002E"));
+
+ assertEquals("Embedded_underscores\u0312unicode\u0045etc", unescape("Embedded__underscores_u0312unicode_x45etc"));
+
+ try {
+ unescape("_");
+
+ fail();
+ } catch (IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ }
+
+ try {
+ unescape("some _a string");
+
+ fail();
+ } catch (IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ }
+
+ try {
+ unescape("_x");
+
+ fail();
+ } catch (IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ }
+
+ try {
+ unescape("_x0");
+
+ fail();
+ } catch (IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ }
+
+ try {
+ unescape("_u");
+
+ fail();
+ } catch (IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ }
+
+ try {
+ unescape("_u-1aaa");
+
+ fail();
+ } catch (IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ }
+
+ try {
+ unescape("_u1zaa");
+
+ fail();
+ } catch (IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ }
+
+ try {
+ unescape("embedded _x 00 into string");
+
+ fail();
+ } catch (IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ }
+
+ try {
+ unescape("embedded _x0 into string");
+
+ fail();
+ } catch (IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ }
+
+ try {
+ unescape("embedded _u012 into string");
+
+ fail();
+ } catch (IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ }
+ }
+
+ @Test
+ public void testEscape() throws Exception {
+ assertEquals("", escape(""));
+ assertEquals("__a__b__", escape("_a_b_"));
+ assertEquals("_x3a0_x3a1", escape(":0:1"));
+ assertEquals("testTEST05", escape("testTEST05"));
+ assertEquals("a_xa9c", escape("a\u00a9c"));
+ assertEquals("a_u037ec", escape("a\u037ec"));
+ assertEquals("a_ue1acd", escape("a\ue1acd"));
+ }
+}
13 years, 5 months
JBoss Rich Faces SVN: r20309 - in trunk/ui: iteration/ui/src/main/java/org/richfaces/component and 2 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2010-12-02 09:32:03 -0500 (Thu, 02 Dec 2010)
New Revision: 20309
Added:
trunk/ui/common/ui/src/main/java/org/richfaces/component/UIDataAdaptor.java.orig
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTree.java.orig
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SwingTreeNodeDataModelImpl.java.orig
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/TreeSequenceKeyModel.java.orig
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeEncoderBase.java.orig
Log:
RF-9680
Added: trunk/ui/common/ui/src/main/java/org/richfaces/component/UIDataAdaptor.java.orig
===================================================================
--- trunk/ui/common/ui/src/main/java/org/richfaces/component/UIDataAdaptor.java.orig (rev 0)
+++ trunk/ui/common/ui/src/main/java/org/richfaces/component/UIDataAdaptor.java.orig 2010-12-02 14:32:03 UTC (rev 20309)
@@ -0,0 +1,1523 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, 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.
+ */
+
+package org.richfaces.component;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.text.MessageFormat;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.el.ValueExpression;
+import javax.faces.FacesException;
+import javax.faces.application.Application;
+import javax.faces.application.FacesMessage;
+import javax.faces.component.ContextCallback;
+import javax.faces.component.EditableValueHolder;
+import javax.faces.component.NamingContainer;
+import javax.faces.component.PartialStateHolder;
+import javax.faces.component.StateHelper;
+import javax.faces.component.StateHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIComponentBase;
+import javax.faces.component.UIForm;
+import javax.faces.component.UINamingContainer;
+import javax.faces.component.UIViewRoot;
+import javax.faces.component.UniqueIdVendor;
+import javax.faces.component.visit.VisitCallback;
+import javax.faces.component.visit.VisitContext;
+import javax.faces.component.visit.VisitResult;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.convert.ConverterException;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.ComponentSystemEvent;
+import javax.faces.event.ComponentSystemEventListener;
+import javax.faces.event.FacesEvent;
+import javax.faces.event.ListenerFor;
+import javax.faces.event.PhaseId;
+import javax.faces.event.PostValidateEvent;
+import javax.faces.event.PreRenderComponentEvent;
+import javax.faces.event.PreValidateEvent;
+import javax.faces.render.Renderer;
+
+import org.ajax4jsf.component.IterationStateHolder;
+import org.ajax4jsf.model.DataComponentState;
+import org.ajax4jsf.model.DataVisitResult;
+import org.ajax4jsf.model.DataVisitor;
+import org.ajax4jsf.model.ExtendedDataModel;
+import org.ajax4jsf.model.Range;
+import org.ajax4jsf.model.SerializableDataModel;
+import org.richfaces.context.ExtendedVisitContext;
+import org.richfaces.log.Logger;
+import org.richfaces.log.RichfacesLogger;
+
+/**
+ * Base class for iterable components, like dataTable, Tomahawk dataList, Facelets repeat, tree etc., with support for
+ * partial rendering on AJAX responces for one or more selected iterations.
+ *
+ * @author shura
+ */
+@ListenerFor(systemEventClass = PreRenderComponentEvent.class)
+public abstract class UIDataAdaptor extends UIComponentBase implements NamingContainer,
+ UniqueIdVendor, IterationStateHolder, ComponentSystemEventListener {
+
+ /**
+ * <p>The standard component family for this component.</p>
+ */
+ public static final String COMPONENT_FAMILY = "org.richfaces.Data";
+
+ /**
+ * <p>The standard component type for this component.</p>
+ */
+ public static final String COMPONENT_TYPE = "org.richfaces.Data";
+
+ private static final class IterationState implements Serializable {
+
+ private static final long serialVersionUID = -3502645160277416066L;
+
+ private DataComponentState componentState;
+
+ private Object savedComponentState;
+
+ private boolean componentStateIsStateHolder;
+
+ private ExtendedDataModel<?> dataModel;
+
+ public IterationState() {
+ super();
+ }
+
+ public IterationState(DataComponentState componentState, ExtendedDataModel<?> dataModel) {
+ super();
+ this.componentState = componentState;
+ this.dataModel = dataModel;
+ }
+
+ public ExtendedDataModel<?> getDataModel() {
+ return dataModel;
+ }
+
+ public DataComponentState getComponentState() {
+ return componentState;
+ }
+
+ /**
+ * @param uiDataAdaptor
+ */
+ public void restoreComponentState(UIDataAdaptor uiDataAdaptor) {
+ if (savedComponentState != null && componentStateIsStateHolder) {
+ componentState = uiDataAdaptor.createComponentState();
+ ((StateHolder) componentState).restoreState(FacesContext.getCurrentInstance(), savedComponentState);
+ savedComponentState = null;
+ }
+ }
+
+ final Object saveState() {
+ boolean localComponentStateIsHolder = false;
+ Object localSavedComponentState = null;
+
+ if (componentState != null) {
+ if (componentState instanceof StateHolder) {
+ localComponentStateIsHolder = true;
+
+ StateHolder stateHolder = (StateHolder) componentState;
+ if (!stateHolder.isTransient()) {
+ localSavedComponentState = stateHolder.saveState(FacesContext.getCurrentInstance());
+ }
+ } else {
+ if (componentState instanceof Serializable) {
+ localSavedComponentState = componentState;
+ }
+ }
+ }
+
+ Object savedSerializableModel = null;
+
+ if (componentState != null && dataModel != null) {
+ // TODO handle model serialization - "execute" model
+ savedSerializableModel = dataModel.getSerializableModel(componentState.getRange());
+ }
+
+ if (localSavedComponentState != null || savedSerializableModel != null) {
+ return new Object[] {
+ localComponentStateIsHolder,
+ localSavedComponentState,
+ savedSerializableModel
+ };
+ } else {
+ return null;
+ }
+ }
+
+ final void restoreState(Object stateObject) {
+ if (stateObject != null) {
+ Object[] state = (Object[]) stateObject;
+ componentStateIsStateHolder = Boolean.TRUE.equals(state[0]);
+ Object localSavedComponentState = state[1];
+
+ if (componentStateIsStateHolder) {
+ savedComponentState = localSavedComponentState;
+ } else {
+ componentState = (DataComponentState) localSavedComponentState;
+ }
+
+ dataModel = (ExtendedDataModel<?>) state[2];
+ }
+ }
+
+ private void writeObject(java.io.ObjectOutputStream out)
+ throws IOException {
+
+ out.writeObject(saveState());
+ }
+
+ private void readObject(java.io.ObjectInputStream in)
+ throws IOException, ClassNotFoundException {
+
+ restoreState(in.readObject());
+ }
+ }
+
+ private static final VisitCallback STUB_CALLBACK = new VisitCallback() {
+
+ public VisitResult visit(VisitContext context, UIComponent target) {
+ return VisitResult.ACCEPT;
+ }
+ };
+
+ private static final Logger LOG = RichfacesLogger.COMPONENTS.getLogger();
+
+ /**
+ * Visitor for process decode on children components.
+ */
+ protected ComponentVisitor decodeVisitor = new ComponentVisitor() {
+ @Override
+ public void processComponent(FacesContext context, UIComponent c, Object argument) {
+ c.processDecodes(context);
+ }
+ };
+
+ /**
+ * Visitor for process validation phase
+ */
+ protected ComponentVisitor validateVisitor = new ComponentVisitor() {
+ @Override
+ public void processComponent(FacesContext context, UIComponent c, Object argument) {
+ c.processValidators(context);
+ }
+ };
+
+ /**
+ * Visitor for process update model phase.
+ */
+ protected ComponentVisitor updateVisitor = new ComponentVisitor() {
+ @Override
+ public void processComponent(FacesContext context, UIComponent c, Object argument) {
+ c.processUpdates(context);
+ }
+ };
+
+ //TODO nick - PSH support?
+ private DataComponentState componentState = null;
+ private ExtendedDataModel<?> extendedDataModel = null;
+
+ private Object rowKey = null;
+
+ private boolean rowDataIsSet = false;
+
+ private Object rowData;
+
+ private String clientId;
+
+ private Object originalVarValue;
+
+ private Converter rowKeyConverter;
+
+ /**
+ * @author Nick Belaevski
+ *
+ */
+ private final class DataVisitorForVisitTree implements DataVisitor {
+ /**
+ *
+ */
+ private final VisitCallback callback;
+ /**
+ *
+ */
+ private final VisitContext visitContext;
+ /**
+ *
+ */
+ private boolean visitResult;
+
+ /**
+ * @param callback
+ * @param visitContext
+ */
+ private DataVisitorForVisitTree(VisitCallback callback, VisitContext visitContext) {
+ this.callback = callback;
+ this.visitContext = visitContext;
+ }
+
+ public DataVisitResult process(FacesContext context, Object rowKey, Object argument) {
+ setRowKey(context, rowKey);
+
+ if (isRowAvailable()) {
+ VisitResult result = VisitResult.ACCEPT;
+
+ if (visitContext instanceof ExtendedVisitContext) {
+ result = visitContext.invokeVisitCallback(UIDataAdaptor.this, callback);
+ if (VisitResult.COMPLETE.equals(result)) {
+ visitResult = true;
+
+ return DataVisitResult.STOP;
+ }
+
+ if (result == VisitResult.ACCEPT) {
+ result = visitDataChildrenMetaComponents((ExtendedVisitContext) visitContext, callback);
+ if (VisitResult.COMPLETE.equals(result)) {
+ visitResult = true;
+
+ return DataVisitResult.STOP;
+ }
+ }
+ }
+
+ if (VisitResult.ACCEPT.equals(result)) {
+ Iterator<UIComponent> dataChildrenItr = dataChildren();
+
+ while (dataChildrenItr.hasNext()) {
+ UIComponent dataChild = dataChildrenItr.next();
+
+ if (dataChild.visitTree(visitContext, callback)) {
+ visitResult = true;
+
+ return DataVisitResult.STOP;
+ }
+ }
+ }
+ }
+
+ return DataVisitResult.CONTINUE;
+ }
+
+ public boolean getVisitResult() {
+ return visitResult;
+ }
+ }
+
+ private enum PropertyKeys {
+ lastId, var, rowKeyVar, stateVar, childState, rowKeyConverter, rowKeyConverterSet, keepSaved
+ }
+
+ public UIDataAdaptor() {
+ super();
+ }
+
+ protected Map<String, Object> getVariablesMap(FacesContext facesContext) {
+ return facesContext.getExternalContext().getRequestMap();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see javax.faces.component.UIComponent#getFamily()
+ */
+ @Override
+ public String getFamily() {
+ return COMPONENT_FAMILY;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see javax.faces.component.UniqueIdVendor#createUniqueId(javax.faces.context.FacesContext, java.lang.String)
+ */
+ public String createUniqueId(FacesContext context, String seed) {
+ Integer i = (Integer) getStateHelper().get(PropertyKeys.lastId);
+ int lastId = (i != null) ? i : 0;
+
+ getStateHelper().put(PropertyKeys.lastId, ++lastId);
+
+ return UIViewRoot.UNIQUE_ID_PREFIX + ((seed == null) ? lastId : seed);
+ }
+
+ /**
+ * @return the rowKey
+ */
+ public Object getRowKey() {
+ return rowKey;
+ }
+
+ private void setRowKeyAndData(FacesContext facesContext, Object rowKey, boolean localRowDataAvailable, Object localRowData) {
+ this.saveChildState(facesContext);
+
+ this.rowKey = rowKey;
+
+ if (localRowDataAvailable) {
+ this.rowData = localRowData;
+ this.rowDataIsSet = (rowKey != null);
+ } else {
+ this.rowData = null;
+ this.rowDataIsSet = false;
+
+ getExtendedDataModel().setRowKey(rowKey);
+ }
+
+ this.clientId = null;
+
+ boolean rowSelected = (rowKey != null) && isRowAvailable();
+
+ setupVariable(facesContext, rowSelected);
+
+ this.restoreChildState(facesContext);
+ }
+
+ protected void setRowKeyAndData(FacesContext facesContext, Object rowKey, Object localRowData) {
+ setRowKeyAndData(facesContext, rowKey, true, localRowData);
+ }
+
+ /**
+ * Setup current row by key. Perform same functionality as
+ * {@link javax.faces.component.UIData#setRowIndex(int)}, but for key object - it may be not only
+ * row number in sequence data, but, for example - path to current node in
+ * tree.
+ *
+ * @param faces -
+ * current FacesContext
+ * @param key new key value.
+ */
+ public void setRowKey(FacesContext facesContext, Object rowKey) {
+<<<<<<< HEAD
+ this.saveChildState(facesContext);
+
+ this.rowKey = rowKey;
+
+ getExtendedDataModel().setRowKey(rowKey);
+
+ this.clientId = null;
+
+ boolean rowSelected = (rowKey != null) && isRowAvailable();
+
+ setupVariable(facesContext, rowSelected);
+
+ this.restoreChildState(facesContext);
+=======
+ setRowKeyAndData(facesContext, rowKey, false, null);
+>>>>>>> RF-9680:
+ }
+
+ /**
+ * Save values of {@link EditableValueHolder} fields before change current
+ * row.
+ *
+ * @param faces
+ */
+ protected void saveChildState(FacesContext facesContext) {
+ Iterator<UIComponent> itr = dataChildren();
+
+ while (itr.hasNext()) {
+ this.saveChildState(facesContext, (UIComponent) itr.next());
+ }
+ }
+
+ /**
+ * @param facesContext
+ * @param next
+ * @param childState
+ */
+ protected void saveChildState(FacesContext facesContext, UIComponent component) {
+
+ // TODO - is it right?
+ if (component.isTransient()) {
+ return;
+ }
+
+ SavedState state = null;
+
+ if (component instanceof IterationStateHolder) {
+ IterationStateHolder ish = (IterationStateHolder) component;
+
+ state = new SavedState(ish);
+ } else if (component instanceof EditableValueHolder) {
+ EditableValueHolder evh = (EditableValueHolder) component;
+
+ state = new SavedState(evh);
+ } else if (component instanceof UIForm) {
+ UIForm form = (UIForm) component;
+
+ state = new SavedState(form);
+ }
+
+ if (state != null) {
+
+ // TODO - use local map - children save their state themselves using visitors
+ getStateHelper().put(PropertyKeys.childState, component.getClientId(facesContext), state);
+ }
+
+ if (component.getChildCount() > 0) {
+ for (UIComponent child : component.getChildren()) {
+ saveChildState(facesContext, child);
+ }
+ }
+
+ if (component.getFacetCount() > 0) {
+ for (UIComponent facet : component.getFacets().values()) {
+ saveChildState(facesContext, facet);
+ }
+ }
+ }
+
+ protected Iterator<UIComponent> dataChildren() {
+ if (getChildCount() > 0) {
+ return getChildren().iterator();
+ } else {
+ return Collections.<UIComponent>emptyList().iterator();
+ }
+ }
+
+ protected Iterator<UIComponent> fixedChildren() {
+ if (getFacetCount() > 0) {
+ return getFacets().values().iterator();
+ } else {
+ return Collections.<UIComponent>emptyList().iterator();
+ }
+ }
+
+ /**
+ * @param facesContext
+ */
+ protected void restoreChildState(FacesContext facesContext) {
+ Iterator<UIComponent> itr = dataChildren();
+
+ while (itr.hasNext()) {
+ this.restoreChildState(facesContext, (UIComponent) itr.next());
+ }
+ }
+
+ /**
+ * Restore values of {@link EditableValueHolder} fields after change current
+ * row.
+ *
+ * @param facesContext
+ * @param next
+ * @param childState
+ */
+ protected void restoreChildState(FacesContext facesContext, UIComponent component) {
+ String id = component.getId();
+
+ component.setId(id); // Forces client id to be reset
+
+ SavedState savedState = null;
+ @SuppressWarnings("unchecked")
+ Map<String, SavedState> savedStatesMap = (Map<String, SavedState>) getStateHelper()
+ .get(PropertyKeys.childState);
+
+ if (savedStatesMap != null) {
+ savedState = savedStatesMap.get(component.getClientId(facesContext));
+ }
+
+ if (savedState == null) {
+ savedState = SavedState.EMPTY;
+ }
+
+ if (component instanceof IterationStateHolder) {
+ IterationStateHolder ish = (IterationStateHolder) component;
+
+ savedState.apply(ish);
+ } else if (component instanceof EditableValueHolder) {
+ EditableValueHolder evh = (EditableValueHolder) component;
+
+ savedState.apply(evh);
+ } else if (component instanceof UIForm) {
+ UIForm form = (UIForm) component;
+
+ savedState.apply(form);
+ }
+
+ if (component.getChildCount() > 0) {
+ for (UIComponent child : component.getChildren()) {
+ restoreChildState(facesContext, child);
+ }
+ }
+
+ if (component.getFacetCount() > 0) {
+ for (UIComponent facet : component.getFacets().values()) {
+ restoreChildState(facesContext, facet);
+ }
+ }
+ }
+
+ public void setRowKey(Object rowKey) {
+ setRowKey(getFacesContext(), rowKey);
+ }
+
+ protected FacesEvent wrapEvent(FacesEvent event) {
+ return new RowKeyContextEventWrapper(this, event, getRowKey());
+ }
+
+ @Override
+ public void queueEvent(FacesEvent event) {
+ super.queueEvent(wrapEvent(event));
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see javax.faces.component.UIComponentBase#broadcast(javax.faces.event.FacesEvent)
+ */
+ @Override
+ public void broadcast(FacesEvent event) throws AbortProcessingException {
+ if (event instanceof RowKeyContextEventWrapper) {
+ RowKeyContextEventWrapper eventWrapper = (RowKeyContextEventWrapper) event;
+
+ eventWrapper.broadcast(getFacesContext());
+ } else {
+ super.broadcast(event);
+ }
+ }
+
+ /**
+ * @return the extendedDataModel
+ */
+ protected ExtendedDataModel<?> getExtendedDataModel() {
+ if (extendedDataModel == null) {
+ extendedDataModel = createExtendedDataModel();
+ }
+
+ return extendedDataModel;
+ }
+
+ /**
+ * @return
+ */
+ protected abstract ExtendedDataModel<?> createExtendedDataModel();
+
+ /**
+ * @param extendedDataModel the extendedDataModel to set
+ */
+ protected void setExtendedDataModel(ExtendedDataModel<?> extendedDataModel) {
+ this.extendedDataModel = extendedDataModel;
+ }
+
+ public String getVar() {
+ return (String) getStateHelper().get(PropertyKeys.var);
+ }
+
+ public void setVar(String var) {
+ getStateHelper().put(PropertyKeys.var, var);
+ }
+
+ public String getRowKeyVar() {
+ return (String) getStateHelper().get(PropertyKeys.rowKeyVar);
+ }
+
+ public void setRowKeyVar(String rowKeyVar) {
+ getStateHelper().put(PropertyKeys.rowKeyVar, rowKeyVar);
+ }
+
+ public String getStateVar() {
+ return (String) getStateHelper().get(PropertyKeys.stateVar);
+ }
+
+ public void setStateVar(String stateVar) {
+ getStateHelper().put(PropertyKeys.stateVar, stateVar);
+ }
+
+ //XXX - review and probably remove - useful method, should be left
+ public int getRowCount() {
+ return getExtendedDataModel().getRowCount();
+ }
+
+ public Object getRowData() {
+ if (rowDataIsSet) {
+ return rowData;
+ }
+
+ return getExtendedDataModel().getRowData();
+ }
+
+ public boolean isRowAvailable() {
+ return rowDataIsSet || getExtendedDataModel().isRowAvailable();
+ }
+
+ /**
+ * Boolean attribute that defines whether this iteration component will reset saved children's state
+ * before rendering. By default state is reset if there are no faces messages with severity error or higher.
+ * @return
+ */
+ public boolean isKeepSaved() {
+ Object value = getStateHelper().eval(PropertyKeys.keepSaved);
+
+ if (value == null) {
+ return keepSaved(getFacesContext());
+ } else {
+ return Boolean.valueOf(value.toString());
+ }
+ }
+
+ public void setKeepSaved(boolean keepSaved) {
+ getStateHelper().put(PropertyKeys.keepSaved, keepSaved);
+ }
+
+ /**
+ * Setup EL variable for different iteration. Value of row data and
+ * component state will be put into request scope attributes with names
+ * given by "var" and "varState" bean properties.
+ * <p/>
+ * Changed: does not check for row availability now
+ *
+ * @param faces current faces context
+ * @param localModel
+ * @param rowSelected
+ */
+ protected void setupVariable(FacesContext faces, boolean rowSelected) {
+ Map<String, Object> attrs = getVariablesMap(faces);
+
+ if (rowSelected) {
+
+ // Current row data.
+ setupVariable(getVar(), attrs, getRowData());
+
+ // Component state variable.
+ setupVariable(getStateVar(), attrs, getComponentState());
+
+ // Row key Data variable.
+ setupVariable(getRowKeyVar(), attrs, getRowKey());
+ } else {
+ removeVariable(getVar(), attrs);
+ removeVariable(getStateVar(), attrs);
+ removeVariable(getRowKeyVar(), attrs);
+ }
+ }
+
+ /**
+ * @return
+ */
+ public DataComponentState getComponentState() {
+ if (componentState != null) {
+ return componentState;
+ }
+
+ ValueExpression componentStateExpression = getValueExpression("componentState");
+
+ if (componentStateExpression != null) {
+ componentState = (DataComponentState) componentStateExpression.getValue(getFacesContext().getELContext());
+ }
+
+ if (componentState == null) {
+ componentState = createComponentState();
+
+ if ((componentStateExpression != null)
+ && !componentStateExpression.isReadOnly(getFacesContext().getELContext())) {
+ componentStateExpression.setValue(getFacesContext().getELContext(), componentState);
+ }
+ }
+
+ return componentState;
+ }
+
+ protected abstract DataComponentState createComponentState();
+
+ /**
+ * @param var
+ * @param attrs
+ * @param rowData
+ */
+ private void setupVariable(String var, Map<String, Object> attrs, Object rowData) {
+ if (var != null) {
+ attrs.put(var, rowData);
+ }
+ }
+
+ /**
+ * @param var
+ * @param attrs
+ * @param rowData
+ */
+ private void removeVariable(String var, Map<String, Object> attrs) {
+ if (var != null) {
+ attrs.remove(var);
+ }
+ }
+
+ public Converter getRowKeyConverter() {
+ if (this.rowKeyConverter != null) {
+ return this.rowKeyConverter;
+ }
+
+ return (Converter) getStateHelper().eval(PropertyKeys.rowKeyConverter);
+ }
+
+ public void setRowKeyConverter(Converter converter) {
+ StateHelper stateHelper = getStateHelper();
+ if (initialStateMarked()) {
+ stateHelper.put(PropertyKeys.rowKeyConverterSet, Boolean.TRUE);
+ }
+
+ this.rowKeyConverter = converter;
+ }
+
+ private boolean isSetRowKeyConverter() {
+ Boolean value = (Boolean) getStateHelper().get(PropertyKeys.rowKeyConverterSet);
+ return Boolean.TRUE.equals(value);
+ }
+
+ @Override
+ public String getClientId(FacesContext facesContext) {
+ if (facesContext == null) {
+ throw new NullPointerException("context");
+ }
+
+ if (null == clientId) {
+ StringBuilder id = new StringBuilder(super.getClientId(facesContext));
+ Object rowKey = getRowKey();
+
+ if (rowKey != null) {
+
+ // Use converter to get String representation ot the row key.
+ Converter rowKeyConverter = getRowKeyConverter();
+
+ if (null == rowKeyConverter) {
+
+ // Create default converter for a row key.
+ rowKeyConverter = facesContext.getApplication().createConverter(rowKey.getClass());
+
+ // Store converter for a invokeOnComponents call.
+ if (null != rowKeyConverter) {
+ // TODO - review
+ setRowKeyConverter(rowKeyConverter);
+ }
+ }
+
+ String rowKeyString;
+
+ if (null != rowKeyConverter) {
+
+ // Temporary set clientId, to avoid infinite calls from converter.
+ clientId = id.toString();
+ rowKeyString = rowKeyConverter.getAsString(facesContext, this, rowKey);
+ } else {
+ rowKeyString = rowKey.toString();
+ }
+
+ id.append(UINamingContainer.getSeparatorChar(facesContext)).append(rowKeyString);
+ }
+
+ Renderer renderer = getRenderer(facesContext);
+
+ if (null != renderer) {
+ clientId = renderer.convertClientId(facesContext, id.toString());
+ } else {
+ clientId = id.toString();
+ }
+ }
+
+ return clientId;
+ }
+
+ public String getBaseClientId(FacesContext context) {
+ return super.getClientId(context);
+ }
+
+ /**
+ * Save current state of data variable.
+ *
+ * @param faces current faces context
+ */
+
+ // TODO move into walk() method body
+ public void captureOrigValue(FacesContext faces) {
+ String var = getVar();
+
+ if (var != null) {
+ Map<String, Object> attrs = getVariablesMap(faces);
+
+ this.originalVarValue = attrs.get(var);
+ }
+
+ // TODO add support for another variables
+ }
+
+ /**
+ * Restore value of data variable after processing phase.
+ *
+ * @param faces current faces context
+ */
+ public void restoreOrigValue(FacesContext faces) {
+ String var = getVar();
+
+ if (var != null) {
+ Map<String, Object> attrs = getVariablesMap(faces);
+
+ if (this.originalVarValue != null) {
+ attrs.put(var, this.originalVarValue);
+ } else {
+ attrs.remove(var);
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see javax.faces.component.UIComponent#setValueExpression(java.lang.String, javax.el.ValueExpression)
+ */
+ @Override
+ public void setValueExpression(String name, ValueExpression binding) {
+ if ("var".equals(name) || "rowKeyVar".equals(name) || "stateVar".equals(name)) {
+ throw new IllegalArgumentException(MessageFormat.format("{0} cannot be EL-expression", name));
+ }
+
+ super.setValueExpression(name, binding);
+ }
+
+ /**
+ * Check for validation errors on children components. If true, saved values
+ * must be keep on render phase
+ *
+ * @param context
+ * @return
+ */
+ protected boolean keepSaved(FacesContext context) {
+
+ // For an any validation errors, children components state should be preserved
+ FacesMessage.Severity sev = context.getMaximumSeverity();
+
+ return (sev != null) && (FacesMessage.SEVERITY_ERROR.compareTo(sev) >= 0);
+ }
+
+ /**
+ * Perform iteration on all children components and all data rows with given
+ * visitor.
+ *
+ * @param faces
+ * @param visitor
+ */
+ protected void iterate(FacesContext faces, ComponentVisitor visitor) {
+
+ // stop if not rendered
+ if (!this.isRendered()) {
+ return;
+ }
+
+ // reset rowIndex
+ this.captureOrigValue(faces);
+ this.setRowKey(faces, null);
+
+ try {
+ Iterator<UIComponent> fixedChildren = fixedChildren();
+
+ while (fixedChildren.hasNext()) {
+ UIComponent component = fixedChildren.next();
+
+ visitor.processComponent(faces, component, null);
+ }
+
+ walk(faces, visitor, null);
+ } catch (Exception e) {
+ throw new FacesException(e);
+ } finally {
+ this.setRowKey(faces, null);
+ this.restoreOrigValue(faces);
+ }
+ }
+
+ /**
+ * Walk ( visit ) this component on all data-aware children for each row.
+ *
+ * @param faces
+ * @param visitor
+ */
+ public void walk(FacesContext faces, DataVisitor visitor, Object argument) {
+ Object key = getRowKey();
+ captureOrigValue(faces);
+
+ Range range = null;
+ DataComponentState componentState = getComponentState();
+
+ if (componentState != null) {
+ range = componentState.getRange();
+ }
+
+ getExtendedDataModel().walk(faces, visitor, range, argument);
+
+ setRowKey(faces, key);
+ restoreOrigValue(faces);
+ }
+
+ public void processDecodes(FacesContext faces) {
+ if (!this.isRendered()) {
+ return;
+ }
+
+ pushComponentToEL(faces, this);
+ preDecode(faces);
+ this.iterate(faces, decodeVisitor);
+ this.decode(faces);
+ popComponentFromEL(faces);
+ }
+
+ public void processValidators(FacesContext faces) {
+ if (!this.isRendered()) {
+ return;
+ }
+
+ pushComponentToEL(faces, this);
+ Application app = faces.getApplication();
+ app.publishEvent(faces, PreValidateEvent.class, this);
+ preValidate(faces);
+ this.iterate(faces, validateVisitor);
+ app.publishEvent(faces, PostValidateEvent.class, this);
+ popComponentFromEL(faces);
+ }
+
+ public void processUpdates(FacesContext faces) {
+ if (!this.isRendered()) {
+ return;
+ }
+
+ pushComponentToEL(faces, this);
+ preUpdate(faces);
+ this.iterate(faces, updateVisitor);
+
+ ExtendedDataModel<?> dataModel = getExtendedDataModel();
+
+ // If no validation errors, update values for serializable model,
+ // restored from view.
+ if ((dataModel instanceof SerializableDataModel) && (!isKeepSaved())) {
+ SerializableDataModel serializableModel = (SerializableDataModel) dataModel;
+
+ serializableModel.update();
+ }
+
+ doUpdate();
+
+ popComponentFromEL(faces);
+ }
+
+ protected void doUpdate() {
+
+ }
+
+ @Override
+ public void setId(String id) {
+ super.setId(id);
+ this.clientId = null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.ajax4jsf.component.IterationStateHolder#getIterationState()
+ */
+ public Object getIterationState() {
+ assert rowKey == null;
+
+ return new IterationState(this.componentState, this.extendedDataModel);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.component.IterationStateHolder#setIterationState(java.lang.Object)
+ */
+ public void setIterationState(Object stateObject) {
+ assert rowKey == null;
+
+ // TODO - ?
+ // restoreChildState(getFacesContext());
+ if (stateObject != null) {
+ IterationState iterationState = (IterationState) stateObject;
+ iterationState.restoreComponentState(this);
+
+ this.componentState = iterationState.getComponentState();
+ this.extendedDataModel = iterationState.getDataModel();
+ } else {
+ this.componentState = null;
+ this.extendedDataModel = null;
+ }
+ }
+
+ protected void resetDataModel() {
+ this.extendedDataModel = null;
+ }
+
+ protected void resetChildState() {
+ getStateHelper().remove(PropertyKeys.childState);
+ }
+
+ protected void preDecode(FacesContext context) {
+ resetDataModel();
+
+ Object savedChildState = getStateHelper().get(PropertyKeys.childState);
+ // TODO - verify the check for null: savedChildState == null
+ if (savedChildState == null || !isKeepSaved()) {
+ resetChildState();
+ }
+ }
+
+ // TODO - do we need this method?
+ protected void preValidate(FacesContext context) {
+ }
+
+ // TODO - do we need this method?
+ protected void preUpdate(FacesContext context) {
+ }
+
+ protected void preEncodeBegin(FacesContext context) {
+ resetDataModel();
+
+ if (!isKeepSaved()) {
+ //TODO - this also resets state for the nested iteration components - is it correct?
+ resetChildState();
+ }
+ }
+
+ @Override
+ public void markInitialState() {
+ super.markInitialState();
+
+ if (rowKeyConverter instanceof PartialStateHolder) {
+ ((PartialStateHolder) rowKeyConverter).markInitialState();
+ }
+ }
+
+ @Override
+ public void clearInitialState() {
+ super.clearInitialState();
+
+ if (rowKeyConverter instanceof PartialStateHolder) {
+ ((PartialStateHolder) rowKeyConverter).clearInitialState();
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see javax.faces.component.UIComponentBase#saveState(javax.faces.context.FacesContext)
+ */
+ @Override
+ public Object saveState(FacesContext context) {
+ Object parentState = super.saveState(context);
+ Object savedComponentState = new IterationState(componentState, extendedDataModel).saveState();
+
+ Object converterState = null;
+ boolean nullDelta = true;
+
+ boolean converterHasPartialState = false;
+
+ if (initialStateMarked()) {
+ if (!isSetRowKeyConverter() && rowKeyConverter != null && rowKeyConverter instanceof PartialStateHolder) {
+ // Delta
+ StateHolder holder = (StateHolder) rowKeyConverter;
+ if (!holder.isTransient()) {
+ Object attachedState = holder.saveState(context);
+ if (attachedState != null) {
+ nullDelta = false;
+ converterState = attachedState;
+ }
+ converterHasPartialState = true;
+ } else {
+ converterState = null;
+ }
+ } else if (isSetRowKeyConverter() || rowKeyConverter != null) {
+ // Full
+ converterState = saveAttachedState(context, rowKeyConverter);
+ nullDelta = false;
+ }
+
+ if (parentState == null && savedComponentState == null && nullDelta) {
+ // No values
+ return null;
+ }
+ } else {
+ converterState = saveAttachedState(context, rowKeyConverter);
+ }
+
+ return new Object[] {
+ parentState,
+ savedComponentState,
+ converterHasPartialState,
+ converterState
+ };
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.component.UIComponentBase#restoreState(javax.faces.context.FacesContext, java.lang.Object)
+ */
+ @Override
+ public void restoreState(FacesContext context, Object stateObject) {
+ if (stateObject == null) {
+ return ;
+ }
+
+ Object[] state = (Object[]) stateObject;
+
+ super.restoreState(context, state[0]);
+
+ if (state[1] != null) {
+ IterationState iterationState = new IterationState();
+ iterationState.restoreState(state[1]);
+ iterationState.restoreComponentState(this);
+
+ // TODO update state model binding
+ componentState = iterationState.getComponentState();
+ extendedDataModel = iterationState.getDataModel();
+ }
+
+ boolean converterHasPartialState = Boolean.TRUE.equals(state[2]);
+ Object savedConverterState = state[3];
+ if (converterHasPartialState) {
+ ((StateHolder) rowKeyConverter).restoreState(context, savedConverterState);
+ } else {
+ rowKeyConverter = (Converter) UIComponentBase.restoreAttachedState(context, savedConverterState);
+ }
+ }
+
+ private boolean matchesBaseId(String clientId, String baseId, char separatorChar) {
+ if (clientId.equals(baseId)) {
+ return true;
+ }
+
+ // if clientId.startsWith(baseId + separatorChar)
+ if (clientId.startsWith(baseId) && (clientId.length() > baseId.length())
+ && (clientId.charAt(baseId.length()) == separatorChar)) {
+ return true;
+ }
+
+ return false;
+ }
+
+ @Override
+ public boolean invokeOnComponent(FacesContext context, String clientId, ContextCallback callback)
+ throws FacesException {
+
+ if ((null == context) || (null == clientId) || (null == callback)) {
+ throw new NullPointerException();
+ }
+
+ String baseId = super.getClientId(context);
+
+ if (!matchesBaseId(clientId, baseId, UINamingContainer.getSeparatorChar(context))) {
+ return false;
+ }
+
+ boolean found = false;
+ Object oldRowKey = getRowKey();
+
+ // TODO - this does not seem right
+ captureOrigValue(context);
+
+ try {
+
+ // TODO - ?
+ // if (null != oldRowKey) {
+ setRowKey(context, null);
+
+ // }
+ if (clientId.equals(baseId)) {
+ callback.invokeContextCallback(context, this);
+ found = true;
+ } else {
+ Iterator<UIComponent> fixedChildrenItr = fixedChildren();
+
+ while (fixedChildrenItr.hasNext() && !found) {
+ UIComponent fixedChild = fixedChildrenItr.next();
+
+ found = fixedChild.invokeOnComponent(context, clientId, callback);
+ }
+ }
+
+ if (!found) {
+ Object newRowKey = null;
+
+ // Call for a child component - try to detect row key
+ // baseId.length() + 1 expression skips SEPARATOR_CHAR
+ //TODO - convertKeyString
+ String rowKeyString = extractKeySegment(context, clientId.substring(baseId.length() + 1));
+
+ if (rowKeyString != null) {
+ Converter keyConverter = getRowKeyConverter();
+
+ if (null != keyConverter) {
+ try {
+ //TODO: review
+ newRowKey = keyConverter.getAsObject(context, this, rowKeyString);
+ } catch (ConverterException e) {
+
+ // TODO: LOG error
+ }
+ }
+ }
+
+ setRowKey(context, newRowKey);
+
+ if (isRowAvailable()) {
+ Iterator<UIComponent> dataChildrenItr = dataChildren();
+
+ while (dataChildrenItr.hasNext() && !found) {
+ UIComponent dataChild = dataChildrenItr.next();
+
+ found = dataChild.invokeOnComponent(context, clientId, callback);
+ }
+ }
+ }
+ } catch (Exception e) {
+ throw new FacesException(e);
+ } finally {
+
+ // if (null != oldRowKey) {
+ try {
+ setRowKey(context, oldRowKey);
+ restoreOrigValue(context);
+ } catch (Exception e) {
+ LOG.error(e.getMessage(), e);
+ }
+
+ // }
+ }
+
+ return found;
+ }
+
+ // Tests whether we need to visit our children as part of
+ // a tree visit
+ private boolean doVisitChildren(VisitContext context, boolean visitRows) {
+
+ // Just need to check whether there are any ids under this
+ // subtree. Make sure row index is cleared out since
+ // getSubtreeIdsToVisit() needs our row-less client id.
+
+ // TODO check this
+ if (visitRows) {
+ setRowKey(context.getFacesContext(), null);
+ }
+
+ // TODO optimize for returned IDs
+ Collection<String> idsToVisit = context.getSubtreeIdsToVisit(this);
+
+ assert idsToVisit != null;
+
+ if (idsToVisit == VisitContext.ALL_IDS) {
+ // TODO
+ }
+
+ // All ids or non-empty collection means we need to visit our children.
+ return !idsToVisit.isEmpty();
+ }
+
+ private boolean visitComponents(Iterator<UIComponent> components, VisitContext context, VisitCallback callback) {
+
+ while (components.hasNext()) {
+ UIComponent nextChild = components.next();
+
+ if (nextChild.visitTree(context, callback)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ protected boolean visitFixedChildren(VisitContext visitContext, VisitCallback callback) {
+
+ return visitComponents(fixedChildren(), visitContext, callback);
+ }
+
+ protected VisitResult visitDataChildrenMetaComponents(ExtendedVisitContext extendedVisitContext, VisitCallback callback) {
+ return VisitResult.ACCEPT;
+ }
+
+ protected boolean visitDataChildren(VisitContext visitContext, VisitCallback callback, boolean visitRows) {
+
+ if (visitRows) {
+ FacesContext facesContext = visitContext.getFacesContext();
+
+ DataVisitorForVisitTree dataVisitor = new DataVisitorForVisitTree(callback, visitContext);
+ this.walk(facesContext, dataVisitor, null);
+
+ return dataVisitor.getVisitResult();
+ } else {
+ return visitComponents(dataChildren(), visitContext, callback);
+ }
+ }
+
+ @Override
+ public boolean visitTree(VisitContext visitContext, VisitCallback callback) {
+
+ // First check to see whether we are visitable. If not
+ // short-circuit out of this subtree, though allow the
+ // visit to proceed through to other subtrees.
+ if (!isVisitable(visitContext)) {
+ return false;
+ }
+
+ // Clear out the row index is one is set so that
+ // we start from a clean slate.
+ FacesContext facesContext = visitContext.getFacesContext();
+
+ // NOTE: that the visitRows local will be obsolete once the
+ // appropriate visit hints have been added to the API
+ boolean visitRows = requiresRowIteration(facesContext);
+
+ Object oldRowKey = null;
+ if (visitRows) {
+ captureOrigValue(facesContext);
+ oldRowKey = getRowKey();
+ setRowKey(facesContext, null);
+ }
+
+ // Push ourselves to EL
+ pushComponentToEL(facesContext, null);
+
+ try {
+
+ // Visit ourselves. Note that we delegate to the
+ // VisitContext to actually perform the visit.
+ VisitResult result = visitContext.invokeVisitCallback(this, callback);
+
+ // If the visit is complete, short-circuit out and end the visit
+ if (result == VisitResult.COMPLETE) {
+ return true;
+ }
+
+ // Visit children, short-circuiting as necessary
+ if ((result == VisitResult.ACCEPT) && doVisitChildren(visitContext, visitRows)) {
+ if (visitRows) {
+ setRowKey(facesContext, null);
+ }
+
+ if (visitFixedChildren(visitContext, callback)) {
+ return true;
+ }
+
+ if (visitContext instanceof ExtendedVisitContext) {
+ ExtendedVisitContext extendedVisitContext = (ExtendedVisitContext) visitContext;
+
+ Collection<String> directSubtreeIdsToVisit = extendedVisitContext.getDirectSubtreeIdsToVisit(this);
+ if (directSubtreeIdsToVisit != VisitContext.ALL_IDS) {
+ if (directSubtreeIdsToVisit.isEmpty()) {
+ return false;
+ } else {
+ VisitContext directChildrenVisitContext =
+ extendedVisitContext.createNamingContainerVisitContext(this, directSubtreeIdsToVisit);
+
+ if (visitRows) {
+ setRowKey(facesContext, null);
+ }
+ if (visitFixedChildren(directChildrenVisitContext, STUB_CALLBACK)) {
+ return false;
+ }
+ }
+ }
+ }
+
+ if (visitDataChildren(visitContext, callback, visitRows)) {
+ return true;
+ }
+ }
+ } finally {
+
+ // Clean up - pop EL and restore old row index
+ popComponentFromEL(facesContext);
+
+ if (visitRows) {
+ try {
+ setRowKey(facesContext, oldRowKey);
+ restoreOrigValue(facesContext);
+ } catch (Exception e) {
+
+ // TODO: handle exception
+ LOG.error(e.getMessage(), e);
+ }
+ }
+ }
+
+ // Return false to allow the visit to continue
+ return false;
+ }
+
+ /**
+ * @param facesContext
+ * @return
+ */
+ private boolean requiresRowIteration(FacesContext context) {
+ return (!PhaseId.RESTORE_VIEW.equals(context.getCurrentPhaseId()));
+ }
+
+ /**
+ * @param context
+ * @param substring
+ * @return
+ */
+ // TODO review!
+ protected String extractKeySegment(FacesContext context, String substring) {
+ char separatorChar = UINamingContainer.getSeparatorChar(context);
+ int separatorIndex = substring.indexOf(separatorChar);
+
+ if (separatorIndex < 0) {
+ return null;
+ } else {
+ return substring.substring(0, separatorIndex);
+ }
+ }
+
+ /**
+ * Base class for visit data model at phases decode, validation and update model
+ *
+ * @author shura
+ */
+ protected abstract class ComponentVisitor implements DataVisitor {
+ public DataVisitResult process(FacesContext context, Object rowKey, Object argument) {
+ setRowKey(context, rowKey);
+
+ if (isRowAvailable()) {
+ Iterator<UIComponent> childIterator = dataChildren();
+
+ while (childIterator.hasNext()) {
+ UIComponent component = childIterator.next();
+
+ processComponent(context, component, argument);
+ }
+ }
+
+ return DataVisitResult.CONTINUE;
+ }
+
+ public abstract void processComponent(FacesContext context, UIComponent c, Object argument);
+ }
+
+ @Override
+ public void processEvent(ComponentSystemEvent event) throws AbortProcessingException {
+ super.processEvent(event);
+
+ if (event instanceof PreRenderComponentEvent) {
+ preEncodeBegin(getFacesContext());
+ }
+ }
+
+ protected DataComponentState getLocalComponentState() {
+ return componentState;
+ }
+}
Added: trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTree.java.orig
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTree.java.orig (rev 0)
+++ trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTree.java.orig 2010-12-02 14:32:03 UTC (rev 20309)
@@ -0,0 +1,575 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.
+ */
+package org.richfaces.component;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+
+import javax.el.ELContext;
+import javax.el.ELException;
+import javax.el.MethodExpression;
+import javax.el.ValueExpression;
+import javax.faces.application.Application;
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UpdateModelException;
+import javax.faces.component.html.HtmlOutputText;
+import javax.faces.component.visit.VisitCallback;
+import javax.faces.component.visit.VisitContext;
+import javax.faces.component.visit.VisitResult;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.ExceptionQueuedEvent;
+import javax.faces.event.ExceptionQueuedEventContext;
+import javax.faces.event.FacesEvent;
+import javax.faces.event.PhaseId;
+
+import org.ajax4jsf.model.DataComponentState;
+import org.ajax4jsf.model.DataVisitor;
+import org.ajax4jsf.model.ExtendedDataModel;
+import org.richfaces.application.MessageFactory;
+import org.richfaces.application.ServiceTracker;
+import org.richfaces.appplication.FacesMessages;
+import org.richfaces.cdk.annotations.Attribute;
+import org.richfaces.cdk.annotations.EventName;
+import org.richfaces.cdk.annotations.JsfComponent;
+import org.richfaces.cdk.annotations.JsfRenderer;
+import org.richfaces.cdk.annotations.Signature;
+import org.richfaces.cdk.annotations.Tag;
+import org.richfaces.component.util.MessageUtil;
+import org.richfaces.context.ExtendedVisitContext;
+import org.richfaces.context.ExtendedVisitContextMode;
+import org.richfaces.convert.SequenceRowKeyConverter;
+import org.richfaces.event.TreeSelectionChangeEvent;
+import org.richfaces.event.TreeSelectionChangeListener;
+import org.richfaces.event.TreeSelectionChangeSource;
+import org.richfaces.event.TreeToggleEvent;
+import org.richfaces.event.TreeToggleListener;
+import org.richfaces.event.TreeToggleSource;
+import org.richfaces.model.DeclarativeTreeDataModelImpl;
+<<<<<<< HEAD
+import org.richfaces.model.DeclarativeTreeModel;
+=======
+>>>>>>> RF-9680
+import org.richfaces.model.SwingTreeNodeDataModelImpl;
+import org.richfaces.model.TreeDataModel;
+import org.richfaces.model.TreeDataModelTuple;
+import org.richfaces.model.TreeDataVisitor;
+import org.richfaces.renderkit.MetaComponentRenderer;
+
+import com.google.common.base.Predicate;
+import com.google.common.base.Strings;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Iterators;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+@JsfComponent(
+ type = AbstractTree.COMPONENT_TYPE,
+ family = AbstractTree.COMPONENT_FAMILY,
+ tag = @Tag(name = "tree", handler = "org.richfaces.view.facelets.TreeHandler"),
+ renderer = @JsfRenderer(type = "org.richfaces.TreeRenderer"),
+ attributes = {"events-props.xml", "core-props.xml", "i18n-props.xml"}
+)
+//TODO add rowData caching for wrapper events
+public abstract class AbstractTree extends UIDataAdaptor implements MetaComponentResolver, MetaComponentEncoder, TreeSelectionChangeSource, TreeToggleSource {
+
+ public static final String COMPONENT_TYPE = "org.richfaces.Tree";
+
+ public static final String COMPONENT_FAMILY = "org.richfaces.Tree";
+
+ public static final String SELECTION_META_COMPONENT_ID = "selection";
+
+ private static final String DEFAULT_TREE_NODE_CREATED = AbstractTree.class.getName() + ":DEFAULT_TREE_NODE_CREATED";
+
+ private static final class MatchingTreeNodePredicate implements Predicate<UIComponent> {
+
+ private String type;
+
+ public MatchingTreeNodePredicate(String type) {
+ super();
+ this.type = type;
+ }
+
+ public boolean apply(UIComponent input) {
+ if (!(input instanceof AbstractTreeNode)) {
+ return false;
+ }
+
+ String nodeType = ((AbstractTreeNode) input).getType();
+ if (type == null && nodeType == null) {
+ return true;
+ }
+
+ return type != null && type.equals(nodeType);
+ }
+ };
+
+ private static final Converter ROW_KEY_CONVERTER = new SequenceRowKeyConverter();
+
+ private enum PropertyKeys {
+ selection
+ }
+
+ @SuppressWarnings("unused")
+ @Attribute(generate = false, signature = @Signature(returnType = Void.class, parameters = TreeSelectionChangeEvent.class))
+ private MethodExpression selectionChangeListener;
+
+ @SuppressWarnings("unused")
+ @Attribute(generate = false, signature = @Signature(returnType = Void.class, parameters = TreeToggleListener.class))
+ private MethodExpression toggleListener;
+
+ private transient TreeRange treeRange;
+
+ public AbstractTree() {
+ setKeepSaved(true);
+ setRendererType("org.richfaces.TreeRenderer");
+ }
+
+ protected TreeRange getTreeRange() {
+ if (treeRange == null) {
+ treeRange = new TreeRange(this);
+ }
+
+ return treeRange;
+ }
+
+ public abstract Object getValue();
+
+ public abstract boolean isImmediate();
+
+ public abstract String getIconLeaf();
+
+ public abstract String getIconExpanded();
+
+ public abstract String getIconCollapsed();
+
+ public abstract String getNodeClass();
+
+ public abstract String getHandleClass();
+
+ public abstract String getIconClass();
+
+ public abstract String getLabelClass();
+
+ @Attribute(events = @EventName("nodetoggle"))
+ public abstract String getOnnodetoggle();
+
+ @Attribute(events = @EventName("beforenodetoggle"))
+ public abstract String getOnbeforenodetoggle();
+
+ @Attribute(events = @EventName("selectionchange"))
+ public abstract String getOnselectionchange();
+
+ @Attribute(events = @EventName("beforeselectionchange"))
+ public abstract String getOnbeforeselectionchange();
+
+ @Attribute(defaultValue = "SwitchType.DEFAULT")
+ public abstract SwitchType getToggleType();
+
+ @Attribute(defaultValue = "SwitchType.client")
+ public abstract SwitchType getSelectionType();
+
+ public abstract String getNodeType();
+
+ public abstract String getToggleNodeEvent();
+
+ @Override
+ public String getFamily() {
+ return COMPONENT_FAMILY;
+ }
+
+ public Collection<Object> getSelection() {
+ @SuppressWarnings("unchecked")
+ Collection<Object> selection = (Collection<Object>) getStateHelper().eval(PropertyKeys.selection);
+ if (selection == null) {
+ selection = new HashSet<Object>();
+
+ ValueExpression ve = getValueExpression(PropertyKeys.selection.toString());
+ if (ve != null) {
+ ve.setValue(getFacesContext().getELContext(), selection);
+ } else {
+ getStateHelper().put(PropertyKeys.selection, selection);
+ }
+ }
+
+ return selection;
+ }
+
+ public void setSelection(Collection<Object> selection) {
+ getStateHelper().put(PropertyKeys.selection, selection);
+ }
+
+ @Override
+ protected DataComponentState createComponentState() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Converter getRowKeyConverter() {
+ Converter converter = super.getRowKeyConverter();
+ if (converter == null) {
+ converter = ROW_KEY_CONVERTER;
+ }
+ return converter;
+ }
+
+ protected Iterator<UIComponent> findMatchingTreeNodeComponent(String nodeType, UIComponent parentComponent) {
+ Iterator<UIComponent> children = parentComponent.getChildren().iterator();
+ if (parentComponent != this) {
+ children = Iterators.concat(children, this.getChildren().iterator());
+ }
+
+ return Iterators.filter(children, new MatchingTreeNodePredicate(nodeType));
+ }
+
+ protected UIComponent getCurrentComponent() {
+ ExtendedDataModel<?> dataModel = getExtendedDataModel();
+ if (dataModel instanceof DeclarativeTreeModel) {
+ return ((DeclarativeTreeModel) dataModel).getCurrentComponent();
+ }
+
+ return this;
+ }
+
+ public AbstractTreeNode findTreeNodeComponent() {
+ FacesContext facesContext = getFacesContext();
+
+ String nodeType = getNodeType();
+
+ Iterator<UIComponent> nodesItr = findMatchingTreeNodeComponent(nodeType, getCurrentComponent());
+
+ if (nodesItr.hasNext()) {
+ Iterator<UIComponent> renderedNodesItr = Iterators.filter(nodesItr, ComponentPredicates.isRendered());
+ if (renderedNodesItr.hasNext()) {
+ return (AbstractTreeNode) renderedNodesItr.next();
+ }
+
+ return null;
+ }
+
+ if (Strings.isNullOrEmpty(nodeType)) {
+ if (getAttributes().put(DEFAULT_TREE_NODE_CREATED, Boolean.TRUE) != null) {
+ return null;
+ }
+
+ Application application = facesContext.getApplication();
+ AbstractTreeNode treeNode = (AbstractTreeNode) application.createComponent(AbstractTreeNode.COMPONENT_TYPE);
+ treeNode.setId("__defaultTreeNode");
+
+ getChildren().add(treeNode);
+
+ UIComponent text = application.createComponent(HtmlOutputText.COMPONENT_TYPE);
+ text.setValueExpression("value", application.getExpressionFactory().createValueExpression(facesContext.getELContext(),
+ "#{" + getVar() + "}", String.class));
+ treeNode.getChildren().add(text);
+
+ return treeNode;
+ }
+
+ return null;
+ }
+
+ @Override
+ public void broadcast(FacesEvent event) throws AbortProcessingException {
+ super.broadcast(event);
+
+ if (event instanceof TreeSelectionChangeEvent) {
+ TreeSelectionChangeEvent selectionEvent = (TreeSelectionChangeEvent) event;
+
+ final Collection<Object> newSelection = selectionEvent.getNewSelection();
+
+ Collection<Object> selectionCollection = getSelection();
+
+ Iterables.removeIf(selectionCollection, new Predicate<Object>() {
+ public boolean apply(Object input) {
+ return !newSelection.contains(input);
+ };
+ });
+
+ if (!newSelection.isEmpty()) {
+ Iterables.addAll(selectionCollection, newSelection);
+ }
+ } else if (event instanceof TreeToggleEvent) {
+ TreeToggleEvent toggleEvent = (TreeToggleEvent) event;
+ AbstractTreeNode treeNodeComponent = findTreeNodeComponent();
+
+ boolean newExpandedValue = toggleEvent.isExpanded();
+
+ FacesContext context = getFacesContext();
+ ValueExpression expression = getValueExpression(AbstractTreeNode.PropertyKeys.expanded.toString());
+ if (expression != null) {
+ ELContext elContext = context.getELContext();
+ Exception caught = null;
+ FacesMessage message = null;
+ try {
+ expression.setValue(elContext, newExpandedValue);
+ } catch (ELException e) {
+ caught = e;
+ String messageStr = e.getMessage();
+ Throwable result = e.getCause();
+ while (null != result &&
+ result.getClass().isAssignableFrom(ELException.class)) {
+ messageStr = result.getMessage();
+ result = result.getCause();
+ }
+ if (null == messageStr) {
+ MessageFactory messageFactory = ServiceTracker.getService(MessageFactory.class);
+ message =
+ messageFactory.createMessage(context, FacesMessages.UIINPUT_UPDATE,
+ MessageUtil.getLabel(context, this));
+ } else {
+ message = new FacesMessage(FacesMessage.SEVERITY_ERROR,
+ messageStr,
+ messageStr);
+ }
+ } catch (Exception e) {
+ caught = e;
+ MessageFactory messageFactory = ServiceTracker.getService(MessageFactory.class);
+ message =
+ messageFactory.createMessage(context, FacesMessages.UIINPUT_UPDATE,
+ MessageUtil.getLabel(context, this));
+ }
+ if (caught != null) {
+ assert(message != null);
+ UpdateModelException toQueue = new UpdateModelException(message, caught);
+ ExceptionQueuedEventContext eventContext =
+ new ExceptionQueuedEventContext(context,
+ toQueue,
+ this,
+ PhaseId.UPDATE_MODEL_VALUES);
+ context.getApplication().publishEvent(context,
+ ExceptionQueuedEvent.class,
+ eventContext);
+ }
+ } else {
+ treeNodeComponent.setExpanded(newExpandedValue);
+ }
+ }
+ }
+
+ @Override
+ protected boolean visitFixedChildren(VisitContext visitContext, VisitCallback callback) {
+ if (visitContext instanceof ExtendedVisitContext) {
+ ExtendedVisitContext extendedVisitContext = (ExtendedVisitContext) visitContext;
+
+ if (ExtendedVisitContextMode.RENDER == extendedVisitContext.getVisitMode()) {
+ VisitResult result = extendedVisitContext.invokeMetaComponentVisitCallback(this, callback, SELECTION_META_COMPONENT_ID);
+ if (result != VisitResult.ACCEPT) {
+ return result == VisitResult.COMPLETE;
+ }
+ }
+ }
+
+ return super.visitFixedChildren(visitContext, callback);
+ }
+
+ void decodeMetaComponent(FacesContext context, String metaComponentId) {
+ ((MetaComponentRenderer) getRenderer(context)).decodeMetaComponent(context, this, metaComponentId);
+ }
+
+ public void encodeMetaComponent(FacesContext context, String metaComponentId) throws IOException {
+ ((MetaComponentRenderer) getRenderer(context)).encodeMetaComponent(context, this, metaComponentId);
+ }
+
+ public String resolveClientId(FacesContext facesContext, UIComponent contextComponent, String metaComponentId) {
+ if (SELECTION_META_COMPONENT_ID.equals(metaComponentId)) {
+ return getClientId(facesContext) + MetaComponentResolver.META_COMPONENT_SEPARATOR_CHAR + metaComponentId;
+ }
+
+ return null;
+ }
+
+ public String substituteUnresolvedClientId(FacesContext facesContext, UIComponent contextComponent,
+ String metaComponentId) {
+
+ return null;
+ }
+
+ @Override
+ protected Iterator<UIComponent> dataChildren() {
+ AbstractTreeNode treeNodeComponent = findTreeNodeComponent();
+ if (treeNodeComponent != null) {
+ return Iterators.<UIComponent>singletonIterator(treeNodeComponent);
+ } else {
+ return Iterators.<UIComponent>emptyIterator();
+ }
+ }
+
+ public void addTreeSelectionChangeListener(TreeSelectionChangeListener listener) {
+ addFacesListener(listener);
+ }
+
+ @Attribute(hidden = true)
+ public TreeSelectionChangeListener[] getTreeSelectionChangeListeners() {
+ return (TreeSelectionChangeListener[]) getFacesListeners(TreeSelectionChangeListener.class);
+ }
+
+ public void removeTreeSelectionChangeListener(TreeSelectionChangeListener listener) {
+ removeFacesListener(listener);
+ }
+
+ public void addTreeToggleListener(TreeToggleListener listener) {
+ addFacesListener(listener);
+ }
+
+ @Attribute(hidden = true)
+ public TreeToggleListener[] getTreeToggleListeners() {
+ return (TreeToggleListener[]) getFacesListeners(TreeToggleListener.class);
+ }
+
+ public void removeTreeToggleListener(TreeToggleListener listener) {
+ removeFacesListener(listener);
+ }
+
+ @Attribute(hidden = true)
+ public boolean isExpanded() {
+ if (getRowKey() == null) {
+ return true;
+ }
+
+ AbstractTreeNode treeNode = findTreeNodeComponent();
+ if (treeNode == null) {
+ return false;
+ }
+
+ return treeNode.isExpanded();
+ }
+
+ //TODO review
+ protected TreeDataModel<?> getTreeDataModel() {
+ return (TreeDataModel<?>) getExtendedDataModel();
+ }
+
+ @Attribute(hidden = true)
+ public boolean isLeaf() {
+ if (getRowKey() == null) {
+ return false;
+ }
+
+ return getTreeDataModel().isLeaf();
+ }
+
+ @Override
+ public void walk(final FacesContext faces, final DataVisitor visitor, final Object argument) {
+ walkModel(faces, new TreeDataVisitor() {
+
+ public void enterNode() {
+ visitor.process(faces, getRowKey(), argument);
+ }
+
+ public void exitNode() {
+ }
+
+ public void beforeChildrenVisit() {
+ }
+
+ public void afterChildrenVisit() {
+ }
+
+ });
+ }
+
+ @Override
+ protected ExtendedDataModel<?> createExtendedDataModel() {
+ ExtendedDataModel<?> dataModel;
+
+ Object value = getValue();
+ if (value == null) {
+ dataModel = new DeclarativeTreeDataModelImpl(this, getVar(), getVariablesMap(getFacesContext()));
+ } else {
+ dataModel = new SwingTreeNodeDataModelImpl();
+ dataModel.setWrappedData(getValue());
+ }
+
+ return dataModel;
+ }
+
+ public void walkModel(FacesContext context, TreeDataVisitor dataVisitor) {
+ TreeDataModel<?> model = getTreeDataModel();
+
+ if (!getTreeRange().shouldProcessNode()) {
+ return;
+ }
+
+ boolean isRootNode = (getRowKey() == null);
+
+ if (!isRootNode) {
+ dataVisitor.enterNode();
+ }
+
+ walkModelChildren(context, dataVisitor, model);
+
+ if (!isRootNode) {
+ dataVisitor.exitNode();
+ }
+ }
+
+ private void walkModelChildren(FacesContext context, TreeDataVisitor dataVisitor, TreeDataModel<?> model) {
+ if (!getTreeRange().shouldIterateChildren()) {
+ return;
+ }
+
+ dataVisitor.beforeChildrenVisit();
+
+ Iterator<TreeDataModelTuple> childrenTuples = model.children();
+ while (childrenTuples.hasNext()) {
+ TreeDataModelTuple tuple = childrenTuples.next();
+
+ restoreFromSnapshot(context, tuple);
+
+ if (!getTreeRange().shouldProcessNode()) {
+ continue;
+ }
+
+ dataVisitor.enterNode();
+
+ walkModelChildren(context, dataVisitor, model);
+
+ dataVisitor.exitNode();
+ }
+
+ dataVisitor.afterChildrenVisit();
+ }
+
+ @Override
+ protected void resetDataModel() {
+ super.resetDataModel();
+ treeRange = null;
+ }
+
+ public TreeDataModelTuple createSnapshot() {
+ return getTreeDataModel().createSnapshot();
+ }
+
+ public void restoreFromSnapshot(FacesContext context, TreeDataModelTuple tuple) {
+ getTreeDataModel().restoreFromSnapshot(tuple);
+ setRowKey(context, tuple.getRowKey());
+ }
+
+}
Added: trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SwingTreeNodeDataModelImpl.java.orig
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SwingTreeNodeDataModelImpl.java.orig (rev 0)
+++ trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SwingTreeNodeDataModelImpl.java.orig 2010-12-02 14:32:03 UTC (rev 20309)
@@ -0,0 +1,196 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.
+ */
+package org.richfaces.model;
+
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+import javax.swing.tree.TreeNode;
+
+import com.google.common.base.Predicates;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Iterators;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class SwingTreeNodeDataModelImpl extends TreeSequenceKeyModel<Integer, TreeNode> {
+
+ private final class SwingTreeNodeRowKeyIterator implements Iterator<TreeDataModelTuple> {
+
+ private SequenceRowKey<Integer> baseKey;
+
+ private Iterator<TreeNode> children;
+
+ private int counter = 0;
+
+ private SwingTreeNodeRowKeyIterator(SequenceRowKey<Integer> baseKey, Iterator<TreeNode> children) {
+ this.baseKey = baseKey;
+ this.children = children;
+ }
+
+ private int getNextCounterValue() {
+ return counter++;
+ }
+
+ public boolean hasNext() {
+ return children.hasNext();
+ }
+
+ public TreeDataModelTuple next() {
+ TreeNode node = children.next();
+
+ SequenceRowKey<Integer> key;
+
+ if (baseKey != null) {
+ key = baseKey.append(getNextCounterValue());
+ } else {
+ key = new SequenceRowKey<Integer>(getNextCounterValue());
+ }
+
+ return new TreeDataModelTuple(key, node);
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+ private final class FakeRootNode implements TreeNode {
+
+ private Collection<TreeNode> wrappedData;
+
+ public FakeRootNode(Collection<TreeNode> wrappedData) {
+ super();
+ this.wrappedData = wrappedData;
+ }
+
+ public boolean isLeaf() {
+ return !wrappedData.isEmpty();
+ }
+
+ public TreeNode getParent() {
+ return null;
+ }
+
+ public int getIndex(TreeNode node) {
+ if (wrappedData == null) {
+ return -1;
+ }
+
+ return Iterables.indexOf(wrappedData, Predicates.equalTo(node));
+ }
+
+ public int getChildCount() {
+ if (wrappedData == null) {
+ return 0;
+ }
+
+ return wrappedData.size();
+ }
+
+ public TreeNode getChildAt(int childIndex) {
+ if (wrappedData == null) {
+ throw new NoSuchElementException(String.valueOf(childIndex));
+ }
+
+ return Iterables.get(wrappedData, childIndex);
+ }
+
+ public boolean getAllowsChildren() {
+ return true;
+ }
+
+ public Enumeration<?> children() {
+ if (wrappedData == null) {
+ return Iterators.asEnumeration(Iterators.emptyIterator());
+ }
+
+ return Iterators.asEnumeration(wrappedData.iterator());
+ }
+
+ public Collection<TreeNode> getWrappedData() {
+ return wrappedData;
+ }
+ }
+
+ private boolean asksAllowsChildren = false;
+
+ private Iterator<TreeNode> safeGetChildren(TreeNode treeNode) {
+ if (treeNode == null) {
+ return Iterators.emptyIterator();
+ }
+
+ return Iterators.forEnumeration((Enumeration<TreeNode>) treeNode.children());
+ }
+
+
+ public Object getParentRowKey(Object rowKey) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void setWrappedData(Object data) {
+ setRootNode(new FakeRootNode((Collection<TreeNode>) data));
+ }
+
+ public Collection<TreeNode> getWrappedData() {
+ FakeRootNode rootNode = (FakeRootNode) getRootNode();
+ if (rootNode == null) {
+ return null;
+ }
+ return rootNode.getWrappedData();
+ }
+
+ protected TreeNode findChild(TreeNode parent, Integer simpleKey) {
+ return parent.getChildAt(simpleKey.intValue());
+ }
+
+ public Iterator<TreeDataModelTuple> children() {
+ return new SwingTreeNodeRowKeyIterator(getRowKey(), safeGetChildren(getData()));
+ }
+
+
+ public boolean isLeaf() {
+ if (!asksAllowsChildren) {
+ return getData().isLeaf();
+ } else {
+ return !getData().getAllowsChildren();
+ }
+ }
+
+ @Override
+ protected void walkNext(Integer segment) {
+ TreeNode child = findChild(getData(), segment);
+ //TODO what if node is missing?
+ //TODO - optimize - remove partial keys creation
+ setRowKeyAndData(safeGetRowKey().append(segment), child);
+ }
+<<<<<<< HEAD
+
+=======
+
+>>>>>>> RF-9680
+}
\ No newline at end of file
Added: trunk/ui/iteration/ui/src/main/java/org/richfaces/model/TreeSequenceKeyModel.java.orig
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/model/TreeSequenceKeyModel.java.orig (rev 0)
+++ trunk/ui/iteration/ui/src/main/java/org/richfaces/model/TreeSequenceKeyModel.java.orig 2010-12-02 14:32:03 UTC (rev 20309)
@@ -0,0 +1,180 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.
+ */
+package org.richfaces.model;
+
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.model.DataVisitor;
+import org.ajax4jsf.model.ExtendedDataModel;
+import org.ajax4jsf.model.Range;
+
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public abstract class TreeSequenceKeyModel<K, V> extends ExtendedDataModel<V> implements TreeDataModel<V> {
+
+ private final SequenceRowKey<K> emptyKey = new SequenceRowKey<K>();
+
+<<<<<<< HEAD
+ private V rootNode;
+
+=======
+>>>>>>> RF-9680:
+ private V data;
+
+ private SequenceRowKey<K> rowKey;
+
+ public SequenceRowKey<K> getRowKey() {
+ return rowKey;
+ }
+
+ protected SequenceRowKey<K> safeGetRowKey() {
+ SequenceRowKey<K> key = getRowKey();
+
+ if (key == null) {
+ key = emptyKey;
+ }
+
+ return key;
+ }
+
+ public void setRowKey(Object rowKey) {
+ if (this.rowKey == null || !this.rowKey.equals(rowKey)) {
+<<<<<<< HEAD
+ walkKey((SequenceRowKey<K>) rowKey);
+ }
+ }
+
+ protected void resetRowKeyAndData() {
+ setRowKeyAndData(null, rootNode);
+ }
+
+=======
+ this.rowKey = (SequenceRowKey<K>) rowKey;
+ this.data = findData(this.rowKey);
+ }
+ }
+
+>>>>>>> RF-9680:
+ protected void setRowKeyAndData(SequenceRowKey<K> key, V data) {
+ this.rowKey = key;
+ this.data = data;
+ }
+
+ public boolean isDataAvailable() {
+<<<<<<< HEAD
+ return getRowKey() == null || data != null;
+=======
+ return data != null;
+>>>>>>> RF-9680:
+ }
+
+ public V getData() {
+ if (!isDataAvailable()) {
+ throw new IllegalArgumentException();
+ }
+
+ return data;
+ }
+<<<<<<< HEAD
+
+ protected void walkKey(SequenceRowKey<K> key) {
+ resetRowKeyAndData();
+=======
+
+ protected V findData(SequenceRowKey<K> key) {
+ if (key == null) {
+ return rootNode;
+ }
+
+ V result = rootNode;
+
+ for (K simpleKey : key.getSimpleKeys()) {
+ result = findChild(result, simpleKey);
+>>>>>>> RF-9680:
+
+ if (key != null) {
+ for (K simpleKey: key.getSimpleKeys()) {
+ walkNext(simpleKey);
+ }
+ }
+ }
+
+ protected abstract void walkNext(K segment);
+
+ protected V getRootNode() {
+ return rootNode;
+ }
+
+ protected void setRootNode(V rootNode) {
+ this.rootNode = rootNode;
+ }
+
+ //TODO ExtendedDataModel legacy
+ @Override
+ public void walk(FacesContext context, DataVisitor visitor, Range range, Object argument) {
+ throw new UnsupportedOperationException();
+ }
+
+
+ @Override
+ public boolean isRowAvailable() {
+ return isDataAvailable();
+ }
+
+
+ @Override
+ public int getRowCount() {
+ throw new UnsupportedOperationException();
+ }
+
+
+ @Override
+ public V getRowData() {
+ return getData();
+ }
+
+
+ @Override
+ public int getRowIndex() {
+ throw new UnsupportedOperationException();
+ }
+
+
+ @Override
+ public void setRowIndex(int rowIndex) {
+ throw new UnsupportedOperationException();
+<<<<<<< HEAD
+ }
+
+ public TreeDataModelTuple createSnapshot() {
+ return new TreeDataModelTuple(getRowKey(), getData());
+ }
+
+ public void restoreFromSnapshot(TreeDataModelTuple tuple) {
+ setRowKeyAndData((SequenceRowKey<K>) tuple.getRowKey(), (V) tuple.getData());
+=======
+>>>>>>> RF-9680:
+ }
+}
Added: trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeEncoderBase.java.orig
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeEncoderBase.java.orig (rev 0)
+++ trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeEncoderBase.java.orig 2010-12-02 14:32:03 UTC (rev 20309)
@@ -0,0 +1,227 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.
+ */
+package org.richfaces.renderkit;
+
+import java.io.IOException;
+
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
+import org.ajax4jsf.context.AjaxContext;
+import org.ajax4jsf.javascript.JSFunction;
+import org.richfaces.component.AbstractTree;
+import org.richfaces.component.AbstractTreeNode;
+import org.richfaces.component.util.HtmlUtil;
+import org.richfaces.model.TreeDataModelTuple;
+import org.richfaces.model.TreeDataVisitor;
+
+abstract class TreeEncoderBase implements TreeDataVisitor {
+
+ private static final class QueuedData {
+
+ private enum State {
+ initial, visited, encoded
+ }
+
+ private State state = State.initial;
+
+ private TreeDataModelTuple tuple;
+
+ public QueuedData(TreeDataModelTuple tuple) {
+ super();
+ this.tuple = tuple;
+ }
+
+ public boolean isEncoded() {
+ return state == State.encoded;
+ }
+
+ public void makeEncoded() {
+ this.state = State.encoded;
+ }
+
+ public void makeVisited() {
+ this.state = State.visited;
+ }
+
+ public boolean isVisited() {
+ return state == State.visited;
+ }
+
+ public TreeDataModelTuple getTuple() {
+ return tuple;
+ }
+
+ }
+
+ static final String TREE_NODE_STATE_ATTRIBUTE = "__treeNodeState";
+
+ protected final FacesContext context;
+
+ protected final ResponseWriter responseWriter;
+
+ protected final AbstractTree tree;
+
+<<<<<<< HEAD
+ private LinkedList<QueuedData> queuedDataList = new LinkedList<QueuedData>();
+
+=======
+>>>>>>> RF-9680:
+ public TreeEncoderBase(FacesContext context, AbstractTree tree) {
+ super();
+ this.context = context;
+ this.responseWriter = context.getResponseWriter();
+ this.tree = tree;
+ }
+
+ protected void encodeTree() throws IOException {
+ tree.walkModel(context, this);
+ }
+
+<<<<<<< HEAD
+ protected void flushParentNode() throws IOException {
+ if (queuedDataList.isEmpty()) {
+ return;
+ }
+
+ QueuedData data = queuedDataList.getLast();
+ if (!data.isEncoded()) {
+ data.makeEncoded();
+ tree.restoreFromSnapshot(context, data.getTuple());
+
+ TreeNodeState nodeState = getNodeState(tree.isLeaf(), false);
+
+ writeTreeNodeStartElement(nodeState);
+ tree.findTreeNodeComponent().encodeAll(context);
+ }
+ }
+
+ private TreeNodeState getNodeState(boolean leaf, boolean visited) {
+ TreeNodeState nodeState;
+ if (leaf) {
+ nodeState = TreeNodeState.leaf;
+ } else if (visited) {
+ nodeState = TreeNodeState.expandedNoChildren;
+ } else if (tree.isExpanded()) {
+ nodeState = TreeNodeState.expanded;
+ } else {
+ nodeState = TreeNodeState.collapsed;
+ }
+ return nodeState;
+ }
+
+ public void beforeChildrenVisit() {
+ if (!queuedDataList.isEmpty()) {
+ queuedDataList.getLast().makeVisited();
+ }
+ }
+
+ public void afterChildrenVisit() {
+ }
+
+ public void enterNode() {
+ TreeDataModelTuple tuple = tree.createSnapshot();
+ QueuedData queuedData = new QueuedData(tuple);
+
+ try {
+ flushParentNode();
+ } catch (IOException e) {
+ throw new FacesException(e.getMessage(), e);
+ }
+
+ tree.restoreFromSnapshot(context, tuple);
+ queuedDataList.add(queuedData);
+ }
+
+ public void exitNode() {
+ QueuedData data = queuedDataList.removeLast();
+
+ tree.restoreFromSnapshot(context, data.getTuple());
+ try {
+ if (!data.isEncoded()) {
+ writeTreeNodeStartElement(getNodeState(tree.isLeaf(), data.isVisited()));
+ tree.findTreeNodeComponent().encodeAll(context);
+ }
+
+=======
+ public void enterNode() {
+ TreeNodeState state;
+ if (tree.isLeaf()) {
+ state = TreeNodeState.leaf;
+ } else {
+ if (tree.isExpanded()) {
+ state = TreeNodeState.expanded;
+ } else {
+ state = TreeNodeState.collapsed;
+ }
+ }
+
+ try {
+ writeTreeNodeStartElement(state);
+ tree.findTreeNodeComponent().encodeAll(context);
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ public void exitNode() {
+ try {
+>>>>>>> RF-9680:
+ writeTreeNodeEndElement();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ protected void writeTreeNodeStartElement(TreeNodeState nodeState) throws IOException {
+ AbstractTreeNode treeNodeComponent = tree.findTreeNodeComponent();
+
+ context.getAttributes().put(TREE_NODE_STATE_ATTRIBUTE, nodeState);
+
+ responseWriter.startElement(HtmlConstants.DIV_ELEM, tree);
+ responseWriter.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE,
+ HtmlUtil.concatClasses("rf-tr-nd", nodeState.getNodeClass()),
+ null);
+ responseWriter.writeAttribute(HtmlConstants.ID_ATTRIBUTE, treeNodeComponent.getClientId(context), null);
+
+ emitClientToggleEvent(treeNodeComponent, nodeState);
+ }
+
+ protected void writeTreeNodeEndElement() throws IOException {
+ responseWriter.endElement(HtmlConstants.DIV_ELEM);
+ }
+
+ public abstract void encode() throws IOException;
+
+ private void emitClientToggleEvent(AbstractTreeNode treeNode, TreeNodeState nodeState) {
+ if (treeNode.getClientId(context).equals(context.getAttributes().get(TreeNodeRendererBase.AJAX_TOGGLED_NODE_ATTRIBUTE))) {
+ TreeNodeState initialState = (TreeNodeState) context.getAttributes().get(TreeNodeRendererBase.AJAX_TOGGLED_NODE_STATE_ATTRIBUTE);
+
+ if (initialState.isDifferentThan(nodeState)) {
+ AjaxContext ajaxContext = AjaxContext.getCurrentInstance(context);
+ ajaxContext.appendOncomplete(new JSFunction("RichFaces.ui.TreeNode.emitToggleEvent", treeNode.getClientId(context)));
+ }
+ }
+ }
+}
\ No newline at end of file
13 years, 5 months
JBoss Rich Faces SVN: r20308 - modules/tests/metamer/trunk/application/src/main/webapp/components/richExtendedDataTable.
by richfaces-svn-commits@lists.jboss.org
Author: lfryc(a)redhat.com
Date: 2010-12-02 09:30:09 -0500 (Thu, 02 Dec 2010)
New Revision: 20308
Modified:
modules/tests/metamer/trunk/application/src/main/webapp/components/richExtendedDataTable/selection.xhtml
Log:
extended rich:extendedDataTable selection sample to allow watch both selectionchange and beforeselectionchange events (RFPL-918)
Modified: modules/tests/metamer/trunk/application/src/main/webapp/components/richExtendedDataTable/selection.xhtml
===================================================================
--- modules/tests/metamer/trunk/application/src/main/webapp/components/richExtendedDataTable/selection.xhtml 2010-12-02 14:29:38 UTC (rev 20307)
+++ modules/tests/metamer/trunk/application/src/main/webapp/components/richExtendedDataTable/selection.xhtml 2010-12-02 14:30:09 UTC (rev 20308)
@@ -70,7 +70,10 @@
value="#{richExtendedDataTableBean.state ? model.capitals : null}"
var="record"
>
- <a4j:ajax execute="@this" event="selectionchange" render="selectionOutput" />
+
+
+ <a4j:ajax execute="@this" event="beforeselectionchange" render="previousSelection" />
+ <a4j:ajax execute="@this" event="selectionchange" render="currentSelection" />
<f:facet name="noData">
<h:outputText value="There is no data." style="color: red;"/>
@@ -113,8 +116,11 @@
</rich:extendedDataTable>
<h:panelGrid columns="2">
- <h:outputLabel value="Selection:" />
- <h:outputText id="selectionOutput" value="#{richExtendedDataTableBean.attributes['selection'].value}" />
+ <h:outputLabel value="Previous Selection:" />
+ <h:outputText id="previousSelection" value="#{richExtendedDataTableBean.attributes['selection'].value}" />
+
+ <h:outputLabel value="CurrentSelection:" />
+ <h:outputText id="currentSelection" value="#{richExtendedDataTableBean.attributes['selection'].value}" />
</h:panelGrid>
</ui:define>
13 years, 5 months
JBoss Rich Faces SVN: r20307 - modules/tests/metamer/trunk/application/src/main/webapp/components/richExtendedDataTable.
by richfaces-svn-commits@lists.jboss.org
Author: lfryc(a)redhat.com
Date: 2010-12-02 09:29:38 -0500 (Thu, 02 Dec 2010)
New Revision: 20307
Added:
modules/tests/metamer/trunk/application/src/main/webapp/components/richExtendedDataTable/selection.xhtml
Modified:
modules/tests/metamer/trunk/application/src/main/webapp/components/richExtendedDataTable/list.xhtml
Log:
added sample of rich:extendedDataTable selection (RFPL-918)
Modified: modules/tests/metamer/trunk/application/src/main/webapp/components/richExtendedDataTable/list.xhtml
===================================================================
--- modules/tests/metamer/trunk/application/src/main/webapp/components/richExtendedDataTable/list.xhtml 2010-12-02 14:29:04 UTC (rev 20306)
+++ modules/tests/metamer/trunk/application/src/main/webapp/components/richExtendedDataTable/list.xhtml 2010-12-02 14:29:38 UTC (rev 20307)
@@ -64,6 +64,10 @@
<metamer:testPageLink id="filtering" outcome="filtering" value="Table Filtering">
Page that contains filterable <b>rich:extendedDataTable</b> (with model containing capitals) and input boxes for all its attributes.
</metamer:testPageLink>
+
+ <metamer:testPageLink id="selection" outcome="selection" value="Selection">
+ Page that contains sample of <b>rich:extendedDataTable</b> selection model
+ </metamer:testPageLink>
</ui:define>
</ui:composition>
Added: modules/tests/metamer/trunk/application/src/main/webapp/components/richExtendedDataTable/selection.xhtml
===================================================================
--- modules/tests/metamer/trunk/application/src/main/webapp/components/richExtendedDataTable/selection.xhtml (rev 0)
+++ modules/tests/metamer/trunk/application/src/main/webapp/components/richExtendedDataTable/selection.xhtml 2010-12-02 14:29:38 UTC (rev 20307)
@@ -0,0 +1,173 @@
+<?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:a4j="http://richfaces.org/a4j"
+ xmlns:metamer="http://java.sun.com/jsf/composite/metamer" xmlns:rich="http://richfaces.org/rich">
+
+ <!--
+JBoss, Home of Professional Open Source
+Copyright 2010, 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="head">
+ <f:metadata>
+ <f:viewParam name="templates" value="#{templateBean.templates}">
+ <f:converter converterId="templatesListConverter" />
+ </f:viewParam>
+ </f:metadata>
+ <style type="text/css">
+ .rf-edt {
+ width: 300px !important;
+ height: 300px !important;
+ }
+ </style>
+ </ui:define>
+
+ <ui:define name="outOfTemplateBefore">
+ <br/>
+ <h:outputText value="Show data in table: " />
+ <h:selectBooleanCheckbox id="noDataCheckbox" value="#{richExtendedDataTableBean.state}">
+ <a4j:ajax render="richEDT scroller1"/>
+ </h:selectBooleanCheckbox>
+ <br/><br/>
+ <rich:dataScroller id="scroller1" for="richEDT" page="#{richExtendedDataTableBean.page}" maxPages="7" render="richEDT"/>
+ </ui:define>
+
+ <ui:define name="component">
+
+ <rich:extendedDataTable id="richEDT"
+ beforeselectionchange="#{richExtendedDataTableBean.attributes['beforeselectionchange'].value}"
+ first="#{richExtendedDataTableBean.attributes['first'].value}"
+ frozenColumns="#{richExtendedDataTableBean.attributes['frozenColumns'].value}"
+ noDataLabel="#{richExtendedDataTableBean.attributes['noDataLabel'].value}"
+ rendered="#{richExtendedDataTableBean.attributes['rendered'].value}"
+ rows="#{richExtendedDataTableBean.attributes['rows'].value}"
+ selection="#{richExtendedDataTableBean.attributes['selection'].value}"
+ selectionchange="#{richExtendedDataTableBean.attributes['selectionchange'].value}"
+ sortMode="#{richExtendedDataTableBean.attributes['sortMode'].value}"
+ sortPriority="#{richExtendedDataTableBean.attributes['sortPriority'].value}"
+ style="#{richExtendedDataTableBean.attributes['style'].value}"
+ styleClass="#{richExtendedDataTableBean.attributes['styleClass'].value}"
+ value="#{richExtendedDataTableBean.state ? model.capitals : null}"
+ var="record"
+ >
+ <a4j:ajax execute="@this" event="selectionchange" render="selectionOutput" />
+
+ <f:facet name="noData">
+ <h:outputText value="There is no data." style="color: red;"/>
+ </f:facet>
+
+ <f:facet name="caption">
+ <h:outputText id="captionFacet" value="Caption Facet" />
+ </f:facet>
+
+ <f:facet name="header">
+ <h:outputText value="Header Facet" />
+ </f:facet>
+
+ <rich:column id="columnState" sortBy="#{record.state}">
+ <f:facet name="header">
+ <h:outputText id="columnHeaderState" value="State" />
+ </f:facet>
+
+ <h:outputText value="#{record.state}" />
+ <f:facet name="footer">
+ <h:outputText id="columnFooterState" value="State" />
+ </f:facet>
+ </rich:column>
+
+ <rich:column id="columnCapital" sortBy="#{record.name}">
+ <f:facet name="header">
+ <h:outputText id="columnHeaderCapital" value="Capital" />
+ </f:facet>
+
+ <h:outputText value="#{record.name}" />
+ <f:facet name="footer">
+ <h:outputText id="columnFooterCapital" value="Capital" />
+ </f:facet>
+ </rich:column>
+
+ <f:facet name="footer">
+ <rich:dataScroller id="scroller2" for="richEDT" page="#{richExtendedDataTableBean.page}" maxPages="7" render="richEDT" />
+ </f:facet>
+
+ </rich:extendedDataTable>
+
+ <h:panelGrid columns="2">
+ <h:outputLabel value="Selection:" />
+ <h:outputText id="selectionOutput" value="#{richExtendedDataTableBean.attributes['selection'].value}" />
+ </h:panelGrid>
+ </ui:define>
+
+ <ui:define name="outOfTemplateAfter">
+ <fieldset>
+ <legend>scroller1</legend>
+
+ <h:commandButton id="buttonFirst1" value="<< first">
+ <rich:componentControl event="click" target="#{rich:clientId('scroller1')}" operation="switchToPage">
+ <f:param value="first" />
+ </rich:componentControl>
+ </h:commandButton>
+
+ <h:commandButton id="buttonPrev1" value="< previous">
+ <rich:componentControl event="click" target="#{rich:clientId('scroller1')}" operation="previous" />
+ </h:commandButton>
+
+ <h:commandButton id="buttonNext1" value="next >">
+ <rich:componentControl event="click" target="#{rich:clientId('scroller1')}" operation="next" />
+ </h:commandButton>
+
+ <h:commandButton id="buttonLast1" value="last >>">
+ <rich:componentControl event="click" target="#{rich:clientId('scroller1')}" operation="switchToPage">
+ <f:param value="last" />
+ </rich:componentControl>
+ </h:commandButton>
+ </fieldset>
+
+ <fieldset>
+ <legend>scroller2</legend>
+ <h:commandButton id="buttonFirst2" value="<< first">
+ <rich:componentControl event="click" target="#{rich:clientId('scroller2')}" operation="switchToPage">
+ <f:param value="first" />
+ </rich:componentControl>
+ </h:commandButton>
+
+ <h:commandButton id="buttonPrev2" value="< previous">
+ <rich:componentControl event="click" target="#{rich:clientId('scroller2')}" operation="previous" />
+ </h:commandButton>
+
+ <h:commandButton id="buttonNext2" value="next >">
+ <rich:componentControl event="click" target="#{rich:clientId('scroller2')}" operation="next" />
+ </h:commandButton>
+
+ <h:commandButton id="buttonLast2" value="last >>">
+ <rich:componentControl event="click" target="#{rich:clientId('scroller2')}" operation="switchToPage">
+ <f:param value="last" />
+ </rich:componentControl>
+ </h:commandButton>
+ </fieldset>
+
+ <metamer:attributes value="#{richExtendedDataTableBean.attributes}" id="attributes" />
+ </ui:define>
+
+ </ui:composition>
+</html>
\ No newline at end of file
13 years, 5 months
JBoss Rich Faces SVN: r20306 - in modules/tests/metamer/trunk/application/src/main/webapp/components: richExtendedDataTable and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: lfryc(a)redhat.com
Date: 2010-12-02 09:29:04 -0500 (Thu, 02 Dec 2010)
New Revision: 20306
Modified:
modules/tests/metamer/trunk/application/src/main/webapp/components/richDataTable/filtering.xhtml
modules/tests/metamer/trunk/application/src/main/webapp/components/richExtendedDataTable/filtering.xhtml
Log:
added issue tracking for RF-9900
Modified: modules/tests/metamer/trunk/application/src/main/webapp/components/richDataTable/filtering.xhtml
===================================================================
--- modules/tests/metamer/trunk/application/src/main/webapp/components/richDataTable/filtering.xhtml 2010-12-02 14:07:40 UTC (rev 20305)
+++ modules/tests/metamer/trunk/application/src/main/webapp/components/richDataTable/filtering.xhtml 2010-12-02 14:29:04 UTC (rev 20306)
@@ -150,7 +150,7 @@
<!-- <a4j:ajax render="commonGrid" /> -->
</rich:inputNumberSlider>
<br />
- (DOESN'T WORK, NOT REPORTED YET (causes continuous refreshing of page))
+ (a4j:ajax disabled - RF-9900)
</f:facet>
<h:outputText value="#{record.numberOfKids}" />
Modified: modules/tests/metamer/trunk/application/src/main/webapp/components/richExtendedDataTable/filtering.xhtml
===================================================================
--- modules/tests/metamer/trunk/application/src/main/webapp/components/richExtendedDataTable/filtering.xhtml 2010-12-02 14:07:40 UTC (rev 20305)
+++ modules/tests/metamer/trunk/application/src/main/webapp/components/richExtendedDataTable/filtering.xhtml 2010-12-02 14:29:04 UTC (rev 20306)
@@ -207,7 +207,7 @@
<!-- <a4j:ajax render="commonGrid" /> -->
</rich:inputNumberSlider>
<br />
- (DOESN'T WORK, NOT REPORTED YET (causes continuous refreshing of page))
+ (a4j:ajax disabled - RF-9900)
</f:facet>
<h:outputText value="#{record.numberOfKids}" />
13 years, 5 months
JBoss Rich Faces SVN: r20305 - in trunk/ui/input/ui/src/main: templates and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: abelevich
Date: 2010-12-02 09:07:40 -0500 (Thu, 02 Dec 2010)
New Revision: 20305
Modified:
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/select.ecss
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/select.js
trunk/ui/input/ui/src/main/templates/select.template.xml
Log:
RF-9576
Modified: trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/select.ecss
===================================================================
--- trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/select.ecss 2010-12-02 13:25:54 UTC (rev 20304)
+++ trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/select.ecss 2010-12-02 14:07:40 UTC (rev 20305)
@@ -1,4 +1,3 @@
-
.rf-sel-inp, .rf-sel-opt {
color: '#{richSkin.generalTextColor}';
font-size: '#{richSkin.generalSizeFont}';
@@ -9,30 +8,42 @@
border-width: 0px;
background: none;
width: 100%;
+ color: '#{richSkin.generalTextColor}';
+ font-size: '#{richSkin.generalSizeFont}';
+ font-family: '#{richSkin.generalFamilyFont}';
}
+.rf-sel{
+ width:200px;
+ display:inline-block;
+}
+
.rf-sel-fld{
- width: 200px;
- position: inline-block;
border-width: 1px;
border-style: solid;
border-color: '#{richSkin.panelBorderColor}';
- display: inline-block;
background-image: "url(#{resource['org.richfaces.renderkit.html.images.AutocompleteFieldGradient']})";
background-repeat: repeat-x;
background-position: top left;
background-color: '#{richSkin.controlBackgroundColor}';
+ width: 100%;
}
+.rf-sel-fld-err input{
+ color: #FF0000;
+}
+
.rf-sel-btn{
background-image: "url(#{resource['org.richfaces.renderkit.html.images.AutocompleteButtonGradient']})";
background-repeat: repeat-x;
background-position: top left;
background-color: '#{richSkin.headerBackgroundColor}';
text-align: center;
- border-left-style: solid;
- border-left-width: 1px;
- border-left-color: '#{richSkin.panelBorderColor}';
+ border-style: solid;
+ border-width: 1px;
+ border-color: '#{richSkin.panelBorderColor}';
+ border-left-width: 0px;
+
width: 15px;
position: absolute;
top: 0px;
Modified: trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/select.js
===================================================================
--- trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/select.js 2010-12-02 13:25:54 UTC (rev 20304)
+++ trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/select.js 2010-12-02 14:07:40 UTC (rev 20305)
@@ -109,7 +109,9 @@
var inputLabel = this.getValue() ;
this.initialValue = (inputLabel != this.defaultLabel) ? inputLabel : "";
this.selValueInput = $(document.getElementById(id+"selValue"));
+ this.field = $(document.getElementById(id+"Field"));
this.clientItems = mergedOptions.items;
+
if(mergedOptions.showControl) {
this.btn = $(document.getElementById(id+"Button"));
@@ -242,6 +244,14 @@
var newValue = this.getValue();
if(this.cache && this.cache.isCached(newValue)) {
this.__updateItems();
+
+ var items = this.popupList.__getItems();
+ if(items.length != 0) {
+ this.field.removeClass("rf-sel-fld-err");
+ } else {
+ this.field.addClass("rf-sel-fld-err");
+ }
+
if(!this.popupList.isVisible()) {
this.showPopup();
}
@@ -316,7 +326,9 @@
}
});
} else {
- var prevValue = this.selValueInput.val();
+ this.field.removeClass("rf-sel-fld-err");
+
+ var prevValue = this.selValueInput.val();
if(prevValue && prevValue != "") {
$.each(this.clientItems, function() {
if(this.value == prevValue) {
@@ -328,6 +340,7 @@
}
}
}
+
this.setValue(label);
this.selValueInput.val(value);
this.focused = false;
Modified: trunk/ui/input/ui/src/main/templates/select.template.xml
===================================================================
--- trunk/ui/input/ui/src/main/templates/select.template.xml 2010-12-02 13:25:54 UTC (rev 20304)
+++ trunk/ui/input/ui/src/main/templates/select.template.xml 2010-12-02 14:07:40 UTC (rev 20305)
@@ -19,19 +19,20 @@
<cdk:object type="java.lang.Object" name="disabled" value="#{component.attributes['disabled']}" />
- <div id="#{clientId}" class="rf-sel-fld">
- <div style="position : relative; overflow : hidden; text-align : left; padding-right : 21px;">
+ <div id="#{clientId}" class="rf-sel">
+ <div style="position : relative; overflow : hidden; text-align : left; padding-right : 18px;">
<input id="#{clientId}selValue" name="#{clientId}" type="hidden" value="#{getInputValue(facesContext, component)}"/>
- <input cdk:passThroughWithExclusions="class autocomplete id value disabled name type readonly"
- id="#{clientId}Input"
- value="#{getSelectLabel(facesContext, component)}"
- disabled="#{disabled}"
- name="#{clientId}Input"
- type="text"
- class="rf-sel-fnt rf-sel-inp"
- autocomplete="off"
- readonly="#{component.attributes['enableManualInput'] ? '' : 'readonly'}"/>
-
+ <div id="#{clientId}Field" class="rf-sel-fld">
+ <input cdk:passThroughWithExclusions="class autocomplete id value disabled name type readonly"
+ id="#{clientId}Input"
+ value="#{getSelectLabel(facesContext, component)}"
+ disabled="#{disabled}"
+ name="#{clientId}Input"
+ type="text"
+ class="rf-sel-inp"
+ autocomplete="off"
+ readonly="#{component.attributes['enableManualInput'] ? '' : 'readonly'}"/>
+ </div>
<c:if test="#{component.attributes['showButton']}">
<c:if test="#{component.attributes['disabled']}">
<div id="#{clientId}Button" class="rf-sel-btn">
13 years, 5 months
JBoss Rich Faces SVN: r20304 - in modules/tests/metamer/trunk: ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTab and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: ppitonak(a)redhat.com
Date: 2010-12-02 08:25:54 -0500 (Thu, 02 Dec 2010)
New Revision: 20304
Modified:
modules/tests/metamer/trunk/application/src/main/webapp/components/richTab/simple.xhtml
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTab/TestRichTab.java
Log:
https://jira.jboss.org/browse/RFPL-875
* added buttons for switching tabs
* added a test for attribute name
Modified: modules/tests/metamer/trunk/application/src/main/webapp/components/richTab/simple.xhtml
===================================================================
--- modules/tests/metamer/trunk/application/src/main/webapp/components/richTab/simple.xhtml 2010-12-02 13:20:26 UTC (rev 20303)
+++ modules/tests/metamer/trunk/application/src/main/webapp/components/richTab/simple.xhtml 2010-12-02 13:25:54 UTC (rev 20304)
@@ -94,6 +94,25 @@
</rich:tab>
</rich:tabPanel>
+ <br/><br/>
+
+ <h:commandButton id="firstTabButton" value="First tab">
+ <rich:toggleControl targetPanel="tabPanel" targetItem="@first" />
+ </h:commandButton>
+ <h:commandButton id="prevTabButton" value="Previous tab">
+ <rich:toggleControl targetPanel="tabPanel" targetItem="@prev" />
+ </h:commandButton>
+ <h:commandButton id="nextTabButton" value="Next tab">
+ <rich:toggleControl targetPanel="tabPanel" targetItem="@next" />
+ </h:commandButton>
+ <h:commandButton id="lastTabButton" value="Last tab">
+ <rich:toggleControl targetPanel="tabPanel" targetItem="@last" />
+ </h:commandButton>
+ <h:commandButton id="customTabButton" value="Custon tab (#{richTabBean.attributes['name'].value})">
+ <rich:toggleControl targetPanel="tabPanel" targetItem="#{richTabBean.attributes['name'].value}" />
+ </h:commandButton>
+
+
</ui:define>
<ui:define name="outOfTemplateAfter">
Modified: modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTab/TestRichTab.java
===================================================================
--- modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTab/TestRichTab.java 2010-12-02 13:20:26 UTC (rev 20303)
+++ modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTab/TestRichTab.java 2010-12-02 13:25:54 UTC (rev 20304)
@@ -223,6 +223,18 @@
}
@Test
+ public void testName() {
+ selenium.type(pjq("input[type=text][id$=nameInput]"), "metamer");
+ selenium.waitForPageToLoad();
+
+ selenium.click(pjq("input[id$=lastTabButton]"));
+ waitGui.failWith("Item 3 was not displayed.").until(isDisplayed.locator(itemContents[4]));
+
+ selenium.click(pjq("input[id$=customTabButton]"));
+ waitGui.failWith("Item 1 was not displayed.").until(isDisplayed.locator(itemContents[0]));
+ }
+
+ @Test
public void testOnclick() {
testFireEvent(Event.CLICK, tab);
}
13 years, 5 months