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

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


The following commit(s) were added to refs/heads/csp by this push:
     new 9ad2079  WICKET-6731: move inline onclick to event handler
9ad2079 is described below

commit 9ad20795847e146db5a536f90bc734f47386cc11
Author: Emond Papegaaij <[email protected]>
AuthorDate: Fri Jan 24 14:50:02 2020 +0100

    WICKET-6731: move inline onclick to event handler
---
 .../apache/wicket/markup/html/form/SubmitLink.java    | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git 
a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/SubmitLink.java 
b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/SubmitLink.java
index 30cbe8b..d8c9426 100644
--- 
a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/SubmitLink.java
+++ 
b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/SubmitLink.java
@@ -17,7 +17,10 @@
 package org.apache.wicket.markup.html.form;
 
 import org.apache.wicket.markup.ComponentTag;
+import org.apache.wicket.markup.head.IHeaderResponse;
+import org.apache.wicket.markup.head.OnDomReadyHeaderItem;
 import org.apache.wicket.model.IModel;
+import org.apache.wicket.util.string.AppendingStringBuffer;
 
 /**
  * A link which can be used exactly like a Button to submit a Form. The 
onclick of the link will use
@@ -165,21 +168,31 @@ public class SubmitLink extends AbstractSubmitLink
                        if (tag.getName().equalsIgnoreCase("a") || 
tag.getName().equalsIgnoreCase("link")
                                || tag.getName().equalsIgnoreCase("area"))
                        {
-                               tag.put("href", "javascript:;");
+                               tag.put("href", "#");
                        }
                        else if (tag.getName().equalsIgnoreCase("button"))
                        {
                                // WICKET-5597 prevent default submit
                                tag.put("type", "button");
                        }
-
-                       tag.put("onclick", getTriggerJavaScript());
                }
                else
                {
                        disableLink(tag);
                }
        }
+       
+       @Override
+       public void renderHead(IHeaderResponse response)
+       {
+               super.renderHead(response);
+
+               if (isEnabledInHierarchy())
+               {
+                       
response.render(OnDomReadyHeaderItem.forScript("Wicket.Event.add('" + 
getMarkupId()
+                               + "', 'click', function(event) { " + 
getTriggerJavaScript() + " });"));
+               }
+       }
 
        /**
         * Controls whether or not clicking on this link will invoke form's 
javascript onsubmit handler.

Reply via email to