Author: nbelaevski
Date: 2010-11-05 12:48:06 -0400 (Fri, 05 Nov 2010)
New Revision: 19969
Added:
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeNodeRendererBase.java
Removed:
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/TreeDecoderHelper.java
Modified:
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTree.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTreeNode.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeEncoderBase.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeEncoderPartial.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeRendererBase.java
trunk/ui/iteration/ui/src/main/resources/META-INF/resources/org.richfaces/tree.js
trunk/ui/iteration/ui/src/main/templates/tree.template.xml
trunk/ui/iteration/ui/src/main/templates/treeNode.template.xml
Log:
https://jira.jboss.org/browse/RF-9627
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-11-05
16:32:09 UTC (rev 19968)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTree.java 2010-11-05
16:48:06 UTC (rev 19969)
@@ -25,44 +25,30 @@
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
-import java.util.Map;
-import javax.el.ELContext;
-import javax.el.ELException;
import javax.el.ValueExpression;
-import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
-import javax.faces.component.UpdateModelException;
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 javax.swing.tree.TreeNode;
import org.ajax4jsf.model.DataComponentState;
import org.ajax4jsf.model.ExtendedDataModel;
import org.ajax4jsf.model.Range;
-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.JsfComponent;
import org.richfaces.cdk.annotations.JsfRenderer;
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.TreeSelectionEvent;
import org.richfaces.event.TreeSelectionListener;
-import org.richfaces.event.TreeToggleEvent;
-import org.richfaces.event.TreeToggleListener;
import org.richfaces.model.ExtendedTreeDataModelImpl;
import org.richfaces.model.SwingTreeNodeDataModelImpl;
import org.richfaces.model.TreeDataModel;
@@ -88,8 +74,6 @@
public static final String COMPONENT_FAMILY = "org.richfaces.Tree";
- public static final String NODE_META_COMPONENT_ID = "node";
-
public static final String SELECTION_META_COMPONENT_ID = "selection";
private static final class MatchingTreeNodePredicate implements
Predicate<UIComponent> {
@@ -132,12 +116,11 @@
}
private enum PropertyKeys {
- expanded, selection
+ selection
}
- private transient TreeDecoderHelper treeDecoderHelper = new TreeDecoderHelper(this);
-
public AbstractTree() {
+ setKeepSaved(true);
setRendererType("org.richfaces.TreeRenderer");
}
@@ -182,40 +165,6 @@
getStateHelper().put(PropertyKeys.selection, selection);
}
- @SuppressWarnings("unchecked")
- protected Boolean getLocalExpandedValue(FacesContext facesContext) {
- Map<String, Object> stateMap = (Map<String, Object>)
getStateHelper().get(PropertyKeys.expanded);
- if (stateMap == null) {
- return null;
- }
-
- String key = this.getClientId(facesContext);
- return (Boolean) stateMap.get(key);
- }
-
- public boolean isExpanded() {
- if (getRowKey() == null) {
- return true;
- }
-
- FacesContext context = getFacesContext();
- Boolean localExpandedValue = getLocalExpandedValue(context);
- if (localExpandedValue != null) {
- return localExpandedValue.booleanValue();
- }
-
- ValueExpression ve = getValueExpression(PropertyKeys.expanded.toString());
- if (ve != null) {
- return Boolean.TRUE.equals(ve.getValue(context.getELContext()));
- }
-
- return false;
- }
-
- public void setExpanded(boolean newValue) {
- getStateHelper().put(PropertyKeys.expanded, this.getClientId(getFacesContext()),
newValue);
- }
-
@Override
protected ExtendedDataModel<?> createExtendedDataModel() {
ExtendedTreeDataModelImpl<?> model = new
ExtendedTreeDataModelImpl<TreeNode>(new SwingTreeNodeDataModelImpl());
@@ -243,7 +192,7 @@
return dataModel.getChildrenRowKeysIterator(rowKey);
}
- public AbstractTreeNode getTreeNodeComponent() {
+ public AbstractTreeNode findTreeNodeComponent() {
if (getChildCount() == 0) {
return null;
}
@@ -262,60 +211,7 @@
public void broadcast(FacesEvent event) throws AbortProcessingException {
super.broadcast(event);
- if (event instanceof TreeToggleEvent) {
- TreeToggleEvent toggleEvent = (TreeToggleEvent) event;
- boolean newExpandedValue = toggleEvent.isExpanded();
-
- FacesContext context = getFacesContext();
- ValueExpression expression =
getValueExpression(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 {
- setExpanded(newExpandedValue);
- }
- } else if (event instanceof TreeSelectionEvent) {
+ if (event instanceof TreeSelectionEvent) {
TreeSelectionEvent selectionEvent = (TreeSelectionEvent) event;
final Collection<Object> newSelection =
selectionEvent.getNewSelection();
@@ -335,20 +231,6 @@
}
@Override
- protected VisitResult visitDataChildrenMetaComponents(ExtendedVisitContext
extendedVisitContext,
- VisitCallback callback) {
-
- 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);
- }
-
- @Override
protected boolean visitFixedChildren(VisitContext visitContext, VisitCallback
callback) {
if (visitContext instanceof ExtendedVisitContext) {
ExtendedVisitContext extendedVisitContext = (ExtendedVisitContext)
visitContext;
@@ -373,7 +255,7 @@
}
public String resolveClientId(FacesContext facesContext, UIComponent
contextComponent, String metaComponentId) {
- if (NODE_META_COMPONENT_ID.equals(metaComponentId) ||
SELECTION_META_COMPONENT_ID.equals(metaComponentId)) {
+ if (SELECTION_META_COMPONENT_ID.equals(metaComponentId)) {
return getClientId(facesContext) +
MetaComponentResolver.META_COMPONENT_SEPARATOR_CHAR + metaComponentId;
}
@@ -388,12 +270,11 @@
@Override
protected Iterator<UIComponent> dataChildren() {
- AbstractTreeNode treeNodeComponent = getTreeNodeComponent();
+ AbstractTreeNode treeNodeComponent = findTreeNodeComponent();
if (treeNodeComponent != null) {
- return
Iterators.<UIComponent>concat(Iterators.<UIComponent>singletonIterator(treeNodeComponent),
- Iterators.singletonIterator(treeDecoderHelper));
+ return Iterators.<UIComponent>singletonIterator(treeNodeComponent);
} else {
- return Iterators.<UIComponent>singletonIterator(treeDecoderHelper);
+ return Iterators.<UIComponent>emptyIterator();
}
}
@@ -402,18 +283,6 @@
return new TreeComponentState();
}
- public void addToggleListener(TreeToggleListener listener) {
- addFacesListener(listener);
- }
-
- public TreeToggleListener[] getTreeToggleListeners() {
- return (TreeToggleListener[]) getFacesListeners(TreeToggleListener.class);
- }
-
- public void removeToggleListener(TreeToggleListener listener) {
- removeFacesListener(listener);
- }
-
public void addSelectionListener(TreeSelectionListener listener) {
addFacesListener(listener);
}
@@ -425,4 +294,18 @@
public void removeSelectionListener(TreeSelectionListener 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();
+ }
}
Modified:
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTreeNode.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTreeNode.java 2010-11-05
16:32:09 UTC (rev 19968)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTreeNode.java 2010-11-05
16:48:06 UTC (rev 19969)
@@ -21,17 +21,39 @@
*/
package org.richfaces.component;
+import java.io.IOException;
+
+import javax.el.ELContext;
+import javax.el.ELException;
+import javax.el.ValueExpression;
+import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.component.UIComponentBase;
+import javax.faces.component.UpdateModelException;
+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.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.component.IterationStateHolder;
+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.JsfComponent;
import org.richfaces.cdk.annotations.JsfRenderer;
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.event.TreeToggleEvent;
+import org.richfaces.event.TreeToggleListener;
+import org.richfaces.renderkit.MetaComponentRenderer;
/**
* @author Nick Belaevski
@@ -43,12 +65,18 @@
tag = @Tag(name = "treeNode"),
renderer = @JsfRenderer(type = "org.richfaces.TreeNodeRenderer")
)
-public abstract class AbstractTreeNode extends UIComponentBase {
+public abstract class AbstractTreeNode extends UIComponentBase implements
MetaComponentResolver, MetaComponentEncoder, IterationStateHolder {
public static final String COMPONENT_TYPE = "org.richfaces.TreeNode";
public static final String COMPONENT_FAMILY = "org.richfaces.TreeNode";
+ public static final String SUBTREE_META_COMPONENT_ID = "subtree";
+
+ private enum PropertyKeys {
+ expanded
+ }
+
public AbstractTreeNode() {
setRendererType("org.richfaces.TreeNodeRenderer");
}
@@ -66,7 +94,38 @@
//TODO - move to template
public abstract String getStyleClass();
- protected AbstractTree findTreeComponent() {
+ protected Boolean getLocalExpandedValue(FacesContext facesContext) {
+ return (Boolean) getStateHelper().get(PropertyKeys.expanded);
+ }
+
+ public boolean isExpanded() {
+ FacesContext context = getFacesContext();
+ Boolean localExpandedValue = getLocalExpandedValue(context);
+ if (localExpandedValue != null) {
+ return localExpandedValue.booleanValue();
+ }
+
+ ValueExpression ve = getValueExpression(PropertyKeys.expanded.toString());
+ if (ve != null) {
+ return Boolean.TRUE.equals(ve.getValue(context.getELContext()));
+ }
+
+ return false;
+ }
+
+ public void setExpanded(boolean newValue) {
+ getStateHelper().put(PropertyKeys.expanded, newValue);
+ }
+
+ public Object getIterationState() {
+ return getStateHelper().get(PropertyKeys.expanded);
+ }
+
+ public void setIterationState(Object state) {
+ getStateHelper().put(PropertyKeys.expanded, state);
+ }
+
+ public AbstractTree findTreeComponent() {
UIComponent c = this;
while (c != null && !(c instanceof AbstractTree)) {
c = c.getParent();
@@ -93,7 +152,103 @@
if (event instanceof TreeToggleEvent) {
TreeToggleEvent toggleEvent = (TreeToggleEvent) event;
- new TreeToggleEvent(findTreeComponent(), toggleEvent.isExpanded()).queue();
+ boolean newExpandedValue = toggleEvent.isExpanded();
+
+ FacesContext context = getFacesContext();
+ ValueExpression expression =
getValueExpression(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 {
+ setExpanded(newExpandedValue);
+ }
}
}
+
+ public void addToggleListener(TreeToggleListener listener) {
+ addFacesListener(listener);
+ }
+
+ public TreeToggleListener[] getTreeToggleListeners() {
+ return (TreeToggleListener[]) getFacesListeners(TreeToggleListener.class);
+ }
+
+ public void removeToggleListener(TreeToggleListener listener) {
+ removeFacesListener(listener);
+ }
+
+ public String resolveClientId(FacesContext facesContext, UIComponent
contextComponent, String metaComponentId) {
+ if (SUBTREE_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
+ public boolean visitTree(VisitContext context, VisitCallback callback) {
+ if (context instanceof ExtendedVisitContext) {
+ ExtendedVisitContext extendedVisitContext = (ExtendedVisitContext) context;
+ if (extendedVisitContext.getVisitMode() == ExtendedVisitContextMode.RENDER)
{
+ VisitResult result =
extendedVisitContext.invokeMetaComponentVisitCallback(this, callback,
SUBTREE_META_COMPONENT_ID);
+
+ if (result != VisitResult.ACCEPT) {
+ return result == VisitResult.COMPLETE;
+ }
+ }
+ }
+
+ return super.visitTree(context, callback);
+ }
+
+ public void encodeMetaComponent(FacesContext context, String metaComponentId) throws
IOException {
+ ((MetaComponentRenderer) getRenderer(context)).encodeMetaComponent(context, this,
metaComponentId);
+ }
}
Deleted:
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/TreeDecoderHelper.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/TreeDecoderHelper.java 2010-11-05
16:32:09 UTC (rev 19968)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/TreeDecoderHelper.java 2010-11-05
16:48:06 UTC (rev 19969)
@@ -1,66 +0,0 @@
-/*
- * 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:
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeEncoderBase.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeEncoderBase.java 2010-11-05
16:32:09 UTC (rev 19968)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeEncoderBase.java 2010-11-05
16:48:06 UTC (rev 19969)
@@ -29,6 +29,7 @@
import javax.faces.context.ResponseWriter;
import org.richfaces.component.AbstractTree;
+import org.richfaces.component.AbstractTreeNode;
import org.richfaces.component.TreeRange;
import org.richfaces.component.util.HtmlUtil;
import org.richfaces.renderkit.TreeRendererBase.NodeState;
@@ -72,7 +73,7 @@
return false;
}
- return tree.getTreeNodeComponent() != null;
+ return tree.findTreeNodeComponent() != null;
}
};
@@ -117,6 +118,8 @@
}
protected void writeTreeNodeStartElement(NodeState nodeState, boolean isLast) throws
IOException {
+ AbstractTreeNode treeNodeComponent = tree.findTreeNodeComponent();
+
context.getAttributes().put(TREE_NODE_HANDLE_CLASS_ATTRIBUTE,
nodeState.getHandleClass());
context.getAttributes().put(TREE_NODE_ICON_CLASS_ATTRIBUTE,
nodeState.getIconClass());
@@ -124,9 +127,9 @@
responseWriter.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE,
HtmlUtil.concatClasses("rf-tr-nd", isLast ?
"rf-tr-nd-last" : null, nodeState.getNodeClass()),
null);
- responseWriter.writeAttribute(HtmlConstants.ID_ATTRIBUTE,
tree.getClientId(context), null);
+ responseWriter.writeAttribute(HtmlConstants.ID_ATTRIBUTE,
treeNodeComponent.getClientId(context), null);
- tree.getTreeNodeComponent().encodeAll(context);
+ treeNodeComponent.encodeAll(context);
}
protected void writeTreeNodeEndElement() throws IOException {
Modified:
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeEncoderPartial.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeEncoderPartial.java 2010-11-05
16:32:09 UTC (rev 19968)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeEncoderPartial.java 2010-11-05
16:48:06 UTC (rev 19969)
@@ -27,7 +27,7 @@
import javax.faces.context.PartialResponseWriter;
import org.ajax4jsf.javascript.JSFunction;
-import org.richfaces.component.AbstractTree;
+import org.richfaces.component.AbstractTreeNode;
/**
* @author Nick Belaevski
@@ -35,11 +35,15 @@
*/
class TreeEncoderPartial extends TreeEncoderBase {
+ protected final AbstractTreeNode treeNode;
+
private Object rowKey;
- public TreeEncoderPartial(FacesContext context, AbstractTree tree) {
- super(context, tree);
+ public TreeEncoderPartial(FacesContext context, AbstractTreeNode treeNode) {
+ super(context, treeNode.findTreeComponent());
+ this.treeNode = treeNode;
+
this.rowKey = tree.getRowKey();
if (this.rowKey == null) {
@@ -49,8 +53,10 @@
@Override
public void encode() throws IOException {
+ String elementId = treeNode.getClientId(context);
+
PartialResponseWriter prw =
context.getPartialViewContext().getPartialResponseWriter();
- prw.startUpdate(tree.getClientId(context));
+ prw.startUpdate(elementId);
Object initialRowKey = tree.getRowKey();
try {
@@ -68,7 +74,7 @@
}
prw.startEval();
- JSFunction function = new
JSFunction("RichFaces.ui.TreeNode.initNodeByAjax", tree.getClientId(context));
+ JSFunction function = new
JSFunction("RichFaces.ui.TreeNode.initNodeByAjax", elementId);
prw.write(function.toScript());
prw.endEval();
}
Added:
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeNodeRendererBase.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeNodeRendererBase.java
(rev 0)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeNodeRendererBase.java 2010-11-05
16:48:06 UTC (rev 19969)
@@ -0,0 +1,82 @@
+/*
+ * 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 java.util.Map;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.PartialViewContext;
+
+import org.richfaces.component.AbstractTreeNode;
+import org.richfaces.component.MetaComponentResolver;
+import org.richfaces.event.TreeToggleEvent;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class TreeNodeRendererBase extends RendererBase implements MetaComponentRenderer
{
+
+ private static final String NEW_NODE_TOGGLE_STATE =
"__NEW_NODE_TOGGLE_STATE";
+
+ private static final String TRIGGER_NODE_AJAX_UPDATE =
"__TRIGGER_NODE_AJAX_UPDATE";
+
+ @Override
+ public void decode(FacesContext context, UIComponent component) {
+ super.decode(context, component);
+
+ final Map<String, String> map =
context.getExternalContext().getRequestParameterMap();
+ String newToggleState = map.get(component.getClientId(context) +
NEW_NODE_TOGGLE_STATE);
+ if (newToggleState != null) {
+
+ AbstractTreeNode treeNode = (AbstractTreeNode) component;
+
+ boolean expanded = Boolean.valueOf(newToggleState);
+ if (treeNode.isExpanded() ^ expanded) {
+ new TreeToggleEvent(treeNode, expanded).queue();
+ }
+
+ PartialViewContext pvc = context.getPartialViewContext();
+ if (pvc.isAjaxRequest() && map.get(component.getClientId(context) +
TRIGGER_NODE_AJAX_UPDATE) != null) {
+ pvc.getRenderIds().add(treeNode.getClientId(context) +
MetaComponentResolver.META_COMPONENT_SEPARATOR_CHAR +
AbstractTreeNode.SUBTREE_META_COMPONENT_ID);
+ }
+ }
+ }
+
+ public void decodeMetaComponent(FacesContext context, UIComponent component, String
metaComponentId) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void encodeMetaComponent(FacesContext context, UIComponent component, String
metaComponentId)
+ throws IOException {
+
+ if (AbstractTreeNode.SUBTREE_META_COMPONENT_ID.equals(metaComponentId)) {
+ AbstractTreeNode treeNode = (AbstractTreeNode) component;
+ new TreeEncoderPartial(context, treeNode).encode();
+ } else {
+ throw new IllegalArgumentException(metaComponentId);
+ }
+
+ }
+}
Modified:
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeRendererBase.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeRendererBase.java 2010-11-05
16:32:09 UTC (rev 19968)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeRendererBase.java 2010-11-05
16:48:06 UTC (rev 19969)
@@ -21,7 +21,6 @@
*/
package org.richfaces.renderkit;
-import static org.richfaces.component.AbstractTree.NODE_META_COMPONENT_ID;
import static org.richfaces.component.AbstractTree.SELECTION_META_COMPONENT_ID;
import static org.richfaces.renderkit.util.AjaxRendererUtils.AJAX_FUNCTION_NAME;
import static org.richfaces.renderkit.util.AjaxRendererUtils.buildAjaxFunction;
@@ -33,8 +32,8 @@
import java.util.Iterator;
import java.util.Map;
+import javax.faces.component.ContextCallback;
import javax.faces.component.UIComponent;
-import javax.faces.component.UINamingContainer;
import javax.faces.context.FacesContext;
import javax.faces.context.PartialResponseWriter;
import javax.faces.context.PartialViewContext;
@@ -46,9 +45,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.TreeSelectionEvent;
-import org.richfaces.event.TreeToggleEvent;
import org.richfaces.log.Logger;
import org.richfaces.log.RichfacesLogger;
@@ -68,10 +65,25 @@
private static final JSReference SOURCE_JS_REF = new
JSReference("source");
- private static final String NEW_NODE_TOGGLE_STATE =
"__NEW_NODE_TOGGLE_STATE";
-
private static final String SELECTION_STATE = "__SELECTION_STATE";
+ /**
+ * @author Nick Belaevski
+ *
+ */
+ private final class RowKeyContextCallback implements ContextCallback {
+ private Object rowKey;
+
+ public void invokeContextCallback(FacesContext context, UIComponent target) {
+ AbstractTreeNode treeNode = (AbstractTreeNode) target;
+ rowKey = treeNode.findTreeComponent().getRowKey();
+ }
+
+ public Object getRowKey() {
+ return rowKey;
+ }
+ }
+
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"),
@@ -146,10 +158,6 @@
new TreeEncoderFull(context, tree).encode();
}
- protected String getDecoderHelperId(FacesContext facesContext) {
- return UINamingContainer.getSeparatorChar(facesContext) +
TreeDecoderHelper.HELPER_ID;
- }
-
protected String getAjaxSubmitFunction(FacesContext context, UIComponent component)
{
AbstractTree tree = (AbstractTree) component;
@@ -189,7 +197,7 @@
try {
tree.setRowKey(context, selectionKey);
if (tree.isRowAvailable()) {
- selectedNodeId = tree.getClientId(context);
+ selectedNodeId = tree.findTreeNodeComponent().getClientId(context);
}
} finally {
try {
@@ -226,20 +234,10 @@
return selectionType;
}
- protected String getNamingContainerSeparatorChar(FacesContext context) {
- return String.valueOf(UINamingContainer.getSeparatorChar(context));
- }
-
- /* (non-Javadoc)
- * @see
org.richfaces.renderkit.MetaComponentRenderer#encodeMetaComponent(javax.faces.context.FacesContext,
javax.faces.component.UIComponent, java.lang.String)
- */
public void encodeMetaComponent(FacesContext context, UIComponent component, String
metaComponentId)
throws IOException {
- if (NODE_META_COMPONENT_ID.equals(metaComponentId)) {
- AbstractTree tree = (AbstractTree) component;
- new TreeEncoderPartial(context, tree).encode();
- } else if (SELECTION_META_COMPONENT_ID.equals(metaComponentId)) {
+ if (SELECTION_META_COMPONENT_ID.equals(metaComponentId)) {
PartialResponseWriter writer =
context.getPartialViewContext().getPartialResponseWriter();
writer.startUpdate(getSelectionStateInputId(context, component));
@@ -261,30 +259,7 @@
}
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 newToggleState = map.get(component.getClientId(context) +
NEW_NODE_TOGGLE_STATE);
- if (newToggleState != null) {
-
- AbstractTree tree = (AbstractTree) component;
- AbstractTreeNode treeNode = tree.getTreeNodeComponent();
-
- if (treeNode == null) {
- return;
- }
-
- boolean expanded = Boolean.valueOf(newToggleState);
- if (tree.isExpanded() ^ expanded) {
- new TreeToggleEvent(treeNode, expanded).queue();
- }
-
- PartialViewContext pvc = context.getPartialViewContext();
- if (pvc.isAjaxRequest()) {
- pvc.getRenderIds().add(tree.getClientId(context) +
MetaComponentResolver.META_COMPONENT_SEPARATOR_CHAR
- + AbstractTree.NODE_META_COMPONENT_ID);
- }
- }
- }
+ throw new UnsupportedOperationException();
}
@Override
@@ -298,8 +273,9 @@
Object selectionRowKey = null;
if (!Strings.isNullOrEmpty(selectedNode)) {
- String selectionRowKeyString =
selectedNode.substring(component.getClientId(context).length() + 1 /* naming container
separator char */);
- selectionRowKey = tree.getRowKeyConverter().getAsObject(context, component,
selectionRowKeyString);
+ RowKeyContextCallback rowKeyContextCallback = new RowKeyContextCallback();
+ tree.invokeOnComponent(context, selectedNode, rowKeyContextCallback);
+ selectionRowKey = rowKeyContextCallback.getRowKey();
}
Collection<Object> selection = tree.getSelection();
Modified:
trunk/ui/iteration/ui/src/main/resources/META-INF/resources/org.richfaces/tree.js
===================================================================
---
trunk/ui/iteration/ui/src/main/resources/META-INF/resources/org.richfaces/tree.js 2010-11-05
16:32:09 UTC (rev 19968)
+++
trunk/ui/iteration/ui/src/main/resources/META-INF/resources/org.richfaces/tree.js 2010-11-05
16:48:06 UTC (rev 19969)
@@ -21,10 +21,10 @@
*/
(function($, richfaces) {
- var DECODER_HELPER_ID = "__treeDecoderHelper";
-
var NEW_NODE_TOGGLE_STATE = "__NEW_NODE_TOGGLE_STATE";
+ var TRIGGER_NODE_AJAX_UPDATE = "__TRIGGER_NODE_AJAX_UPDATE";
+
var SELECTION_STATE = "__SELECTION_STATE";
var TREE_CLASSES = ["rf-tr-nd-colps", "rf-tr-nd-exp"];
@@ -233,8 +233,6 @@
return tree != findTree(elt);
};
- var ncSepChar;
-
richfaces.ui.Tree = richfaces.ui.TreeNode.extendClass({
name: "Tree",
@@ -304,7 +302,8 @@
var form = this.__treeRootElt.closest('form');
richfaces.submitForm(form, clientParams);
} else {
- this.__ajaxSubmitFunction(event, toggleSource + ncSepChar + DECODER_HELPER_ID,
clientParams);
+ clientParams[toggleSource + TRIGGER_NODE_AJAX_UPDATE] = newNodeState;
+ this.__ajaxSubmitFunction(event, toggleSource, clientParams);
}
},
@@ -376,8 +375,4 @@
}
});
- richfaces.ui.Tree.setNamingContainerSeparatorChar = function(s) {
- ncSepChar = s.charAt(0);
- };
-
}(jQuery, RichFaces));
\ No newline at end of file
Modified: trunk/ui/iteration/ui/src/main/templates/tree.template.xml
===================================================================
--- trunk/ui/iteration/ui/src/main/templates/tree.template.xml 2010-11-05 16:32:09 UTC
(rev 19968)
+++ trunk/ui/iteration/ui/src/main/templates/tree.template.xml 2010-11-05 16:48:06 UTC
(rev 19969)
@@ -29,7 +29,6 @@
<cdk:call expression="encodeSelectionStateInput(facesContext,
component)" />
<script type="text/javascript">
-
RichFaces.ui.Tree.setNamingContainerSeparatorChar(#{toScriptArgs(getNamingContainerSeparatorChar(facesContext))});
<cdk:scriptObject name="options">
<cdk:scriptOption attributes="toggleType"
defaultValue="SwitchType.DEFAULT" />
<cdk:scriptOption name="selectionType"
value="#{getSelectionMode(facesContext, component)}"
defaultValue="SwitchType.client" />
Modified: trunk/ui/iteration/ui/src/main/templates/treeNode.template.xml
===================================================================
--- trunk/ui/iteration/ui/src/main/templates/treeNode.template.xml 2010-11-05 16:32:09 UTC
(rev 19968)
+++ trunk/ui/iteration/ui/src/main/templates/treeNode.template.xml 2010-11-05 16:48:06 UTC
(rev 19969)
@@ -8,7 +8,7 @@
<cc:interface>
<cdk:class>org.richfaces.renderkit.html.TreeNodeRenderer
</cdk:class>
-
<cdk:superclass>org.richfaces.renderkit.RendererBase</cdk:superclass>
+
<cdk:superclass>org.richfaces.renderkit.TreeNodeRendererBase</cdk:superclass>
<cdk:component-family>org.richfaces.TreeNode
</cdk:component-family>
<cdk:renderer-type>org.richfaces.TreeNodeRenderer