Author: nbelaevski
Date: 2008-03-27 22:59:55 -0400 (Thu, 27 Mar 2008)
New Revision: 7344
Modified:
trunk/ui/tree/src/main/config/component/tree.xml
trunk/ui/tree/src/main/java/org/richfaces/component/UITree.java
Log:
http://jira.jboss.com/jira/browse/RF-2812
Modified: trunk/ui/tree/src/main/config/component/tree.xml
===================================================================
--- trunk/ui/tree/src/main/config/component/tree.xml 2008-03-28 02:59:48 UTC (rev 7343)
+++ trunk/ui/tree/src/main/config/component/tree.xml 2008-03-28 02:59:55 UTC (rev 7344)
@@ -256,6 +256,10 @@
null, a particular treeNode saves the current state
</description>
<methodargs>org.richfaces.component.UITree</methodargs>
+ </property>
+
+ <property hidden="true">
+ <name>rowKeyConverter</name>
</property>
</component>
Modified: trunk/ui/tree/src/main/java/org/richfaces/component/UITree.java
===================================================================
--- trunk/ui/tree/src/main/java/org/richfaces/component/UITree.java 2008-03-28 02:59:48
UTC (rev 7343)
+++ trunk/ui/tree/src/main/java/org/richfaces/component/UITree.java 2008-03-28 02:59:55
UTC (rev 7344)
@@ -24,12 +24,17 @@
import java.io.IOException;
import java.util.Iterator;
import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import javax.faces.FacesException;
import javax.faces.application.Application;
+import javax.faces.component.ContextCallback;
import javax.faces.component.NamingContainer;
import javax.faces.component.UIComponent;
import javax.faces.component.UIOutput;
import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
import javax.faces.el.MethodBinding;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.FacesEvent;
@@ -67,6 +72,7 @@
import org.richfaces.model.CacheableTreeDataModel;
import org.richfaces.model.ClassicCacheableTreeDataModel;
import org.richfaces.model.ClassicTreeDataModel;
+import org.richfaces.model.ListRowKey;
import org.richfaces.model.StackingTreeModel;
import org.richfaces.model.StackingTreeModelProvider;
import org.richfaces.model.SwingCacheableTreeDataModel;
@@ -883,6 +889,105 @@
return null;
}
+
+ public boolean invokeOnComponent(FacesContext context, String clientId, ContextCallback
callback) throws FacesException {
+ if (null == context || null == clientId || null == callback) {
+ throw new NullPointerException();
+ }
+
+ boolean found = false;
+ if (clientId.equals(this.getClientId(context))) {
+ try {
+ callback.invokeContextCallback(context, this);
+ return true;
+ } catch (Exception e) {
+ throw new FacesException(e);
+ }
+ } else {
+ Iterator<UIComponent> itr = this.getFacetsAndChildren();
+
+ while (itr.hasNext() && !found) {
+ found = itr.next().invokeOnComponent(context, clientId,
+ callback);
+ }
+ }
+
+ if (found) {
+ return true;
+ } else {
+ String baseId = getBaseClientId(context) + NamingContainer.SEPARATOR_CHAR;
+ if (clientId.startsWith(baseId)) {
+ String rowKeyString = clientId.substring(baseId.length());
+ String keyString = (String) getRowKeyConverter().getAsObject(context, this,
rowKeyString);
+ AbstractTreeDataModel dataModel = (AbstractTreeDataModel) getExtendedDataModel();
+ Object rowKey = dataModel.convertToKey(context, keyString, this, null);
+
+ if (rowKey != null) {
+ assert rowKey.toString().equals(rowKeyString);
+
+ Object oldKey = getRowKey();
+ try {
+ setRowKey(context, rowKey);
+
+ return getNodeFacet().invokeOnComponent(context, clientId, callback);
+ } finally {
+ try {
+ setRowKey(context, oldKey);
+ } catch (Exception e) {
+ context.getExternalContext().log(e.getMessage(), e);
+ }
+ }
+ }
+ }
+ }
+
+ return false;
+ }
+
+ private static final Pattern SEPARATOR = Pattern.compile("(?<!" +
ListRowKey.SEPARATOR_ESCAPE_CHAR + ")\\"
+ + NamingContainer.SEPARATOR_CHAR + "\\" + SEPARATOR_CHAR);
+
+ private static final Converter KEY_CONVERTER = new Converter() {
+
+ public Object getAsObject(FacesContext context, UIComponent component, String value) {
+ if (component == null || context == null) {
+ throw new NullPointerException();
+ }
+
+ if (value == null || value.length() == 0) {
+ return null;
+ }
+
+ Matcher matcher = SEPARATOR.matcher(value);
+ if (matcher.find()) {
+ return value.substring(0, matcher.start());
+ } else {
+ throw new IllegalArgumentException("Row key is illegally formed: " +
value);
+ }
+ }
+
+ public String getAsString(FacesContext context, UIComponent component, Object value) {
+ if (component == null || context == null) {
+ throw new NullPointerException();
+ }
+
+ if (value == null) {
+ return null;
+ }
+
+ return value.toString() + NamingContainer.SEPARATOR_CHAR;
+ }
+ };
+
+ @Override
+ public Converter getRowKeyConverter() {
+ return KEY_CONVERTER;
+ }
+
+ @Override
+ public void setRowKeyConverter(Converter rowKeyConverter) {
+ throw new UnsupportedOperationException();
+ }
}