Author: nbelaevski
Date: 2010-10-31 12:26:17 -0400 (Sun, 31 Oct 2010)
New Revision: 19798
Added:
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/component/TreeDecoderHelper.java
Modified:
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/component/AbstractTree.java
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/renderkit/TreeRendererBase.java
sandbox/trunk/ui/tree-actual/ui/src/main/resources/META-INF/resources/org.richfaces/tree.js
sandbox/trunk/ui/tree-actual/ui/src/main/templates/tree.template.xml
Log:
https://jira.jboss.org/browse/RF-9315
Modified:
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/component/AbstractTree.java
===================================================================
---
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/component/AbstractTree.java 2010-10-31
15:21:51 UTC (rev 19797)
+++
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/component/AbstractTree.java 2010-10-31
16:26:17 UTC (rev 19798)
@@ -52,6 +52,7 @@
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.TreeToggleEvent;
import org.richfaces.model.TreeDataModelImpl;
@@ -70,7 +71,7 @@
tag = @Tag(name = "tree"),
renderer = @JsfRenderer(type = "org.richfaces.TreeRenderer")
)
-public abstract class AbstractTree extends UIDataAdaptor implements
MetaComponentProcessor, MetaComponentResolver, MetaComponentEncoder {
+public abstract class AbstractTree extends UIDataAdaptor implements
MetaComponentResolver, MetaComponentEncoder {
public static final String COMPONENT_TYPE = "org.richfaces.Tree";
@@ -90,6 +91,8 @@
expanded
}
+ private transient TreeDecoderHelper treeDecoderHelper = new TreeDecoderHelper(this);
+
public AbstractTree() {
setRendererType("org.richfaces.TreeRenderer");
}
@@ -245,18 +248,18 @@
protected VisitResult visitDataChildrenMetaComponents(ExtendedVisitContext
extendedVisitContext,
VisitCallback callback) {
- VisitResult result = extendedVisitContext.invokeMetaComponentVisitCallback(this,
callback, NODE_META_COMPONENT_ID);
- if (result != VisitResult.ACCEPT) {
- return result;
+ if (ExtendedVisitContextMode.RENDER == extendedVisitContext.getVisitMode()) {
+ VisitResult result =
extendedVisitContext.invokeMetaComponentVisitCallback(this, callback,
NODE_META_COMPONENT_ID);
+ if (result != VisitResult.ACCEPT) {
+ return result;
+ }
}
return super.visitDataChildrenMetaComponents(extendedVisitContext, callback);
}
- public void processMetaComponent(FacesContext context, String metaComponentId) {
- if (context.getCurrentPhaseId() == PhaseId.APPLY_REQUEST_VALUES) {
- ((MetaComponentRenderer) getRenderer(context)).decodeMetaComponent(context,
this, metaComponentId);
- }
+ void decodeMetaComponent(FacesContext context, String metaComponentId) {
+ ((MetaComponentRenderer) getRenderer(context)).decodeMetaComponent(context, this,
metaComponentId);
}
public void encodeMetaComponent(FacesContext context, String metaComponentId) throws
IOException {
@@ -270,4 +273,9 @@
return null;
}
+
+ @Override
+ protected Iterator<UIComponent> dataChildren() {
+ return Iterators.<UIComponent>concat(super.dataChildren(),
Iterators.singletonIterator(treeDecoderHelper));
+ }
}
Added:
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/component/TreeDecoderHelper.java
===================================================================
---
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/component/TreeDecoderHelper.java
(rev 0)
+++
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/component/TreeDecoderHelper.java 2010-10-31
16:26:17 UTC (rev 19798)
@@ -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.component;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIComponentBase;
+import javax.faces.context.FacesContext;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class TreeDecoderHelper extends UIComponentBase {
+
+ public static final String HELPER_ID = "__treeDecoderHelper";
+
+ private AbstractTree tree;
+
+ public TreeDecoderHelper(AbstractTree tree) {
+ super();
+ this.tree = tree;
+
+ setId(HELPER_ID);
+ setTransient(true);
+ }
+
+ @Override
+ public UIComponent getParent() {
+ return tree;
+ }
+
+ @Override
+ public boolean isInView() {
+ return tree.isInView();
+ }
+
+ @Override
+ public String getFamily() {
+ return null;
+ }
+
+ @Override
+ public void decode(FacesContext context) {
+ super.decode(context);
+ tree.decodeMetaComponent(context, AbstractTree.NODE_META_COMPONENT_ID);
+ }
+}
Modified:
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/renderkit/TreeRendererBase.java
===================================================================
---
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/renderkit/TreeRendererBase.java 2010-10-31
15:21:51 UTC (rev 19797)
+++
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/renderkit/TreeRendererBase.java 2010-10-31
16:26:17 UTC (rev 19798)
@@ -30,6 +30,7 @@
import java.util.Map;
import javax.faces.component.UIComponent;
+import javax.faces.component.UINamingContainer;
import javax.faces.context.FacesContext;
import javax.faces.context.PartialViewContext;
@@ -39,6 +40,7 @@
import org.richfaces.component.AbstractTreeNode;
import org.richfaces.component.MetaComponentResolver;
import org.richfaces.component.SwitchType;
+import org.richfaces.component.TreeDecoderHelper;
import org.richfaces.event.TreeToggleEvent;
import org.richfaces.log.Logger;
import org.richfaces.log.RichfacesLogger;
@@ -56,12 +58,8 @@
private static final JSReference TOGGLE_SOURCE = new
JSReference("toggleSource");
- private static final String TREE_TOGGLE_ID_PARAM =
"org.richfaces.Tree.TREE_TOGGLE_ID";
-
- private static final String NODE_TOGGLE_ID_PARAM =
"org.richfaces.Tree.NODE_TOGGLE_ID";
+ private static final String NEW_NODE_TOGGLE_STATE =
"__NEW_NODE_TOGGLE_STATE";
- private static final String NEW_STATE_PARAM =
"org.richfaces.Tree.NEW_STATE";
-
enum NodeState {
expanded("rf-tr-nd-exp", "rf-trn-hnd-exp",
"rf-trn-ico-nd"),
collapsed("rf-tr-nd-colps", "rf-trn-hnd-colps",
"rf-trn-ico-nd"),
@@ -136,10 +134,15 @@
new TreeEncoderFull(context, tree).encode();
}
+ protected String getDecoderHelperId(FacesContext facesContext) {
+ return UINamingContainer.getSeparatorChar(facesContext) +
TreeDecoderHelper.HELPER_ID;
+ }
+
protected String getAjaxToggler(FacesContext context, UIComponent component) {
AbstractTree tree = (AbstractTree) component;
- if (!SwitchType.ajax.equals(tree.getToggleMode())) {
+ SwitchType toggleMode = tree.getToggleMode();
+ if (toggleMode != SwitchType.ajax) {
return null;
}
@@ -152,16 +155,9 @@
if (!eventOptions.isEmpty()) {
ajaxFunction.addParameter(eventOptions);
}
-
return ajaxFunction.toScript();
}
-
- @Override
- protected void doDecode(FacesContext context, UIComponent component) {
- super.doDecode(context, component);
-
- }
-
+
/* (non-Javadoc)
* @see
org.richfaces.renderkit.MetaComponentRenderer#encodeMetaComponent(javax.faces.context.FacesContext,
javax.faces.component.UIComponent, java.lang.String)
*/
@@ -182,12 +178,12 @@
public void decodeMetaComponent(FacesContext context, UIComponent component, String
metaComponentId) {
if (NODE_META_COMPONENT_ID.equals(metaComponentId)) {
final Map<String, String> map =
context.getExternalContext().getRequestParameterMap();
- String toggleId = map.get(NODE_TOGGLE_ID_PARAM);
- if (component.getClientId(context).equals(toggleId)) {
+ String newToggleState = map.get(component.getClientId(context) +
NEW_NODE_TOGGLE_STATE);
+ if (newToggleState != null) {
AbstractTree tree = (AbstractTree) component;
AbstractTreeNode treeNode = tree.getTreeNodeComponent();
- boolean expanded = Boolean.valueOf(map.get(NEW_STATE_PARAM));
+ boolean expanded = Boolean.valueOf(newToggleState);
if (tree.isExpanded() ^ expanded) {
new TreeToggleEvent(treeNode, expanded).queue();
}
Modified:
sandbox/trunk/ui/tree-actual/ui/src/main/resources/META-INF/resources/org.richfaces/tree.js
===================================================================
---
sandbox/trunk/ui/tree-actual/ui/src/main/resources/META-INF/resources/org.richfaces/tree.js 2010-10-31
15:21:51 UTC (rev 19797)
+++
sandbox/trunk/ui/tree-actual/ui/src/main/resources/META-INF/resources/org.richfaces/tree.js 2010-10-31
16:26:17 UTC (rev 19798)
@@ -28,11 +28,7 @@
});
}
- var TOGGLE_TREE_ID_PARAM = "org.richfaces.Tree.TREE_TOGGLE_ID";
-
- var TOGGLE_NODE_ID_PARAM = "org.richfaces.Tree.NODE_TOGGLE_ID";
-
- var TOGGLE_NEW_STATE_PARAM = "org.richfaces.Tree.NEW_STATE";
+ var NEW_NODE_TOGGLE_STATE = "__NEW_NODE_TOGGLE_STATE"
var TREE_CLASSES = ["rf-tr-nd-colps", "rf-tr-nd-exp"];
@@ -123,6 +119,16 @@
}
},
+ __updateClientToggleStateInput: function(newState) {
+ if (!this.__clientStateInput) {
+ this.__clientStateInput = $("<input type='hidden'
/>").appendTo(this.elt)
+ .attr({name: this.elt.attr("id") + NEW_NODE_TOGGLE_STATE});
+ }
+
+ this.__clientStateInput.val(newState.toString());
+
+ },
+
__changeToggleState: function(newState) {
if (!this.isLeaf()) {
var tree = this.getTree();
@@ -131,16 +137,14 @@
case 'client':
this.elt.addClass(TREE_CLASSES[newState ? 1 :
0]).removeClass(TREE_CLASSES[!newState ? 1 : 0]);
this.handler.addClass(TREE_HANDLE_CLASSES[newState ? 1 :
0]).removeClass(TREE_HANDLE_CLASSES[!newState ? 1 : 0]);
+ this.__updateClientToggleStateInput(newState);
break;
case 'ajax':
+ case 'server':
//TODO - event?
- tree.toggleByAjax(null, richfaces.getDomElement(this.id).id, newState);
+ tree.sendToggleRequest(null, richfaces.getDomElement(this.id).id, newState);
break;
-
- case 'server':
-
- break;
}
}
@@ -163,6 +167,8 @@
},
destroy: function() {
+ this.__clientStateInput = null;
+
if (this.parent) {
this.parent.removeChild(this);
}
@@ -189,6 +195,8 @@
parentNode.addChild(new richfaces.ui.TreeNode(node[0]), idx);
};
+ var decoderHelperId;
+
richfaces.ui.Tree = richfaces.ui.TreeNode.extendClass({
name: "Tree",
@@ -210,13 +218,16 @@
this.__ajaxToggler = null;
},
- toggleByAjax: function(event, toggleSource, newNodeState) {
+ sendToggleRequest: function(event, toggleSource, newNodeState) {
var clientParams = {};
- clientParams[TOGGLE_NEW_STATE_PARAM] = newNodeState;
- clientParams[TOGGLE_NODE_ID_PARAM] = toggleSource;
- clientParams[TOGGLE_TREE_ID_PARAM] = this.id;
+ clientParams[toggleSource + NEW_NODE_TOGGLE_STATE] = newNodeState;
- this.__ajaxToggler(event, toggleSource + '@node', clientParams);
+ if (this.__toggleMode == 'server') {
+ var form = $(richfaces.getDomElement(this.id)).closest('form');
+ richfaces.submitForm(form, clientParams);
+ } else {
+ this.__ajaxToggler(event, toggleSource + decoderHelperId, clientParams);
+ }
},
getToggleMode: function() {
@@ -228,4 +239,8 @@
}
});
+ richfaces.ui.Tree.setDecoderHelperId = function(id) {
+ decoderHelperId = id;
+ };
+
}(jQuery, RichFaces));
\ No newline at end of file
Modified: sandbox/trunk/ui/tree-actual/ui/src/main/templates/tree.template.xml
===================================================================
--- sandbox/trunk/ui/tree-actual/ui/src/main/templates/tree.template.xml 2010-10-31
15:21:51 UTC (rev 19797)
+++ sandbox/trunk/ui/tree-actual/ui/src/main/templates/tree.template.xml 2010-10-31
16:26:17 UTC (rev 19798)
@@ -26,6 +26,7 @@
</cdk:body>
<script type="text/javascript">
+
RichFaces.ui.Tree.setDecoderHelperId(#{toScriptArgs(getDecoderHelperId(facesContext))});
<cdk:scriptObject name="options">
<cdk:scriptOption attributes="toggleMode selectionMode"
defaultValue="SwitchType.DEFAULT" />
<cdk:scriptOption name="ajaxToggler"
value="#{getAjaxToggler(facesContext, component)}" />