also I see
that org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink#onSubmit() is
final but has no log.warn()
no matter which one we use they should be consistent

Martin Grigorov
Wicket Training and Consulting


On Tue, May 20, 2014 at 2:32 PM, Martin Grigorov <[email protected]>wrote:

>
>
> On Tue, May 20, 2014 at 2:19 PM, <[email protected]> wrote:
>
>> Repository: wicket
>> Updated Branches:
>>   refs/heads/master 273127d8c -> 2cda29611
>>
>>
>> WICKET-5594 AjaxButton #onSubmit() #onError() intricacies
>>
>> Make non-Ajax hooks final and prevent non-Ajax submit
>>
>> Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
>> Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/2cda2961
>> Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/2cda2961
>> Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/2cda2961
>>
>> Branch: refs/heads/master
>> Commit: 2cda29611dcd78db1e6e2563034577fd86bd80a8
>> Parents: 273127d
>> Author: svenmeier <[email protected]>
>> Authored: Tue May 20 13:19:03 2014 +0200
>> Committer: svenmeier <[email protected]>
>> Committed: Tue May 20 13:19:03 2014 +0200
>>
>> ----------------------------------------------------------------------
>>  .../ajax/markup/html/form/AjaxButton.java       | 36 ++++++++++++++++++++
>>  .../ajax/markup/html/form/AjaxButtonTest.java   |  2 ++
>>  2 files changed, 38 insertions(+)
>> ----------------------------------------------------------------------
>>
>>
>>
>> http://git-wip-us.apache.org/repos/asf/wicket/blob/2cda2961/wicket-core/src/main/java/org/apache/wicket/ajax/markup/html/form/AjaxButton.java
>> ----------------------------------------------------------------------
>> diff --git
>> a/wicket-core/src/main/java/org/apache/wicket/ajax/markup/html/form/AjaxButton.java
>> b/wicket-core/src/main/java/org/apache/wicket/ajax/markup/html/form/AjaxButton.java
>> index eae85a6..88153c8 100644
>> ---
>> a/wicket-core/src/main/java/org/apache/wicket/ajax/markup/html/form/AjaxButton.java
>> +++
>> b/wicket-core/src/main/java/org/apache/wicket/ajax/markup/html/form/AjaxButton.java
>> @@ -19,9 +19,12 @@ package org.apache.wicket.ajax.markup.html.form;
>>  import org.apache.wicket.ajax.AjaxRequestTarget;
>>  import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
>>  import org.apache.wicket.ajax.form.AjaxFormSubmitBehavior;
>> +import org.apache.wicket.markup.ComponentTag;
>>  import org.apache.wicket.markup.html.form.Button;
>>  import org.apache.wicket.markup.html.form.Form;
>>  import org.apache.wicket.model.IModel;
>> +import org.slf4j.Logger;
>> +import org.slf4j.LoggerFactory;
>>
>>  /**
>>   * A button that submits the form via ajax.
>> @@ -34,6 +37,8 @@ public abstract class AjaxButton extends Button
>>  {
>>         private static final long serialVersionUID = 1L;
>>
>> +       private static final Logger logger =
>> LoggerFactory.getLogger(AjaxButton.class);
>> +
>>         private final Form<?> form;
>>
>>         /**
>> @@ -160,6 +165,37 @@ public abstract class AjaxButton extends Button
>>                 }
>>         }
>>
>> +       @Override
>> +       protected void onComponentTag(ComponentTag tag)
>> +       {
>> +               // WICKET-5594 prevent non-Ajax submit
>> +               tag.put("type", "button");
>> +
>> +               super.onComponentTag(tag);
>> +       }
>> +
>> +       /**
>> +        * This method is never called.
>> +        *
>> +        * @see #onSubmit(AjaxRequestTarget, Form)
>> +        */
>> +       @Override
>> +       public final void onSubmit()
>> +       {
>> +               logger.warn("unexpected invocation of #onSubmit()");
>>
>
> this would be more useful with '+ this' to print the component details
> (id, path, etc.)
>  same for onError() below.
> Use SLF4J's {} to call Component#toString() only when WARN is enabled
>
>
>> +       }
>> +
>> +       /**
>> +        * This method is never called.
>> +        *
>> +        * @see #onError(AjaxRequestTarget, Form)
>> +        */
>> +       @Override
>> +       public final void onError()
>> +       {
>> +               logger.warn("unexpected invocation of #onError()");
>> +       }
>> +
>>         /**
>>          * Listener method invoked on form submit with no errors, before
>> {@link Form#onSubmit()}.
>>          *
>>
>>
>> http://git-wip-us.apache.org/repos/asf/wicket/blob/2cda2961/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/form/AjaxButtonTest.java
>> ----------------------------------------------------------------------
>> diff --git
>> a/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/form/AjaxButtonTest.java
>> b/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/form/AjaxButtonTest.java
>> index 09e8fa8..3a0f39f 100644
>> ---
>> a/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/form/AjaxButtonTest.java
>> +++
>> b/wicket-core/src/test/java/org/apache/wicket/ajax/markup/html/form/AjaxButtonTest.java
>> @@ -34,6 +34,8 @@ public class AjaxButtonTest extends WicketTestCase
>>                 tester.startPage(HomePage.class);
>>                 // assert rendered page class
>>                 tester.assertRenderedPage(HomePage.class);
>> +               // assert button type for AjaxButtons, WICKET-5594
>> +               assertEquals("button",
>> tester.getTagById("submit2").getAttribute("type"));
>>                 // assert rendered label component
>>                 tester.assertLabel("message",
>>                         "If you see this message wicket is properly
>> configured and running");
>>
>>
>

Reply via email to