Author: nbelaevski
Date: 2010-12-22 14:25:18 -0500 (Wed, 22 Dec 2010)
New Revision: 20750
Modified:
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTree.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeHandler.java
Log:
https://issues.jboss.org/browse/RF-10059
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-12-22
19:18:08 UTC (rev 20749)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTree.java 2010-12-22
19:25:18 UTC (rev 20750)
@@ -30,11 +30,9 @@
import javax.el.ELException;
import javax.el.MethodExpression;
import javax.el.ValueExpression;
-import javax.faces.application.Application;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.component.UpdateModelException;
-import javax.faces.component.html.HtmlOutputText;
import javax.faces.component.visit.VisitCallback;
import javax.faces.component.visit.VisitContext;
import javax.faces.component.visit.VisitResult;
@@ -100,10 +98,10 @@
public static final String SELECTION_META_COMPONENT_ID = "selection";
- private static final String DEFAULT_TREE_NODE_CREATED = AbstractTree.class.getName()
+ ":DEFAULT_TREE_NODE_CREATED";
+ public static final String DEFAULT_TREE_NODE_ID = "__defaultTreeNode";
+
+ public static final String DEFAULT_TREE_NODE_FACET_NAME = DEFAULT_TREE_NODE_ID;
- private static final String DEFAULT_TREE_NODE_ID = "__defaultTreeNode";
-
private static final class MatchingTreeNodePredicate implements
Predicate<UIComponent> {
private String type;
@@ -272,52 +270,22 @@
}
}
- private boolean isDefaultTreeNode(AbstractTreeNode node) {
- return DEFAULT_TREE_NODE_ID.equals(node.getId());
- }
-
public AbstractTreeNode findTreeNodeComponent() {
- FacesContext facesContext = getFacesContext();
-
String nodeType = getNodeType();
Iterator<UIComponent> nodesItr = findMatchingTreeNodeComponent(nodeType,
currentComponent);
- boolean hasOnlyDefaultNodes = true;
- while (nodesItr.hasNext()) {
-
- AbstractTreeNode node = (AbstractTreeNode) nodesItr.next();
-
- if (!isDefaultTreeNode(node)) {
- hasOnlyDefaultNodes = false;
+ if (nodesItr.hasNext()) {
+ while (nodesItr.hasNext()) {
+
+ AbstractTreeNode node = (AbstractTreeNode) nodesItr.next();
+
+ if (node.isRendered()) {
+ return node;
+ }
}
-
- if (!node.isRendered()) {
- continue;
- }
-
- if (!isDefaultTreeNode(node) || hasOnlyDefaultNodes) {
- return node;
- }
- }
-
- if (Strings.isNullOrEmpty(nodeType)) {
- if (getAttributes().put(DEFAULT_TREE_NODE_CREATED, Boolean.TRUE) != null) {
- return null;
- }
- //TODO default TreeNode is created when getRowKey() == null but it's not
used for presentational purposes
- Application application = facesContext.getApplication();
- AbstractTreeNode treeNode = (AbstractTreeNode)
application.createComponent(AbstractTreeNode.COMPONENT_TYPE);
- treeNode.setId(DEFAULT_TREE_NODE_ID);
-
- getChildren().add(treeNode);
-
- UIComponent text =
application.createComponent(HtmlOutputText.COMPONENT_TYPE);
- text.setValueExpression("value",
application.getExpressionFactory().createValueExpression(facesContext.getELContext(),
- "#{" + getVar() + "}", String.class));
- treeNode.getChildren().add(text);
-
- return treeNode;
+ } else if (Strings.isNullOrEmpty(nodeType)) {
+ return (AbstractTreeNode) getFacet(DEFAULT_TREE_NODE_FACET_NAME);
}
return null;
@@ -601,5 +569,5 @@
setupCurrentComponent();
super.restoreChildState(facesContext);
}
-
+
}
Modified:
trunk/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeHandler.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeHandler.java 2010-12-22
19:18:08 UTC (rev 20749)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeHandler.java 2010-12-22
19:25:18 UTC (rev 20750)
@@ -21,8 +21,16 @@
*/
package org.richfaces.view.facelets;
+import static org.richfaces.component.AbstractTree.DEFAULT_TREE_NODE_FACET_NAME;
+import static org.richfaces.component.AbstractTree.DEFAULT_TREE_NODE_ID;
+
+import javax.faces.application.Application;
+import javax.faces.component.UIComponent;
+import javax.faces.component.html.HtmlOutputText;
+import javax.faces.context.FacesContext;
import javax.faces.view.facelets.ComponentConfig;
import javax.faces.view.facelets.ComponentHandler;
+import javax.faces.view.facelets.FaceletContext;
import javax.faces.view.facelets.MetaRule;
import javax.faces.view.facelets.MetaRuleset;
import javax.faces.view.facelets.Metadata;
@@ -30,7 +38,10 @@
import javax.faces.view.facelets.TagAttribute;
import org.richfaces.component.AbstractTree;
+import org.richfaces.component.AbstractTreeNode;
+import com.google.common.base.Strings;
+
/**
* @author Nick Belaevski
*
@@ -63,4 +74,32 @@
metaRuleset.addRule(RULE);
return metaRuleset;
}
+
+ @Override
+ public void onComponentPopulated(FaceletContext ctx, UIComponent c, UIComponent
parent) {
+ super.onComponentPopulated(ctx, c, parent);
+
+ UIComponent defaultTreeNode = c.getFacet(DEFAULT_TREE_NODE_FACET_NAME);
+ if (defaultTreeNode == null) {
+ String var = ((AbstractTree) c).getVar();
+
+ if (Strings.isNullOrEmpty(var)) {
+ return;
+ }
+
+ FacesContext facesContext = ctx.getFacesContext();
+ Application application = facesContext.getApplication();
+
+ AbstractTreeNode treeNode = (AbstractTreeNode)
application.createComponent(AbstractTreeNode.COMPONENT_TYPE);
+ treeNode.setId(DEFAULT_TREE_NODE_ID);
+
+ c.getFacets().put(DEFAULT_TREE_NODE_FACET_NAME, treeNode);
+
+ UIComponent text =
application.createComponent(HtmlOutputText.COMPONENT_TYPE);
+
+ text.setValueExpression("value",
application.getExpressionFactory().createValueExpression(facesContext.getELContext(),
+ "#{" + var + "}", String.class));
+ treeNode.getChildren().add(text);
+ }
+ }
}