You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2011/11/24 17:19:50 UTC

svn commit: r1205908 - in /myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago: internal/component/AbstractUITreeData.java internal/util/StringUtils.java model/TreePath.java

Author: lofwyr
Date: Thu Nov 24 16:19:46 2011
New Revision: 1205908

URL: http://svn.apache.org/viewvc?rev=1205908&view=rev
Log:
TOBAGO-1053: Using partial rendering (AJAX) in tc:tree doesn't call the action and actionListener

Modified:
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITreeData.java
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/StringUtils.java
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/TreePath.java

Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITreeData.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITreeData.java?rev=1205908&r1=1205907&r2=1205908&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITreeData.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITreeData.java Thu Nov 24 16:19:46 2011
@@ -18,6 +18,7 @@ package org.apache.myfaces.tobago.intern
  */
 
 import org.apache.commons.lang.ObjectUtils;
+import org.apache.myfaces.tobago.compat.FacesUtils;
 import org.apache.myfaces.tobago.component.TreeModelBuilder;
 import org.apache.myfaces.tobago.model.MixedTreeModel;
 import org.apache.myfaces.tobago.model.Node;
@@ -25,6 +26,8 @@ import org.apache.myfaces.tobago.model.T
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import javax.faces.FacesException;
+import javax.faces.component.ContextCallback;
 import javax.faces.component.NamingContainer;
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
@@ -358,6 +361,43 @@ public abstract class AbstractUITreeData
     }
   }
 
+  public boolean invokeOnComponent(FacesContext facesContext, String clientId, ContextCallback callback)
+      throws FacesException {
+    TreePath oldRowIndex = getRowIndex();
+    try {
+      String sheetId = getClientId(facesContext);
+      if (clientId.startsWith(sheetId)) {
+        String idRemainder = clientId.substring(sheetId.length());
+        if (LOG.isDebugEnabled()) {
+          LOG.debug("idRemainder = '" + idRemainder + "'");
+        }
+        if (idRemainder.matches("^:(_\\d+)+:.*")) {
+          idRemainder = idRemainder.substring(1);
+          int idx = idRemainder.indexOf(":");
+          try {
+            TreePath rowIndex = new TreePath(idRemainder.substring(0, idx));
+            if (LOG.isDebugEnabled()) {
+              LOG.debug("set rowIndex = '" + rowIndex + "'");
+            }
+            setRowIndex(facesContext, rowIndex);
+          } catch (NumberFormatException e) {
+            LOG.warn("idRemainder = '" + idRemainder + "'", e);
+          }
+        } else {
+          if (LOG.isDebugEnabled()) {
+            LOG.debug("no match for '^:(_\\d+)+:.*'");
+          }
+        }
+      }
+
+      return FacesUtils.invokeOnComponent(facesContext, this, clientId, callback);
+
+    } finally {
+      // we should reset rowIndex on UISheet
+      setRowIndex(facesContext, oldRowIndex);
+    }
+  }
+
   @Override
   public Object saveState(FacesContext context) {
     Object[] state = new Object[2];

Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/StringUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/StringUtils.java?rev=1205908&r1=1205907&r2=1205908&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/StringUtils.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/StringUtils.java Thu Nov 24 16:19:46 2011
@@ -28,11 +28,14 @@ public final class StringUtils {
     // utils class
   }
 
-  public static List<Integer> parseIntegerList(String integerList)
-      throws NumberFormatException {
+  public static List<Integer> parseIntegerList(String integerList) throws NumberFormatException {
+    return parseIntegerList(integerList, ", ");
+  }
+
+  public static List<Integer> parseIntegerList(String integerList, String delimiters) throws NumberFormatException {
     List<Integer> list = new ArrayList<Integer>();
 
-    StringTokenizer tokenizer = new StringTokenizer(integerList, ", ");
+    StringTokenizer tokenizer = new StringTokenizer(integerList, delimiters);
     while (tokenizer.hasMoreElements()) {
       String token = tokenizer.nextToken().trim();
       if (token.length() > 0) {

Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/TreePath.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/TreePath.java?rev=1205908&r1=1205907&r2=1205908&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/TreePath.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/TreePath.java Thu Nov 24 16:19:46 2011
@@ -17,6 +17,8 @@ package org.apache.myfaces.tobago.model;
  * limitations under the License.
  */
 
+import org.apache.myfaces.tobago.internal.util.StringUtils;
+
 import javax.swing.tree.DefaultMutableTreeNode;
 import java.io.Serializable;
 import java.util.Arrays;
@@ -50,6 +52,10 @@ public class TreePath implements Seriali
     path[position.path.length] = addendum;
   }
 
+  public TreePath(String string) throws NumberFormatException {
+    this(StringUtils.parseIntegerList(string, "_"));
+  }
+
   public int[] getPath() {
     return path;
   }
@@ -59,21 +65,23 @@ public class TreePath implements Seriali
   }
 
   public String getPathString() {
-    StringBuffer buffer = new StringBuffer();
+    StringBuilder builder = new StringBuilder();
     for (int item : path) {
-      buffer.append("_");
-      buffer.append(item);
+      builder.append("_");
+      builder.append(item);
     }
-    return buffer.toString();
+    return builder.toString();
   }
 
+  /** @deprecated */
+  @Deprecated
   public String getParentPathString() {
-    StringBuffer buffer = new StringBuffer();
+    StringBuilder builder = new StringBuilder();
     for (int i = 0; i < path.length - 1; i++) {
-      buffer.append("_");
-      buffer.append(path[i]);
+      builder.append("_");
+      builder.append(path[i]);
     }
-    return buffer.toString();
+    return builder.toString();
   }
 
   /**