You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Maarten Billemont (JIRA)" <ji...@apache.org> on 2009/01/13 11:37:03 UTC

[jira] Created: (WICKET-2019) Validation messages aren't cleared on success.

Validation messages aren't cleared on success.
----------------------------------------------

                 Key: WICKET-2019
                 URL: https://issues.apache.org/jira/browse/WICKET-2019
             Project: Wicket
          Issue Type: Bug
          Components: wicket
    Affects Versions: 1.4-RC1
            Reporter: Maarten Billemont


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>

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (WICKET-2019) Validation messages aren't cleared on success.

Posted by "Juergen Donnerstag (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WICKET-2019?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Juergen Donnerstag resolved WICKET-2019.
----------------------------------------

       Resolution: Fixed
    Fix Version/s: 1.4-RC2
         Assignee: Juergen Donnerstag

WicketTester:

		// Set request cycle so it won't detach automatically and clear messages
		// we want to check
		cycle.setAutomaticallyClearFeedbackMessages(false);

To reset the messages you could use (and that is what had to do in the past)
getWicketSession().clearFeedbackMessages().

In life systems resetting the feedback messages does work. Did you test it? You didn't mention it in your report.

But it can be improved. There is no reason why form.submit() cannot clear the feedback message. Latest by than they should be reset. That is change I did and it should testers life a bit easier.


> Validation messages aren't cleared on success.
> ----------------------------------------------
>
>                 Key: WICKET-2019
>                 URL: https://issues.apache.org/jira/browse/WICKET-2019
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket
>    Affects Versions: 1.4-RC1
>            Reporter: Maarten Billemont
>            Assignee: Juergen Donnerstag
>             Fix For: 1.4-RC2
>
>
> 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>

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WICKET-2019) Validation messages aren't cleared on success.

Posted by "Juergen Donnerstag (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-2019?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12663483#action_12663483 ] 

Juergen Donnerstag commented on WICKET-2019:
--------------------------------------------

I used your code for a life system and it works with 1.4 trunk without any problems. The messages are reset. The problem only occured with WicketTester. There should be no need to use clearFeedbackMessages(). 

> Validation messages aren't cleared on success.
> ----------------------------------------------
>
>                 Key: WICKET-2019
>                 URL: https://issues.apache.org/jira/browse/WICKET-2019
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket
>    Affects Versions: 1.4-RC1
>            Reporter: Maarten Billemont
>            Assignee: Juergen Donnerstag
>             Fix For: 1.4-RC2
>
>
> 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>

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WICKET-2019) Validation messages aren't cleared on success.

Posted by "Maarten Billemont (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-2019?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12663470#action_12663470 ] 

Maarten Billemont commented on WICKET-2019:
-------------------------------------------

The reason I made this test case was because it was failing in our live system.

So yes, this issue also occurs in live systems (Wicket + JBoss AS).  Am I supposed to do a Session.get().clearFeedbackMessages() in onBeforeRender?

If so, that can probably be improved; the wicket user shouldn't have to implement this behaviour himself - that's something the Wicket framework should take care of, imho.

> Validation messages aren't cleared on success.
> ----------------------------------------------
>
>                 Key: WICKET-2019
>                 URL: https://issues.apache.org/jira/browse/WICKET-2019
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket
>    Affects Versions: 1.4-RC1
>            Reporter: Maarten Billemont
>            Assignee: Juergen Donnerstag
>             Fix For: 1.4-RC2
>
>
> 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>

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.