Author: nbelaevski
Date: 2007-10-24 15:40:02 -0400 (Wed, 24 Oct 2007)
New Revision: 3517
Modified:
branches/3.1.x/framework/api/src/main/java/org/richfaces/model/StackingTreeModel.java
branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/component/UIDataAdaptor.java
branches/3.1.x/ui/tree/src/main/java/org/richfaces/renderkit/TreeRendererBase.java
Log:
http://jira.jboss.com/jira/browse/RF-980
Modified:
branches/3.1.x/framework/api/src/main/java/org/richfaces/model/StackingTreeModel.java
===================================================================
---
branches/3.1.x/framework/api/src/main/java/org/richfaces/model/StackingTreeModel.java 2007-10-24
19:14:03 UTC (rev 3516)
+++
branches/3.1.x/framework/api/src/main/java/org/richfaces/model/StackingTreeModel.java 2007-10-24
19:40:02 UTC (rev 3517)
@@ -76,12 +76,8 @@
return ((StackEntry) stackEntries.getLast()).model;
}
- return null;
- //FIXME: Maksim: Handle deleted entries correctly
-/*
throw new IllegalStateException(
"No tree element available or row key not set!");
-*/
}
public boolean isEmpty() {
@@ -226,12 +222,9 @@
if (isRowAvailable()) {
return null;
}
- return null;
- //FIXME: Maksim: Handle deleted entries correctly
-/*
+
throw new IllegalStateException(
"No tree element available or row key not set!");
-*/
}
/*
@@ -252,12 +245,9 @@
return true;
}
- return true;
- //FIXME: Maksim: Handle deleted entries correctly
-/*
+
throw new IllegalStateException(
"No tree element available or row key not set!");
-*/
}
protected StackingTreeModel getRoot() {
@@ -491,12 +481,8 @@
return lastEntry.model.rowData;
}
- return null;
- //FIXME: Maksim: Handle deleted entries correctly
- /*
throw new IllegalStateException(
"No tree element available or row key not set!");
- */
}
/*
Modified:
branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/component/UIDataAdaptor.java
===================================================================
---
branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/component/UIDataAdaptor.java 2007-10-24
19:14:03 UTC (rev 3516)
+++
branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/component/UIDataAdaptor.java 2007-10-24
19:40:02 UTC (rev 3517)
@@ -259,22 +259,35 @@
public void setRowIndex(int index) {
FacesContext faces = FacesContext.getCurrentInstance();
ExtendedDataModel localModel = getExtendedDataModel();
+
+ boolean rowAvailable = isRowAvailable();
+
// if(key == localModel.getRowIndex()){
// return;
// }
- // save child state
- this.saveChildState(faces);
+
+ if (rowAvailable) {
+ // save child state
+ this.saveChildState(faces);
+ }
+
// Set current model row by int, but immediately get value from model.
// for compability, complex models must provide values map between
// integer and key value.
localModel.setRowIndex(index);
+ rowAvailable = isRowAvailable();
+
this._rowKey = localModel.getRowKey();
this._clientId = null;
- boolean rowSelected = this._rowKey != null;
+
+ boolean rowSelected = this._rowKey != null && rowAvailable;
setupVariable(faces, localModel, rowSelected);
- // restore child state
- this.restoreChildState(faces);
+
+ if (rowAvailable) {
+ // restore child state
+ this.restoreChildState(faces);
+ }
}
/*
@@ -312,18 +325,29 @@
*/
public void setRowKey(FacesContext faces, Object key) {
ExtendedDataModel localModel = getExtendedDataModel();
- // save child state
- this.saveChildState(faces);
+
+ boolean rowAvailable = isRowAvailable();
+
+ if (rowAvailable) {
+ // save child state
+ this.saveChildState(faces);
+ }
+
this._rowKey = key;
this._clientId = null;
+
localModel.setRowKey(key);
+ rowAvailable = isRowAvailable();
- boolean rowSelected = key != null;
+ boolean rowSelected = key != null && rowAvailable;
+ //XXX check for row availability
setupVariable(faces, localModel, rowSelected);
- // restore child state
- this.restoreChildState(faces);
-
+
+ if (rowAvailable) {
+ // restore child state
+ this.restoreChildState(faces);
+ }
}
/*
@@ -485,6 +509,8 @@
* component state will be put into request scope attributes with names
* given by "var" and "varState" bean properties.
*
+ * Changed: does not check for row availability now
+ *
* @param faces
* current faces context
* @param localModel
@@ -493,7 +519,7 @@
protected void setupVariable(FacesContext faces, DataModel localModel,
boolean rowSelected) {
Map attrs = faces.getExternalContext().getRequestMap();
- if (rowSelected && isRowAvailable()) {
+ if (rowSelected/*&& isRowAvailable()*/) {
// Current row data.
setupVariable(getVar(), attrs, localModel.getRowData());
// Component state variable.
Modified:
branches/3.1.x/ui/tree/src/main/java/org/richfaces/renderkit/TreeRendererBase.java
===================================================================
---
branches/3.1.x/ui/tree/src/main/java/org/richfaces/renderkit/TreeRendererBase.java 2007-10-24
19:14:03 UTC (rev 3516)
+++
branches/3.1.x/ui/tree/src/main/java/org/richfaces/renderkit/TreeRendererBase.java 2007-10-24
19:40:02 UTC (rev 3517)
@@ -22,10 +22,10 @@
package org.richfaces.renderkit;
import java.io.IOException;
+import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -34,6 +34,7 @@
import javax.faces.FacesException;
import javax.faces.component.NamingContainer;
import javax.faces.component.UIComponent;
+import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.faces.el.MethodBinding;
@@ -50,7 +51,6 @@
import org.richfaces.component.state.TreeState;
import org.richfaces.component.state.TreeStateAdvisor;
import org.richfaces.model.LastElementAware;
-import org.richfaces.model.ListRowKey;
import org.richfaces.model.TreeRange;
import org.richfaces.model.TreeRowKey;
@@ -367,28 +367,6 @@
NSUtils.writeNameSpace(context, component);
}
-
- private TreeRowKey parentRowKey(TreeRowKey key) {
- //If depth is > 1, return parent row key
- int depth = key.depth();
- TreeRowKey rowKey = key;
-
- if (depth > 1) {
- List keyComps = new ArrayList(depth);
-
- for(Iterator iter = key.iterator(); iter.hasNext(); ) {
- Object next = iter.next();
- if (iter.hasNext()) {
- keyComps.add(next);
- }
- }
-
- rowKey = new ListRowKey(keyComps);
- }
-
- return rowKey;
- }
-
public void encodeAjaxChildren(FacesContext context, UIComponent component,
String path, Set ids, Set renderedAreas) throws IOException {
super.encodeAjaxChildren(context, component, path, ids, renderedAreas);
@@ -416,30 +394,14 @@
try {
Set ajaxKeys = tree.getAllAjaxKeys();
-
if (ajaxKeys != null) {
- Set aKeys = new HashSet();
-
- for(Iterator it = ajaxKeys.iterator(); it.hasNext(); ) {
- TreeRowKey treeRowKey = (TreeRowKey) it.next();
- treeRowKey = parentRowKey(treeRowKey);
-
- if (treeRowKey.depth() > 0) {
- aKeys.add(treeRowKey);
- }
- }
- ajaxKeys = aKeys;
- }
-
-
- if (ajaxKeys != null) {
List sortedKeys = new ArrayList(ajaxKeys.size());
sortedKeys.addAll(ajaxKeys);
Collections.sort(sortedKeys, treeRowKeyComparator);
Iterator ajaxKeysItr = sortedKeys.iterator();
TreeRowKey lastKey = null;
boolean nullRoot = false;
-
+
while (!nullRoot && ajaxKeysItr.hasNext()) {
TreeRowKey key = (TreeRowKey) ajaxKeysItr.next();
@@ -459,48 +421,35 @@
key = null;
}
-
-
-
tree.setRowKey(context, key);
-
- if (key != null) {
- int d = key.depth();
- List components = new ArrayList(d);
-
- for(Iterator iter = key.iterator(); iter.hasNext();
components.add(iter.next()));
-
- while(!tree.isRowAvailable()) {
-
- key = new ListRowKey(components.subList(0, d--));
-
- tree.setRowKey(context, key);
+
+ if (tree.isRowAvailable()) {
+ String treeClientId;
+ if (key == null) {
+ treeClientId = tree.getClientId(context);
+ } else {
+ treeClientId = tree.getNodeFacet().getClientId(context);
}
- }
-
-
- //key.getPath().
-
- //TODO: In case of deleted entry, try to update its parent
- //ey.getSubPathIterator(fromIndex)
-
-
- String treeClientId;
- if (key == null) {
- treeClientId = tree.getClientId(context);
- } else {
- treeClientId = tree.getNodeFacet().getClientId(context);
- }
- String treeChildrenId = treeClientId + NamingContainer.SEPARATOR_CHAR +
"childs";
-
- writeContent(context, tree, key);
- encodeScripts = true;
- renderedAreas.add(treeClientId);
- encodedAreaIds.add(treeClientId);
+ String treeChildrenId = treeClientId + NamingContainer.SEPARATOR_CHAR +
"childs";
+
+ writeContent(context, tree, key);
+ encodeScripts = true;
+ renderedAreas.add(treeClientId);
+ encodedAreaIds.add(treeClientId);
- renderedAreas.add(treeChildrenId);
- //encodedAreaIds.add(id+":childs");
+ renderedAreas.add(treeChildrenId);
+ //encodedAreaIds.add(id+":childs");
+ } else {
+ String cid = tree.getClientId(context);
+ String message = MessageFormat.format(
+ "Failed to re-render tree node: {0} due to model data unavailability!
" +
+ "Maybe parent node should be re-rendered instead?",
+ new Object[] { cid });
+
+ ExternalContext externalContext = context.getExternalContext();
+ externalContext.log(message);
+ }
}
//ajaxKeys.clear();
}