Author: abelevich
Date: 2007-10-10 09:58:12 -0400 (Wed, 10 Oct 2007)
New Revision: 3309
Modified:
trunk/ui/tabPanel/src/main/java/org/richfaces/renderkit/TabHeaderRendererBase.java
Log:
add support for f:param if tabPanel mode is server(RF-1090)
Modified:
trunk/ui/tabPanel/src/main/java/org/richfaces/renderkit/TabHeaderRendererBase.java
===================================================================
---
trunk/ui/tabPanel/src/main/java/org/richfaces/renderkit/TabHeaderRendererBase.java 2007-10-10
12:54:00 UTC (rev 3308)
+++
trunk/ui/tabPanel/src/main/java/org/richfaces/renderkit/TabHeaderRendererBase.java 2007-10-10
13:58:12 UTC (rev 3309)
@@ -21,7 +21,20 @@
package org.richfaces.renderkit;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIParameter;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
+import org.ajax4jsf.Messages;
import org.ajax4jsf.javascript.JSFunction;
+import org.ajax4jsf.javascript.ScriptUtils;
import org.ajax4jsf.renderkit.AjaxRendererUtils;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
import org.ajax4jsf.util.HtmlDimensions;
@@ -30,13 +43,7 @@
import org.richfaces.component.UITabPanel;
import org.richfaces.component.util.HtmlUtil;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-import java.io.IOException;
-import java.util.Map;
-
/**
* @author Nick Belaevski - nbelaevski(a)exadel.com
* created 12.01.2007
@@ -48,7 +55,41 @@
protected Class getComponentClass() {
return UITab.class;
}
-
+
+ // find and encode UIParameter's components
+ public List encodeParams(FacesContext context, UITab component) throws IOException {
+
+ UITab menuItem = component;
+ List params = new ArrayList();
+ StringBuffer buff = new StringBuffer();
+
+ List children = menuItem.getChildren();
+ for (Iterator iterator = children.iterator(); iterator.hasNext();) {
+ UIComponent child = (UIComponent) iterator.next();
+
+ if(child instanceof UIParameter){
+
+ UIParameter param = (UIParameter)child;
+ String name = param.getName();
+
+ if (null == name) {
+ throw new IllegalArgumentException(Messages.getMessage(
+ Messages.UNNAMED_PARAMETER_ERROR, component.getClientId(context)));
+ }
+
+ Object value = param.getValue();
+ buff.append("_params[");
+ buff.append(ScriptUtils.toScript(name));
+ buff.append("] = ");
+ buff.append(ScriptUtils.toScript(value));
+ buff.append(";");
+ params.add(buff.toString());
+ }
+ }
+
+ return params;
+ }
+
public void encodeTabLabel(FacesContext context, UITab tab) throws IOException {
ResponseWriter writer = context.getResponseWriter();
@@ -90,7 +131,14 @@
String script = buffer.toString();
writer.writeAttribute(HTML.onclick_ATTRIBUTE, activeCheck +
eventCheck + script, null);
} else {
- StringBuffer script = new StringBuffer("var _formName =
A4J.findForm(this).id; var _paramName = '" + clientId +
"_server_submit'; var _params = new Object(); _params[_paramName] = _paramName;
_JSFFormSubmit('");
+ StringBuffer script = new StringBuffer("var _formName =
A4J.findForm(this).id; var _paramName = '" + clientId +
"_server_submit'; var _params = new Object(); _params[_paramName] = _paramName;
");
+ List params = encodeParams(context, tab);
+
+ for (Iterator iterator = params.iterator(); iterator.hasNext();) {
+ script.append(iterator.next());
+ }
+
+ script.append("_JSFFormSubmit('");
script.append(clientId);
script.append("', _formName, null, _params);");
script.append("this.onclick = null;
_clearJSFFormParameters(_formName, null, [_paramName]);");