[seam-commits] Seam SVN: r7568 - branches/Seam_2_0/ui/src/main/java/org/jboss/seam/ui/renderkit.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Thu Mar 13 13:32:49 EDT 2008
Author: pete.muir at jboss.org
Date: 2008-03-13 13:32:49 -0400 (Thu, 13 Mar 2008)
New Revision: 7568
Modified:
branches/Seam_2_0/ui/src/main/java/org/jboss/seam/ui/renderkit/CommandButtonParameterRendererBase.java
Log:
backport r7567, JBSEAM-2588
Modified: branches/Seam_2_0/ui/src/main/java/org/jboss/seam/ui/renderkit/CommandButtonParameterRendererBase.java
===================================================================
--- branches/Seam_2_0/ui/src/main/java/org/jboss/seam/ui/renderkit/CommandButtonParameterRendererBase.java 2008-03-13 17:32:13 UTC (rev 7567)
+++ branches/Seam_2_0/ui/src/main/java/org/jboss/seam/ui/renderkit/CommandButtonParameterRendererBase.java 2008-03-13 17:32:49 UTC (rev 7568)
@@ -33,7 +33,6 @@
throws IOException
{
UIComponent actionComponent = component.getParent();
- String actionComponentId = actionComponent.getClientId(context);
UIComponent form = getUtils().getForm(actionComponent);
UIParameter parameter = (UIParameter) component;
if (getUtils().isCommandButton(actionComponent))
@@ -46,6 +45,8 @@
{
getLog().warn("Must set an id for the command buttons with s:conversationPropagation");
}
+
+
String functionBody =
"{" +
"if (document.getElementById)" +
@@ -68,10 +69,31 @@
"return true;" +
"}" +
"}";
+
+ String functionName = "cp_" + actionComponent.getId();
+
String functionCode =
- "document.getElementById('" + actionComponentId + "').onclick = " +
- "new Function(\"event\", \"" + functionBody + "\");";
+ "var " + functionName + " = " +
+ "new Function(\"event\", \"" + functionBody + "\");";
+
writer.write(functionCode);
+
+ // We are either written before the HTML element (e.g. a:commandButton)
+ // In this case we can simply prepend to the existing onClick
+
+ String existingOnClick = (String) actionComponent.getAttributes().get("onclick");
+
+ actionComponent.getAttributes().put("onclick", functionName + "();" + existingOnClick);
+
+ // But we also might be written after (e.g. JSF RI h:commandButton
+ // In this case we can use event capture
+
+ String functionRegister =
+ "if (document.getElementById('" + actionComponent.getClientId(context) + "'))" +
+ "{" +
+ "document.getElementById('" + actionComponent.getClientId(context) + "').onclick = new Function(\"event\", \"" + functionBody + "\");" +
+ "}";
+ writer.write(functionRegister);
writer.endElement("script");
}
}
More information about the seam-commits
mailing list