[richfaces-svn-commits] JBoss Rich Faces SVN: r18776 - in trunk: ui/common/ui/src/main/java/org/richfaces/renderkit/util and 4 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Wed Aug 18 15:41:15 EDT 2010


Author: Alex.Kolonitsky
Date: 2010-08-18 15:41:15 -0400 (Wed, 18 Aug 2010)
New Revision: 18776

Modified:
   trunk/examples/output-demo/src/main/webapp/examples/togglePanel-mixed.xhtml
   trunk/ui/common/ui/src/main/java/org/richfaces/renderkit/util/FormUtil.java
   trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractTogglePanel.java
   trunk/ui/output/ui/src/main/java/org/richfaces/component/UITogglePanel.java
   trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelRenderer.java
   trunk/ui/output/ui/src/main/resources/META-INF/pn.faces-config.xml
   trunk/ui/output/ui/src/main/resources/META-INF/pn.taglib.xml
   trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/TogglePanel.js
Log:
RF-9009 switchablePanel's: improve cycled switching

Modified: trunk/examples/output-demo/src/main/webapp/examples/togglePanel-mixed.xhtml
===================================================================
--- trunk/examples/output-demo/src/main/webapp/examples/togglePanel-mixed.xhtml	2010-08-18 19:08:04 UTC (rev 18775)
+++ trunk/examples/output-demo/src/main/webapp/examples/togglePanel-mixed.xhtml	2010-08-18 19:41:15 UTC (rev 18776)
@@ -13,7 +13,7 @@
 
     <ui:define name="body">
         <h:form id="f">
-            <pn:togglePanel id="panel" activeItem="name1" switchType="client" lang="en">
+            <pn:togglePanel id="panel" activeItem="name1" switchType="client" lang="en" cycledSwitching="true" >
                 <pn:togglePanelItem name="name1">hello name1 client</pn:togglePanelItem>
                 <pn:togglePanelItem name="name2" switchType="ajax">hello name2 ajax</pn:togglePanelItem>
                 <pn:togglePanelItem name="name3" switchType="server">hello name3 server</pn:togglePanelItem>

Modified: trunk/ui/common/ui/src/main/java/org/richfaces/renderkit/util/FormUtil.java
===================================================================
--- trunk/ui/common/ui/src/main/java/org/richfaces/renderkit/util/FormUtil.java	2010-08-18 19:08:04 UTC (rev 18775)
+++ trunk/ui/common/ui/src/main/java/org/richfaces/renderkit/util/FormUtil.java	2010-08-18 19:41:15 UTC (rev 18776)
@@ -44,7 +44,7 @@
 
         // TODO nick -> nick - switchType checking can be harmful here
         SwitchType switchType = (SwitchType) component.getAttributes().get("switchType");
-        boolean isSwitchTypeClient = (switchType != null) && SwitchType.client == switchType;
+        boolean isSwitchTypeClient = SwitchType.client == switchType;
 
         if ((form == null) && !isSwitchTypeClient) {
             throw new EnclosingFormRequiredException(component.getClass().toString() + " (id=\"" + component.getId()

Modified: trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractTogglePanel.java
===================================================================
--- trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractTogglePanel.java	2010-08-18 19:08:04 UTC (rev 18775)
+++ trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractTogglePanel.java	2010-08-18 19:41:15 UTC (rev 18776)
@@ -445,11 +445,14 @@
     
     public AbstractTogglePanelItem getItemByIndex(final int index) {
         List<AbstractTogglePanelItem> children = getRenderedChildren();
-        if (index < 0 || index >= children.size()) {
+        if (isCycledSwitching()) {
+            int size = getRenderedChildren().size();
+            return children.get((size + index) % size);
+        } else if (index < 0 || index >= children.size()) {
             return null;
+        } else {
+            return children.get(index);
         }
-
-        return children.get(index);
     }
 
     private List<AbstractTogglePanelItem> getRenderedChildren() {
@@ -552,6 +555,8 @@
 
     public abstract boolean isLimitToList();
 
+    public abstract boolean isCycledSwitching();
+
     public abstract Object getData();
 
     public abstract String getStatus();

Modified: trunk/ui/output/ui/src/main/java/org/richfaces/component/UITogglePanel.java
===================================================================
--- trunk/ui/output/ui/src/main/java/org/richfaces/component/UITogglePanel.java	2010-08-18 19:08:04 UTC (rev 18775)
+++ trunk/ui/output/ui/src/main/java/org/richfaces/component/UITogglePanel.java	2010-08-18 19:41:15 UTC (rev 18776)
@@ -34,6 +34,7 @@
         switchType,
         bypassUpdates,
         limitToList,
+        cycledSwitching,
         data,
         status,
         execute,
@@ -65,6 +66,14 @@
         getStateHelper().put(PropertyKeys.limitToList, limitToList);
     }
 
+    public boolean isCycledSwitching() {
+        return Boolean.valueOf(String.valueOf(getStateHelper().eval(PropertyKeys.cycledSwitching, false)));
+    }
+
+    public void setCycledSwitching(boolean cycledSwitching) {
+        getStateHelper().put(PropertyKeys.cycledSwitching, cycledSwitching);
+    }
+
     public Object getData() {
         return getStateHelper().eval(PropertyKeys.data);
     }

Modified: trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelRenderer.java
===================================================================
--- trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelRenderer.java	2010-08-18 19:08:04 UTC (rev 18775)
+++ trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelRenderer.java	2010-08-18 19:41:15 UTC (rev 18776)
@@ -143,6 +143,7 @@
 
         Map<String, Object> options = new HashMap<String, Object>(5);
         options.put("activeItem", panel.getActiveItem());
+        options.put("cycledSwitching", panel.isCycledSwitching());
         options.put("items", getChildrenScriptObjects(context, panel));
         options.put("ajax", getAjaxOptions(context, panel));
 

Modified: trunk/ui/output/ui/src/main/resources/META-INF/pn.faces-config.xml
===================================================================
--- trunk/ui/output/ui/src/main/resources/META-INF/pn.faces-config.xml	2010-08-18 19:08:04 UTC (rev 18775)
+++ trunk/ui/output/ui/src/main/resources/META-INF/pn.faces-config.xml	2010-08-18 19:41:15 UTC (rev 18776)
@@ -35,6 +35,11 @@
         </property>
         <property>
             <description></description>
+            <property-name>cycledSwitching</property-name>
+            <property-class>boolean</property-class>
+        </property>
+        <property>
+            <description></description>
             <property-name>data</property-name>
             <property-class>java.lang.Object</property-class>
         </property>
@@ -275,6 +280,11 @@
         </property>
         <property>
             <description></description>
+            <property-name>cycledSwitching</property-name>
+            <property-class>boolean</property-class>
+        </property>
+        <property>
+            <description></description>
             <property-name>data</property-name>
             <property-class>java.lang.Object</property-class>
         </property>

Modified: trunk/ui/output/ui/src/main/resources/META-INF/pn.taglib.xml
===================================================================
--- trunk/ui/output/ui/src/main/resources/META-INF/pn.taglib.xml	2010-08-18 19:08:04 UTC (rev 18775)
+++ trunk/ui/output/ui/src/main/resources/META-INF/pn.taglib.xml	2010-08-18 19:41:15 UTC (rev 18776)
@@ -57,6 +57,11 @@
         </attribute>
         <attribute>
             <description></description>
+            <name>cycledSwitching</name>
+            <type>boolean</type>
+        </attribute>
+        <attribute>
+            <description></description>
             <name>data</name>
             <type>java.lang.Object</type>
         </attribute>
@@ -343,6 +348,11 @@
         </attribute>
         <attribute>
             <description></description>
+            <name>cycledSwitching</name>
+            <type>boolean</type>
+        </attribute>
+        <attribute>
+            <description></description>
             <name>data</name>
             <type>java.lang.Object</type>
         </attribute>

Modified: trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/TogglePanel.js
===================================================================
--- trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/TogglePanel.js	2010-08-18 19:08:04 UTC (rev 18775)
+++ trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/TogglePanel.js	2010-08-18 19:41:15 UTC (rev 18776)
@@ -313,7 +313,7 @@
          */
         prevItem: function (itemName) {
             var itemIndex = this.__getItemIndex(itemName || this.activeItem);
-            if (itemIndex < 1) {
+            if (!this.options.cycledSwitching && itemIndex < 1) {
                 return null;
             }
 
@@ -355,11 +355,14 @@
          *    null - if item not found
          * */
         __getItem : function (index) {
-            if (index >= 0 && index < this.items.length) {
+            if (this.options.cycledSwitching) {
+                var size = this.items.length;
+                return this.items[(size + index) % size]
+            } else if (index >= 0 && index < this.items.length) {
                 return this.items[index]
+            } else {
+                return null;
             }
-
-            return null;
         },
 
         __getItemByName : function (name) {



More information about the richfaces-svn-commits mailing list