Uploaded image for project: 'Wicket'
  1. Wicket
  2. WICKET-2019

Validation messages aren't cleared on success.

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.4-RC1
    • Fix Version/s: 1.4-RC2
    • Component/s: wicket
    • Labels:
      None

      Description

      When triggering validation messages on a form component, they aren't cleared anymore when afterward we fix our validation problem.

      The following code demonstrates this issue by making a form with a single text field that is set as required. First, we submit the form without filling in the field. We expect that to cause an error. Which it does. Then, we set a value in the field, and submit again. We expect that to pass validation. It does not, however.

      Instead, we get this exception:
      junit.framework.AssertionFailedError: expect no error message, but contains
      Field 'field' is required.
      at junit.framework.Assert.fail(Assert.java:47)
      at junit.framework.Assert.assertTrue(Assert.java:20)
      at org.apache.wicket.util.tester.WicketTester.assertNoErrorMessage(WicketTester.java:493)
      at test.spike.net.link.safeonline.TinyTests.wicketTest(TinyTests.java:93)

      Code:

      package test.spike;

      import org.apache.wicket.Page;
      import org.apache.wicket.markup.html.WebPage;
      import org.apache.wicket.markup.html.form.Form;
      import org.apache.wicket.markup.html.form.TextField;
      import org.apache.wicket.protocol.http.WebApplication;
      import org.apache.wicket.util.tester.FormTester;
      import org.apache.wicket.util.tester.WicketTester;
      import org.junit.Test;

      public class TinyTests {

      public static class MyApp extends WebApplication {

      @Override
      public Class<? extends Page> getHomePage()

      { return MyPage.class; }

      }

      public static class MyPage extends WebPage {

      public MyPage()

      { add(new MyForm("form")); }

      class MyForm extends Form<String> {

      private static final long serialVersionUID = 1L;

      public MyForm(String id)

      { super(id); TextField<String> f = new TextField<String>("field"); f.setRequired(true); add(f); }

      }
      }

      @Test
      public void wicketTest() {

      WicketTester wicket = new WicketTester(new MyApp());
      wicket.processRequestCycle();

      FormTester form = wicket.newFormTester("form");
      form.submit();

      wicket.assertErrorMessages(new String[]

      { "Field 'field' is required." }

      );

      form = wicket.newFormTester("form");
      form.setValue("field", "foo");
      form.submit();

      wicket.assertNoErrorMessage(); // <- Exception line.
      }
      }

      <html>
      <body>
      <form wicket:id="form">
      <input wicket:id="field" />
      <input type="submit" />
      </form>
      </body>
      </html>

        Attachments

          Activity

            People

            • Assignee:
              jdonnerstag Juegen Donnerstag
              Reporter:
              lhunath Maarten Billemont
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: