Author: nbelaevski
Date: 2007-06-05 14:10:20 -0400 (Tue, 05 Jun 2007)
New Revision: 1029
Added:
trunk/richfaces/common/src/main/resources/org/richfaces/renderkit/html/scripts/form.js
Modified:
trunk/richfaces/tree/src/main/java/org/richfaces/component/UITree.java
trunk/richfaces/tree/src/main/java/org/richfaces/renderkit/NodeRendererBase.java
trunk/richfaces/tree/src/main/resources/org/richfaces/renderkit/html/css/tree.xcss
trunk/richfaces/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree-item.js
trunk/richfaces/tree/src/main/templates/htmlTree.jspx
trunk/richfaces/tree/src/main/templates/htmlTreeNode.jspx
trunk/richfaces/tree/src/test/java/org/richfaces/component/TreeComponentTest.java
Log:
http://jira.jboss.com/jira/browse/RF-85 fixed
Added:
trunk/richfaces/common/src/main/resources/org/richfaces/renderkit/html/scripts/form.js
===================================================================
---
trunk/richfaces/common/src/main/resources/org/richfaces/renderkit/html/scripts/form.js
(rev 0)
+++
trunk/richfaces/common/src/main/resources/org/richfaces/renderkit/html/scripts/form.js 2007-06-05
18:10:20 UTC (rev 1029)
@@ -0,0 +1,19 @@
+if (!window.Richfaces) {
+ window.Richfaces = {};
+}
+
+Richfaces.jsFormSubmit = function(linkId, formName, target, params) {
+ var form = document.getElementById(formName);
+ if (form) {
+ var formTarget = form.target;
+ var paramNames = new Array();
+ if (params) {
+ for (var n in params) {
+ paramNames.push(n);
+ }
+ }
+
+ _JSFFormSubmit(linkId,formName,target,params);
+ _clearJSFFormParameters(formName, formTarget, paramNames);
+ }
+}
\ No newline at end of file
Modified: trunk/richfaces/tree/src/main/java/org/richfaces/component/UITree.java
===================================================================
--- trunk/richfaces/tree/src/main/java/org/richfaces/component/UITree.java 2007-06-05
17:55:47 UTC (rev 1028)
+++ trunk/richfaces/tree/src/main/java/org/richfaces/component/UITree.java 2007-06-05
18:10:20 UTC (rev 1029)
@@ -28,8 +28,6 @@
import javax.faces.application.Application;
import javax.faces.component.NamingContainer;
-import javax.faces.component.UIComponent;
-import javax.faces.component.UIForm;
import javax.faces.component.UIOutput;
import javax.faces.context.FacesContext;
import javax.faces.event.AbortProcessingException;
@@ -86,9 +84,6 @@
public final static String SWITCH_AJAX = "ajax";
- public final static String EXPANDED_STATE_PARAMETER_NAME =
NamingContainer.SEPARATOR_CHAR
- + "expanded";
-
public final static String SELECTED_NODE_PARAMETER_NAME =
NamingContainer.SEPARATOR_CHAR
+ "selectedNode";
@@ -97,8 +92,6 @@
public static final String SELECTION_INPUT_ATTRIBUTE = "_selectionInput";
- public static final String TOGGLE_LINK_ATTRIBUTE = "_toggleLink";
-
public final static String TREE_DATA_LOCATOR_BINDING = "treeDataLocator";
public final static String DEFAULT_SELECTED_CSS_CLASS = "dr-tree-i-sel";
@@ -344,23 +337,7 @@
if (!this.isRendered())
return;
- UIComponent formComponent = this;
- do {
- formComponent = formComponent.getParent();
- } while (formComponent != null && !(formComponent instanceof UIForm));
-
- Map requestParameterMap = faces.getExternalContext()
- .getRequestParameterMap();
- if (formComponent != null) {
- String id = formComponent.getClientId(faces)
- + NamingContainer.SEPARATOR_CHAR + "_idcl";
- String string = (String) requestParameterMap.get(id);
-
- if (string != null) {
- this.getAttributes().put(TOGGLE_LINK_ATTRIBUTE, string);
- }
- }
-
+ Map requestParameterMap = faces.getExternalContext().getRequestParameterMap();
if (requestParameterMap.get(getBaseClientId(faces)
+ SELECTED_NODE_PARAMETER_NAME) != null) {
getAttributes().put(
@@ -368,12 +345,6 @@
requestParameterMap.get(getBaseClientId(faces)
+ SELECTED_NODE_PARAMETER_NAME));
}
- getAttributes().put(
- EXPANDED_STATE_PARAMETER_NAME,
- new Boolean((String) requestParameterMap
- .get(getBaseClientId(faces)
- + EXPANDED_STATE_PARAMETER_NAME)));
-
Object selectionInputValue = requestParameterMap
.get(getSelectionStateInputName(faces));
if (selectionInputValue instanceof String) {
@@ -394,8 +365,6 @@
} finally {
getAttributes().remove(SELECTION_INPUT_ATTRIBUTE);
getAttributes().remove(SELECTED_NODE_PARAMETER_NAME);
- getAttributes().remove(TOGGLE_LINK_ATTRIBUTE);
- getAttributes().remove(EXPANDED_STATE_PARAMETER_NAME);
}
// if (treePersister != null) {
Modified:
trunk/richfaces/tree/src/main/java/org/richfaces/renderkit/NodeRendererBase.java
===================================================================
---
trunk/richfaces/tree/src/main/java/org/richfaces/renderkit/NodeRendererBase.java 2007-06-05
17:55:47 UTC (rev 1028)
+++
trunk/richfaces/tree/src/main/java/org/richfaces/renderkit/NodeRendererBase.java 2007-06-05
18:10:20 UTC (rev 1029)
@@ -9,7 +9,6 @@
import java.util.Map;
import java.util.Set;
-import javax.faces.component.NamingContainer;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
@@ -37,6 +36,8 @@
*/
public abstract class NodeRendererBase extends CompositeRenderer {
+ protected static final String NODE_EXPANDED_INPUT_SUFFIX = "NodeExpanded";
+
private static class TreeNodeOptions extends ScriptOptions {
public TreeNodeOptions(UIComponent component) {
@@ -45,7 +46,7 @@
Map params = new HashMap();
if (((Boolean) (component.getAttributes().get("isLastElement")))
- .booleanValue()) {
+ .booleanValue()) {
UITree tree = ((UITreeNode) component).getUITree();
@@ -72,11 +73,9 @@
if ("handle".equals(to) && treeNode.getUITree().isToggleOnClick() ||
"mainRow".equals(to) && !treeNode.getUITree().isToggleOnClick())
return "";
-
+
UITree tree = treeNode.getUITree();
String id = treeNode.getClientId(context);
- String toggleId = id + NamingContainer.SEPARATOR_CHAR
- + UITree.TOGGLE_LINK_ATTRIBUTE;
if (UITree.SWITCH_AJAX.equals(tree.getSwitchType())) {
JSFunction function = AjaxRendererUtils.buildAjaxFunction(tree.getNodeFacet(),
@@ -85,12 +84,9 @@
tree.getNodeFacet());
Map parameters = (Map) eventOptions.get("parameters");
parameters.remove(id);
- parameters.put(toggleId, toggleId);
- parameters.put(tree.getBaseClientId(context)
- + UITree.EXPANDED_STATE_PARAMETER_NAME, String.valueOf(tree
+ parameters.put(id + NODE_EXPANDED_INPUT_SUFFIX, String.valueOf(!tree
.isExpanded()));
-
if (((Boolean) (treeNode.getAttributes().get("isLastElement")))
.booleanValue()) {
parameters.put(tree.getBaseClientId(context)
@@ -103,20 +99,21 @@
buffer.append(";");
return buffer.toString();
} else if (UITree.SWITCH_SERVER.equals(tree.getSwitchType())) {
+ String paramName = id + NODE_EXPANDED_INPUT_SUFFIX;
+
StringBuffer result = new StringBuffer();
result.append('{');
+ result.append("var form = A4J.findForm(this);");
result.append("var params = new Object();");
result.append("params['");
- result.append(tree.getBaseClientId(context)
- + UITree.EXPANDED_STATE_PARAMETER_NAME);
-
+ result.append(paramName);
result.append("'] = ");
- result.append(tree.isExpanded());
+ result.append(!tree.isExpanded());
result.append(';');
- result.append("_JSFFormSubmit('");
- result.append(toggleId);
+ result.append("Richfaces.jsFormSubmit('");
+ result.append(id);
result.append("', ");
- result.append("A4J.findForm(this).id, ");
+ result.append("form.id, ");
result.append("'', ");
result.append("params);};");
@@ -127,7 +124,7 @@
}
public void initializeLines(FacesContext context, UITreeNode treeNode)
- throws IOException {
+ throws IOException {
ComponentVariables variables = ComponentsVariableResolver.getVariables(
this, treeNode);
@@ -142,16 +139,16 @@
}
if (tree.isExpanded()) {
variables
- .setVariable("lineFirst", "dr-tree-h-ic-line-exp");
+ .setVariable("lineFirst", "dr-tree-h-ic-line-exp");
} else {
variables.setVariable("lineFirst",
- "dr-tree-h-ic-line-clp");
+ "dr-tree-h-ic-line-clp");
}
}
}
public void initializeResources(FacesContext context, UITreeNode treeNode)
- throws IOException {
+ throws IOException {
ComponentVariables variables = ComponentsVariableResolver.getVariables(
this, treeNode);
@@ -181,8 +178,8 @@
resource += " " + cssClass;
}
variables.setVariable("selectedClass", resource);
-
-
+
+
resource = ViewUtil.getResourceURL(treeNode.getIcon());
if (resource == null) {
resource = ViewUtil.getResourceURL(tree.getIcon());
@@ -209,12 +206,12 @@
if (resource != null) {
variables.setVariable("expanded", resource);
}
-
+
resource = ViewUtil.getResourceURL(treeNode.getIconLeaf());
if (resource == null) {
resource = ViewUtil.getResourceURL(tree.getIconLeaf());
}
-
+
if (resource != null) {
variables.setVariable("leaf", resource);
}
@@ -224,18 +221,22 @@
if (node.getUITree().isExpanded() ^ expandHandle) {
return "display: none;";
}
-
+
return "";
}
-
+
public String getHandleCollapsedDisplayStyle(FacesContext context, UITreeNode node) {
return getHandleDisplayStyle(context, node, false);
}
-
+
public String getHandleExpandedDisplayStyle(FacesContext context, UITreeNode node) {
return getHandleDisplayStyle(context, node, true);
}
+ public String getExpandedValue(FacesContext context, UITreeNode node) {
+ return Boolean.toString(node.getUITree().isExpanded());
+ }
+
protected void doDecode(FacesContext context, UIComponent component) {
super.doDecode(context, component);
@@ -247,32 +248,30 @@
TreeState componentState = (TreeState) tree.getComponentState();
TreeRowKey key = (TreeRowKey) tree.getRowKey();
- String toggleId = id + NamingContainer.SEPARATOR_CHAR
- + UITree.TOGGLE_LINK_ATTRIBUTE;
- if (null != requestMap.get(toggleId)
- || toggleId.equals(tree.getAttributes().get(
- UITree.TOGGLE_LINK_ATTRIBUTE))) {
+ String nodeExpandedId = id + NODE_EXPANDED_INPUT_SUFFIX;
+ Object nodeExpandedValue = requestMap.get(nodeExpandedId);
+ if (nodeExpandedValue != null) {
+ boolean nodeExpanded = Boolean.valueOf(nodeExpandedValue.toString()).booleanValue();
+ if (tree.isExpanded() ^ nodeExpanded) {
+ if (nodeExpanded) {
+ new ExpandNodeCommandEvent(tree, key).queue();
+ } else {
+ new CollapseNodeCommandEvent(tree, key).queue();
+ }
- if (((Boolean) tree.getAttributes().get(
- UITree.EXPANDED_STATE_PARAMETER_NAME)).booleanValue()) {
+ new NodeExpandedEvent(node).queue();
+ new NodeExpandedEvent(tree).queue();
- new CollapseNodeCommandEvent(tree, key).queue();
- } else {
- new ExpandNodeCommandEvent(tree, key).queue();
- }
+ if (UITree.SWITCH_AJAX.equals(tree.getSwitchType()) &&
AjaxRendererUtils.isAjaxRequest(context)) {
+ Set ajaxKeys = tree.getAjaxKeys();
+ if (ajaxKeys == null) {
+ ajaxKeys = new HashSet();
- new NodeExpandedEvent(node).queue();
- new NodeExpandedEvent(tree).queue();
+ tree.setAjaxKeys(ajaxKeys);
+ }
- if (AjaxRendererUtils.isAjaxRequest(context)) {
- Set ajaxKeys = tree.getAjaxKeys();
- if (ajaxKeys == null) {
- ajaxKeys = new HashSet();
-
- tree.setAjaxKeys(ajaxKeys);
+ ajaxKeys.add(key);
}
-
- ajaxKeys.add(key);
}
}
Modified:
trunk/richfaces/tree/src/main/resources/org/richfaces/renderkit/html/css/tree.xcss
===================================================================
---
trunk/richfaces/tree/src/main/resources/org/richfaces/renderkit/html/css/tree.xcss 2007-06-05
17:55:47 UTC (rev 1028)
+++
trunk/richfaces/tree/src/main/resources/org/richfaces/renderkit/html/css/tree.xcss 2007-06-05
18:10:20 UTC (rev 1029)
@@ -7,6 +7,10 @@
.dr-tree {
}
+.dr-tree-h-input {
+ display: none;
+}
+
.dr-tree-h-ic {
width: 16px;
padding : 1px
Modified:
trunk/richfaces/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree-item.js
===================================================================
---
trunk/richfaces/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree-item.js 2007-06-05
17:55:47 UTC (rev 1028)
+++
trunk/richfaces/tree/src/main/resources/org/richfaces/renderkit/html/scripts/tree-item.js 2007-06-05
18:10:20 UTC (rev 1029)
@@ -49,6 +49,7 @@
getElements: function() {
($(this.id)).object = this;
+ this.nodeStateInput = $(this.id + "NodeExpanded");
this.childs = [];
var childsRowId = this.id + Tree.ID_DEVIDER + Tree.ID_CHILDS_ROW;
var mainRowId = this.id + Tree.ID_DEVIDER + Tree.ID_MAIN_ROW;
@@ -117,6 +118,10 @@
Element.addClassName(this.elements.icon, Tree.CLASS_ITEM_COLLAPSED);
}
+ if (this.nodeStateInput) {
+ this.nodeStateInput.value = "false";
+ }
+
this.fireCollapsionEvent();
} else {
this.elements.handleImgExpanded.style.display="";
@@ -126,6 +131,10 @@
Element.addClassName(this.elements.icon, Tree.CLASS_ITEM_EXPANDED);
}
+ if (this.nodeStateInput) {
+ this.nodeStateInput.value = "true";
+ }
+
this.fireExpansionEvent();
}
Modified: trunk/richfaces/tree/src/main/templates/htmlTree.jspx
===================================================================
--- trunk/richfaces/tree/src/main/templates/htmlTree.jspx 2007-06-05 17:55:47 UTC (rev
1028)
+++ trunk/richfaces/tree/src/main/templates/htmlTree.jspx 2007-06-05 18:10:20 UTC (rev
1029)
@@ -18,6 +18,7 @@
/org/ajax4jsf/framework/ajax/scripts/AJAX.js,
/org/richfaces/renderkit/html/scripts/utils.js,
/org/ajax4jsf/renderkit/html/scripts/form.js,
+ /org/richfaces/renderkit/html/scripts/form.js,
/org/richfaces/renderkit/html/scripts/events.js,
/org/richfaces/renderkit/html/scripts/tree.js,
/org/richfaces/renderkit/html/scripts/tree-selection.js,
Modified: trunk/richfaces/tree/src/main/templates/htmlTreeNode.jspx
===================================================================
--- trunk/richfaces/tree/src/main/templates/htmlTreeNode.jspx 2007-06-05 17:55:47 UTC (rev
1028)
+++ trunk/richfaces/tree/src/main/templates/htmlTreeNode.jspx 2007-06-05 18:10:20 UTC (rev
1029)
@@ -37,6 +37,19 @@
<div>
<jsp:scriptlet>
<![CDATA[
+ if
(org.richfaces.component.UITree.SWITCH_CLIENT.equals(component.getUITree().getSwitchType()))
{
+ ]]>
+ </jsp:scriptlet>
+ <input class="dr-tree-h-input" type="hidden"
id="#{clientId}NodeExpanded" name="#{clientId}NodeExpanded"
value="#{this:getExpandedValue(context,component)}" />
+ <jsp:scriptlet>
+ <![CDATA[
+ }
+ ]]>
+ </jsp:scriptlet>
+
+
+ <jsp:scriptlet>
+ <![CDATA[
if (component.getUITree().isLeaf()) {
]]>
</jsp:scriptlet>
Modified:
trunk/richfaces/tree/src/test/java/org/richfaces/component/TreeComponentTest.java
===================================================================
---
trunk/richfaces/tree/src/test/java/org/richfaces/component/TreeComponentTest.java 2007-06-05
17:55:47 UTC (rev 1028)
+++
trunk/richfaces/tree/src/test/java/org/richfaces/component/TreeComponentTest.java 2007-06-05
18:10:20 UTC (rev 1029)
@@ -84,6 +84,7 @@
javaScripts.add("/org/ajax4jsf/renderkit/html/scripts/form.js");
+ javaScripts.add("/org/richfaces/renderkit/html/scripts/form.js");
javaScripts.add("/org/richfaces/renderkit/html/scripts/events.js");
javaScripts.add("/org/richfaces/renderkit/html/scripts/tree.js");
javaScripts.add("/org/richfaces/renderkit/html/scripts/tree-selection.js");