Author: nbelaevski
Date: 2007-07-04 11:24:27 -0400 (Wed, 04 Jul 2007)
New Revision: 1466
Modified:
branches/3.0.2/richfaces/tree/src/main/java/org/richfaces/component/state/TreeState.java
branches/3.0.2/richfaces/tree/src/main/java/org/richfaces/renderkit/TreeRendererBase.java
branches/3.0.2/richfaces/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree-item.js
Log:
http://jira.jboss.com/jira/browse/RF-34 fixed
Modified:
branches/3.0.2/richfaces/tree/src/main/java/org/richfaces/component/state/TreeState.java
===================================================================
---
branches/3.0.2/richfaces/tree/src/main/java/org/richfaces/component/state/TreeState.java 2007-07-04
14:48:13 UTC (rev 1465)
+++
branches/3.0.2/richfaces/tree/src/main/java/org/richfaces/component/state/TreeState.java 2007-07-04
15:24:27 UTC (rev 1466)
@@ -116,6 +116,10 @@
return (selectedNode != null && selectedNode.equals(rowKey));
}
+ public TreeRowKey getSelectedNode() {
+ return selectedNode;
+ }
+
public boolean setSelected(TreeRowKey rowKey) {
if (selectedNode == null) {
if (rowKey != null) {
Modified:
branches/3.0.2/richfaces/tree/src/main/java/org/richfaces/renderkit/TreeRendererBase.java
===================================================================
---
branches/3.0.2/richfaces/tree/src/main/java/org/richfaces/renderkit/TreeRendererBase.java 2007-07-04
14:48:13 UTC (rev 1465)
+++
branches/3.0.2/richfaces/tree/src/main/java/org/richfaces/renderkit/TreeRendererBase.java 2007-07-04
15:24:27 UTC (rev 1466)
@@ -37,7 +37,6 @@
import org.ajax4jsf.ajax.repeat.DataVisitor;
import org.ajax4jsf.framework.renderer.AjaxRendererUtils;
-import org.ajax4jsf.framework.renderer.ComponentVariables;
import org.ajax4jsf.framework.renderer.ComponentsVariableResolver;
import org.ajax4jsf.framework.renderer.RendererUtils;
import org.ajax4jsf.framework.util.javascript.JSFunction;
@@ -147,8 +146,6 @@
private final ResponseWriter writer;
- private final StringHolder holder;
-
private final Flag flag;
private final UITree tree;
@@ -158,10 +155,9 @@
private TreeStateAdvisor methodBindingAdvisor = null;
private DataVisitorWithLastElement(ResponseWriter writer,
- StringHolder holder, Flag flag, UITree tree,
+ Flag flag, UITree tree,
TreeDataModelEventNavigator navigator) {
this.writer = writer;
- this.holder = holder;
this.flag = flag;
this.tree = tree;
this.navigator = navigator;
@@ -174,10 +170,6 @@
processAdvisors(context, (TreeRowKey)rowKey);
- if (tree.isSelected()) {
- holder.setValue(tree.getNodeFacet().getClientId(context));
- }
-
if (!flag.isFlagSet()) {
closeLevelDownTable(context, tree, writer);
openLevelDownTable(context, tree, writer);
@@ -350,24 +342,34 @@
}
public String encodeSelectionStateInput(FacesContext context, UITree tree) throws
IOException {
- ComponentVariables variables = ComponentsVariableResolver.getVariables(this, tree);
- Object object = variables.getVariable("selectionId");
- if (object != null) {
- ResponseWriter writer = context.getResponseWriter();
- writer.startElement("input", tree);
- writer.writeAttribute("type", "hidden", null);
- String selectionHolderInputId = tree.getSelectionStateInputName(context);
- writer.writeAttribute("id", selectionHolderInputId, null);
- writer.writeAttribute("name", selectionHolderInputId, null);
-
- writer.writeAttribute("value", object,
- null);
- writer.endElement("input");
-
- return selectionHolderInputId;
+ String result = "";
+ TreeState treeState = (TreeState) tree.getComponentState();
+ TreeRowKey selectedNodeKey = treeState.getSelectedNode();
+ if (selectedNodeKey != null) {
+ Object rowKey = tree.getRowKey();
+ try {
+ tree.setRowKey(selectedNodeKey);
+ result = tree.getNodeFacet().getClientId(context);
+ } finally {
+ try {
+ tree.setRowKey(rowKey);
+ } catch (Exception e) {
+ context.getExternalContext().log(e.getMessage(), e);
+ }
+ }
}
+
+ ResponseWriter writer = context.getResponseWriter();
+ writer.startElement("input", tree);
+ writer.writeAttribute("type", "hidden", null);
+ String selectionHolderInputId = tree.getSelectionStateInputName(context);
+ writer.writeAttribute("id", selectionHolderInputId, null);
+ writer.writeAttribute("name", selectionHolderInputId, null);
- return null;
+ writer.writeAttribute("value", result, null);
+ writer.endElement("input");
+
+ return selectionHolderInputId;
}
protected String getAjaxScript(FacesContext context, UITree tree) {
@@ -457,8 +459,6 @@
TreeRowKey rowKey = (TreeRowKey) key;
- final StringHolder selectionValueHolder = new StringHolder();
-
//Object savedRowKey = input.getRowKey();
try {
input.captureOrigValue();
@@ -500,7 +500,7 @@
};
input.walk(context, new DataVisitorWithLastElement(writer,
- selectionValueHolder, droppedDownToLevelFlag, input,
+ droppedDownToLevelFlag, input,
levelNavigator), treeRange, key, null);
if (key != null) {
@@ -508,14 +508,6 @@
}
levelNavigator.followRowKey(context, null);
-
- ComponentVariables variables = ComponentsVariableResolver.getVariables(this, input);
- String value = selectionValueHolder.getValue();
- if (value != null) {
- variables.setVariable("selectionId", value);
- } else if (rowKey == null) {
- variables.setVariable("selectionId", "");
- }
} finally {
input.setRowKey(context, null);
input.restoreOrigValue();
@@ -559,16 +551,4 @@
public boolean isFlagSet() {
return flag;
}
-}
-
-class StringHolder {
- private String value;
-
- public String getValue() {
- return value;
- }
-
- public void setValue(String value) {
- this.value = value;
- }
}
\ No newline at end of file
Modified:
branches/3.0.2/richfaces/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree-item.js
===================================================================
---
branches/3.0.2/richfaces/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree-item.js 2007-07-04
14:48:13 UTC (rev 1465)
+++
branches/3.0.2/richfaces/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree-item.js 2007-07-04
15:24:27 UTC (rev 1466)
@@ -7,7 +7,7 @@
this.switchType = switchType;
this.tree = $(tree);
this.elements = {};
- ($(id)).object = this;
+ //($(id)).object = this; //dublicate: see getElements()
this.toggleOnClick = toggleOnClick;
this.getElements();
@@ -48,7 +48,7 @@
},
getElements: function() {
- //($(this.id)).object = this; //dublicate: see initialize()
+ ($(this.id)).object = this;
this.nodeStateInput = $(this.id + "NodeExpanded");
this.childs = [];
var childsRowId = this.id + Tree.ID_DEVIDER + Tree.ID_CHILDS_ROW;