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 2013/04/09 15:44:55 UTC

svn commit: r1466029 - in /myfaces/tobago/trunk: tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/ tobago-core/src/main/java/org/apache/myfaces/tobago/model/ tobago-core/src/main/java/org/apache/myfaces/tobago/webapp/ tobago-examp...

Author: lofwyr
Date: Tue Apr  9 13:44:54 2013
New Revision: 1466029

URL: http://svn.apache.org/r1466029
Log:
TOBAGO-1244: tc:columnSelector and tc:treeSelect should work in the same manner
 - implementing value "selection" for treeSelect

Added:
    myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/tree/tree-select-via-state.xhtml
      - copied, changed from r1463501, myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/tree/tree-select.xhtml
    myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/tree/tree-select-via-value.xhtml
      - copied, changed from r1464994, myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/tree/tree-select.xhtml
Removed:
    myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/tree/tree-select.xhtml
Modified:
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIData.java
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUISheet.java
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITree.java
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITreeSelect.java
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/SelectedState.java
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/SheetState.java
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoServletContextListener.java
    myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeSelectRenderer.java
    myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-tree.js

Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIData.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIData.java?rev=1466029&r1=1466028&r2=1466029&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIData.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIData.java Tue Apr  9 13:44:54 2013
@@ -23,6 +23,7 @@ import org.apache.myfaces.tobago.compat.
 import org.apache.myfaces.tobago.component.Attributes;
 import org.apache.myfaces.tobago.model.ExpandedState;
 import org.apache.myfaces.tobago.model.Selectable;
+import org.apache.myfaces.tobago.model.SelectedState;
 import org.apache.myfaces.tobago.model.TreeDataModel;
 import org.apache.myfaces.tobago.model.TreeNodeDataModel;
 import org.apache.myfaces.tobago.model.TreePath;
@@ -129,6 +130,8 @@ public abstract class AbstractUIData ext
 
   public abstract ExpandedState getExpandedState();
 
+  public abstract SelectedState getSelectedState();
+
   /**
    * @deprecated The name of this method is ambiguous.
    * You may use the inverse of {@link #isRowsUnlimited()}. Deprecated since 1.5.5.

Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUISheet.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUISheet.java?rev=1466029&r1=1466028&r2=1466029&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUISheet.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUISheet.java Tue Apr  9 13:44:54 2013
@@ -40,6 +40,7 @@ import org.apache.myfaces.tobago.layout.
 import org.apache.myfaces.tobago.layout.LayoutManager;
 import org.apache.myfaces.tobago.layout.LayoutTokens;
 import org.apache.myfaces.tobago.model.ExpandedState;
+import org.apache.myfaces.tobago.model.SelectedState;
 import org.apache.myfaces.tobago.model.SheetState;
 import org.apache.myfaces.tobago.renderkit.LayoutComponentRenderer;
 import org.apache.myfaces.tobago.util.ComponentUtils;
@@ -643,6 +644,11 @@ public abstract class AbstractUISheet ex
     return getState().getExpandedState();
   }
 
+  @Override
+  public SelectedState getSelectedState() {
+    return getState().getSelectedState();
+  }
+
   public Grid getHeaderGrid() {
     return headerGrid;
   }

Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITree.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITree.java?rev=1466029&r1=1466028&r2=1466029&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITree.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITree.java Tue Apr  9 13:44:54 2013
@@ -226,6 +226,7 @@ public abstract class AbstractUITree ext
     return state;
   }
 
+  @Override
   public SelectedState getSelectedState() {
     return getState().getSelectedState();
   }
@@ -235,12 +236,14 @@ public abstract class AbstractUITree ext
     return getState().getExpandedState();
   }
 
+  @Override
   public void restoreState(FacesContext context, Object componentState) {
     Object[] values = (Object[]) componentState;
     super.restoreState(context, values[0]);
     state = (TreeState) values[1];
   }
 
+  @Override
   public Object saveState(FacesContext context) {
     Object[] values = new Object[2];
     values[0] = super.saveState(context);

Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITreeSelect.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITreeSelect.java?rev=1466029&r1=1466028&r2=1466029&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITreeSelect.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITreeSelect.java Tue Apr  9 13:44:54 2013
@@ -19,8 +19,10 @@
 
 package org.apache.myfaces.tobago.internal.component;
 
+import org.apache.myfaces.tobago.component.Attributes;
 import org.apache.myfaces.tobago.config.Configurable;
 
+import javax.el.ValueExpression;
 import javax.faces.component.UISelectBoolean;
 import javax.faces.context.FacesContext;
 
@@ -30,4 +32,14 @@ public abstract class AbstractUITreeSele
   public void updateModel(FacesContext context) {
     super.updateModel(context);
   }
+
+  /**
+   * The value is stored in the state of the parent UITree, if the value attribute has not a value expression.
+   * The value is stored normally, if there is a value expression.
+   * @return Is the value stored in the state of the UITree parent object?
+   */
+  public boolean isValueStoredInState() {
+    final ValueExpression valueExpression = getValueExpression(Attributes.VALUE);
+    return valueExpression == null;
+  }
 }

Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/SelectedState.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/SelectedState.java?rev=1466029&r1=1466028&r2=1466029&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/SelectedState.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/SelectedState.java Tue Apr  9 13:44:54 2013
@@ -26,6 +26,7 @@ import java.util.Set;
 /**
  * Manages the selected tree paths of a tree.
  */
+// TODO: might be renamed to SelectedTreeState?
 public class SelectedState implements Serializable {
 
   private Set<TreePath> selected = new HashSet<TreePath>();
@@ -66,4 +67,15 @@ public class SelectedState implements Se
   public void clear() {
     selected.clear();
   }
+
+  /**
+   * Set the selection state of the given path
+   */
+  public void select(TreePath path, boolean selected) {
+    if (selected) {
+      select(path);
+    } else {
+      unselect(path);
+    }
+  }
 }

Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/SheetState.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/SheetState.java?rev=1466029&r1=1466028&r2=1466029&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/SheetState.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/SheetState.java Tue Apr  9 13:44:54 2013
@@ -44,6 +44,7 @@ public class SheetState implements Seria
   private List<Integer> selectedRows;
   private Integer[] scrollPosition;
   private ExpandedState expandedState;
+  private SelectedState selectedState;
 
   public SheetState() {
     resetSelected();
@@ -125,6 +126,17 @@ public class SheetState implements Seria
     this.expandedState = expandedState;
   }
 
+  public SelectedState getSelectedState() {
+    if (selectedState == null) {
+      selectedState = new SelectedState();
+    }
+    return selectedState;
+  }
+
+  public void setSelectedState(SelectedState selectedState) {
+    this.selectedState = selectedState;
+  }
+
   public static Integer[] parseScrollPosition(String value) {
     Integer[] position = null;
     if (!StringUtils.isBlank(value)) {

Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoServletContextListener.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoServletContextListener.java?rev=1466029&r1=1466028&r2=1466029&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoServletContextListener.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoServletContextListener.java Tue Apr  9 13:44:54 2013
@@ -47,8 +47,8 @@ public class TobagoServletContextListene
     }
 
     TobagoConfigBuilder.init(servletContext);
-    if (LOG.isDebugEnabled()) {
-      LOG.debug("tobago config: " + TobagoConfig.getInstance(servletContext));
+    if (LOG.isInfoEnabled()) {
+      LOG.info("tobago config: " + TobagoConfig.getInstance(servletContext));
     }
   }
 

Copied: myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/tree/tree-select-via-state.xhtml (from r1463501, myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/tree/tree-select.xhtml)
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/tree/tree-select-via-state.xhtml?p2=myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/tree/tree-select-via-state.xhtml&p1=myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/tree/tree-select.xhtml&r1=1463501&r2=1466029&rev=1466029&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/tree/tree-select.xhtml (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/tree/tree-select-via-state.xhtml Tue Apr  9 13:44:54 2013
@@ -24,13 +24,15 @@
   <tc:page id="page">
     <tc:gridLayoutConstraint width="600px" height="300px"/>
     <f:facet name="layout">
-      <tc:gridLayout rows="*;auto;auto"/>
+      <tc:gridLayout rows="20px;*;auto;auto"/>
     </f:facet>
 
+    <tc:out value="Stores the selection value in the state object of the tree."/>
+
     <tc:tree id="tree" selectable="single" showRoot="true" showRootJunction="true" value="#{tree.tree}" var="node">
       <tc:treeNode id="template">
         <tc:treeIndent/>
-        <tc:treeSelect id="select" label="#{node.userObject.name}" value="#{node.userObject.selected}"/>
+        <tc:treeSelect id="select" label="#{node.userObject.name}"/>
       </tc:treeNode>
     </tc:tree>
 

Copied: myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/tree/tree-select-via-value.xhtml (from r1464994, myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/tree/tree-select.xhtml)
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/tree/tree-select-via-value.xhtml?p2=myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/tree/tree-select-via-value.xhtml&p1=myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/tree/tree-select.xhtml&r1=1464994&r2=1466029&rev=1466029&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/tree/tree-select.xhtml (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-test/src/main/webapp/test/tree/tree-select-via-value.xhtml Tue Apr  9 13:44:54 2013
@@ -24,10 +24,13 @@
   <tc:page id="page">
     <tc:gridLayoutConstraint width="600px" height="300px"/>
     <f:facet name="layout">
-      <tc:gridLayout rows="*;auto;auto"/>
+      <tc:gridLayout rows="20px;*;auto;auto"/>
     </f:facet>
 
-    <tc:tree id="tree" selectable="single" showRoot="true" showRootJunction="true" value="#{tree.tree}" var="node">
+    <tc:out value="Stores the selection value in the value attribute of the tc:treeSelect component."/>
+
+    <tc:tree id="tree" selectable="single" showRoot="true" showRootJunction="true"
+             value="#{tree.tree}" state="#{tree.state}" var="node">
       <tc:treeNode id="template">
         <tc:treeIndent/>
         <tc:treeSelect id="select" label="#{node.userObject.name}" value="#{node.userObject.selected}"/>

Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeSelectRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeSelectRenderer.java?rev=1466029&r1=1466028&r2=1466029&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeSelectRenderer.java (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeSelectRenderer.java Tue Apr  9 13:44:54 2013
@@ -24,6 +24,7 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.myfaces.tobago.component.UITreeSelect;
 import org.apache.myfaces.tobago.internal.component.AbstractUIData;
+import org.apache.myfaces.tobago.internal.component.AbstractUITreeNode;
 import org.apache.myfaces.tobago.model.Selectable;
 import org.apache.myfaces.tobago.renderkit.RendererBase;
 import org.apache.myfaces.tobago.renderkit.css.Classes;
@@ -46,7 +47,8 @@ public class TreeSelectRenderer extends 
   public void decode(FacesContext facesContext, UIComponent component) {
 
     final UITreeSelect select = (UITreeSelect) component;
-    final AbstractUIData data = ComponentUtils.findAncestor(select, AbstractUIData.class);
+    final AbstractUITreeNode node = ComponentUtils.findAncestor(select, AbstractUITreeNode.class);
+    final AbstractUIData data = ComponentUtils.findAncestor(node, AbstractUIData.class);
 
     if (ComponentUtils.isOutputOnly(select)) {
       return;
@@ -60,24 +62,34 @@ public class TreeSelectRenderer extends 
       name = clientId;
     }
 
-    final String newValue = (String) facesContext.getExternalContext().getRequestParameterMap().get(name);
+    final String parameter = (String) facesContext.getExternalContext().getRequestParameterMap().get(name);
 
     if (LOG.isDebugEnabled()) {
-      LOG.debug("new value = '" + newValue + "'");
+      LOG.debug("parameter = '" + parameter + "'");
     }
 
-    select.setSubmittedValue(clientId.equals(newValue) ? "true" : "false");
+    final boolean selected = clientId.equals(parameter);
+    if (!select.isValueStoredInState()) {
+      select.setSubmittedValue(selected ? "true" : "false");
+    }
   }
 
   @Override
   public void encodeBegin(FacesContext facesContext, UIComponent component) throws IOException {
 
     final UITreeSelect select = (UITreeSelect) component;
-    final AbstractUIData data = ComponentUtils.findAncestor(select, AbstractUIData.class);
+    final AbstractUITreeNode node = ComponentUtils.findAncestor(select, AbstractUITreeNode.class);
+    final AbstractUIData data = ComponentUtils.findAncestor(node, AbstractUIData.class);
 
     final String id = select.getClientId(facesContext);
     final String currentValue = getCurrentValue(facesContext, select);
-    final boolean checked = "true".equals(currentValue);
+    final boolean checked;
+    if (select.isValueStoredInState()) {
+      checked = data.getSelectedState().isSelected(node.getPath());
+    } else {
+      checked = "true".equals(currentValue);
+    }
+
     final boolean folder = data.isFolder();
     final Selectable selectable = data.getSelectableAsEnum();
 

Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-tree.js
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-tree.js?rev=1466029&r1=1466028&r2=1466029&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-tree.js (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-tree.js Tue Apr  9 13:44:54 2013
@@ -177,6 +177,24 @@ Tobago.Tree.init = function(elements) {
     node.addClass("tobago-treeNode-markup-selected");
   });
 
+  // selected for treeSelect
+  Tobago.Utils.selectWidthJQuery(elements, ".tobago-treeSelect > input").change(function () {
+    var select = jQuery(this);
+    var selected = select.prop("checked");
+    var data = select.closest(".tobago-treeMenu, .tobago-tree, .tobago-sheet");
+    var hidden = data.children(".tobago-treeMenu-selected, .tobago-tree-selected, .tobago-sheet-selected");
+    var newValue;
+    if (select.attr("type") == "radio") {
+      newValue = "," + Tobago.Tree.rowIndex(select) + ",";
+    } else if (selected) {
+      newValue = hidden.val() + Tobago.Tree.rowIndex(select) + ",";
+    } else {
+      newValue = hidden.val().replace(new RegExp("," + Tobago.Tree.rowIndex(select) + ","), ",");
+    }
+    // XXX optimize: regexp and Tobago.Tree.rowIndex
+    hidden.val(newValue);
+  });
+
   // selected for treeMenuNode
   Tobago.Utils.selectWidthJQuery(elements, ".tobago-treeMenuCommand").focus(function() {
     var command = jQuery(this);
@@ -190,20 +208,22 @@ Tobago.Tree.init = function(elements) {
 
   // init selected field
   Tobago.Utils.selectWidthJQuery(elements, ".tobago-treeMenu, .tobago-tree, .tobago-sheet").each(function() {
-    var selected = jQuery(this).children(".tobago-treeMenu-selected, .tobago-tree-selected, .tobago-sheet-selected");
-    var string = "";
+    var hidden = jQuery(this).children(".tobago-treeMenu-selected, .tobago-tree-selected, .tobago-sheet-selected");
+    var string = ",";
     jQuery(this).find(".tobago-treeMenuNode-markup-selected, .tobago-treeNode-markup-selected").each(function() {
       string += Tobago.Tree.rowIndex(jQuery(this)) + ",";
     });
+    hidden.val(string);
   });
 
   // init expanded field
   Tobago.Utils.selectWidthJQuery(elements, ".tobago-treeMenu, .tobago-tree, .tobago-sheet").each(function() {
-    var expanded = jQuery(this).children(".tobago-treeMenu-expanded, .tobago-tree-expanded, .tobago-sheet-expanded");
+    var hidden = jQuery(this).children(".tobago-treeMenu-expanded, .tobago-tree-expanded, .tobago-sheet-expanded");
     var string = ",";
     jQuery(this).find(".tobago-treeMenuNode-markup-expanded, .tobago-treeNode-markup-expanded").each(function() {
       string += Tobago.Tree.rowIndex(jQuery(this)) + ",";
     });
+    hidden.val(string);
   });
 
   // init tree selection for multiCascade