Author: nbelaevski
Date: 2008-06-03 17:44:19 -0400 (Tue, 03 Jun 2008)
New Revision: 8895
Modified:
trunk/ui/tree/src/main/java/org/richfaces/component/UITree.java
Log:
http://jira.jboss.com/jira/browse/RF-3595
Modified: trunk/ui/tree/src/main/java/org/richfaces/component/UITree.java
===================================================================
--- trunk/ui/tree/src/main/java/org/richfaces/component/UITree.java 2008-06-03 21:43:18
UTC (rev 8894)
+++ trunk/ui/tree/src/main/java/org/richfaces/component/UITree.java 2008-06-03 21:44:19
UTC (rev 8895)
@@ -29,9 +29,7 @@
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;
@@ -959,94 +957,54 @@
return null;
}
- public boolean invokeOnComponent(FacesContext context, String clientId, ContextCallback
callback) throws FacesException {
- if (null == context || null == clientId || null == callback) {
- throw new NullPointerException();
- }
+ private static final Pattern SEPARATOR = Pattern.compile("(?<!" +
ListRowKey.SEPARATOR_ESCAPE_CHAR + ")\\"
+ + NamingContainer.SEPARATOR_CHAR + "\\" + SEPARATOR_CHAR);
- boolean found = false;
- if (clientId.equals(this.getClientId(context))) {
- try {
- callback.invokeContextCallback(context, this);
- return true;
- } catch (Exception e) {
- throw new FacesException(e);
+ @Override
+ protected String extractKeySegment(FacesContext context, String tailId) {
+ Matcher matcher = SEPARATOR.matcher(tailId);
+ if (matcher.find()) {
+ return tailId.substring(0, matcher.start());
+ } else {
+ return null;
}
- } else {
- Iterator<UIComponent> itr = this.getFacetsAndChildren();
+ }
+
+ @Override
+ protected Iterator<UIComponent> invocableChildren() {
+ return dataChildren();
+ }
+
+ private static final Converter KEY_CONVERTER = new Converter() {
- while (itr.hasNext() && !found) {
- found = itr.next().invokeOnComponent(context, clientId,
- callback);
- }
- }
+ public Object getAsObject(FacesContext context, UIComponent component, String value) {
+ if (component == null || context == null) {
+ throw new NullPointerException();
+ }
- 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);
- }
+ if (value == null || value.length() == 0) {
+ return null;
}
- }
- }
- }
- return false;
- }
+ UITree tree = (UITree) component;
+ AbstractTreeDataModel dataModel = (AbstractTreeDataModel)
tree.getExtendedDataModel();
+ Object rowKey = dataModel.convertToKey(context, value, tree, null);
- 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);
- }
+ return rowKey;
}
public String getAsString(FacesContext context, UIComponent component, Object value) {
- if (component == null || context == null) {
- throw new NullPointerException();
- }
+ if (component == null || context == null) {
+ throw new NullPointerException();
+ }
- if (value == null) {
- return null;
- }
-
- return value.toString() + NamingContainer.SEPARATOR_CHAR;
+ if (value == null) {
+ return null;
+ }
+
+ return value.toString() + NamingContainer.SEPARATOR_CHAR;
}
- };
+ };
@Override
public Converter getRowKeyConverter() {