You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by pa...@apache.org on 2020/02/03 21:09:21 UTC

[wicket] branch master updated: WICKET-6740: move inline js to event binding

This is an automated email from the ASF dual-hosted git repository.

papegaaij pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/wicket.git


The following commit(s) were added to refs/heads/master by this push:
     new 6bf04e5  WICKET-6740: move inline js to event binding
6bf04e5 is described below

commit 6bf04e58e52d2e9dd3165019fdf1c8223180fe96
Author: Emond Papegaaij <em...@topicus.nl>
AuthorDate: Mon Feb 3 22:04:21 2020 +0100

    WICKET-6740: move inline js to event binding
---
 .../org/apache/wicket/markup/html/form/Button.java     | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/Button.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/Button.java
index 0b4bcdf..cf358ef 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/Button.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/Button.java
@@ -18,6 +18,8 @@ package org.apache.wicket.markup.html.form;
 
 import org.apache.wicket.markup.ComponentTag;
 import org.apache.wicket.markup.MarkupStream;
+import org.apache.wicket.markup.head.IHeaderResponse;
+import org.apache.wicket.markup.head.OnEventHeaderItem;
 import org.apache.wicket.model.IModel;
 import org.apache.wicket.util.string.Strings;
 
@@ -165,7 +167,7 @@ public class Button extends FormComponent<String> implements IFormSubmittingComp
 	}
 
 	/**
-	 * Gets any script that should rendered as the &quot;onclick&quot; attribute of the button.
+	 * Gets any script that should rendered as a &quot;click&quot; event handler for the button.
 	 * Returns null by default, override this method to provide any script.
 	 * 
 	 * @return Any onClick JavaScript that should be used, returns null by default
@@ -177,8 +179,7 @@ public class Button extends FormComponent<String> implements IFormSubmittingComp
 
 	/**
 	 * Processes the component tag. A <tt>value</tt> attribute is added with the value of the model
-	 * object, if available. An <tt>onclick</tt> attribute is added if the subclass specified
-	 * javascript.
+	 * object, if available.
 	 * 
 	 * <p>
 	 * <b>NOTE</b>. For a <tt>&lt;button&gt;</tt> the <tt>value</tt> attribute is not rendered,
@@ -203,12 +204,21 @@ public class Button extends FormComponent<String> implements IFormSubmittingComp
 				tag.put("value", value);
 			}
 		}
+	}
+
+	/**
+	 * Adds a <tt>click</tt> event handler if the subclass specified javascript.
+	 */
+	@Override
+	public void renderHead(IHeaderResponse response)
+	{
+		super.renderHead(response);
 
 		// If the subclass specified javascript, use that
 		final String onClickJavaScript = getOnClickScript();
 		if (onClickJavaScript != null)
 		{
-			tag.put("onclick", onClickJavaScript);
+			response.render(OnEventHeaderItem.forComponent(this, "click", onClickJavaScript));
 		}
 	}