use of org.apache.wicket.feedback.FeedbackCollector in project wicket by apache.
the class FormValidatorBehaviorTest method actAsValidator.
/**
* Tests validators are treated as validators
*/
@Test
public void actAsValidator() {
TestPage page = new TestPage();
tester.startPage(page);
FormTester ft = tester.newFormTester("form");
ft.setValue("name", "999999999");
ft.submit();
assertEquals(0, new FeedbackCollector(page).collect().size());
MaxLenValidator max = new MaxLenValidator(page.name);
page.form.add(max);
ft = tester.newFormTester("form");
ft.setValue("name", "999999999");
ft.submit();
assertEquals(1, new FeedbackCollector(page).collect().size());
assertEquals("MAX", new FeedbackCollector(page).collect().get(0).getMessage().toString());
ft = tester.newFormTester("form");
ft.setValue("name", "22");
ft.submit();
assertEquals(0, new FeedbackCollector(page).collect().size());
MinLenValidator min = new MinLenValidator(page.name);
page.form.add(min);
ft = tester.newFormTester("form");
ft.setValue("name", "22");
ft.submit();
assertEquals(1, new FeedbackCollector(page).collect().size());
assertEquals("MINIMUM", new FeedbackCollector(page).collect().get(0).getMessage().toString());
ft = tester.newFormTester("form");
ft.setValue("name", "7777777");
ft.submit();
assertEquals(0, new FeedbackCollector(page).collect().size());
page.form.remove(min);
ft = tester.newFormTester("form");
ft.setValue("name", "22");
ft.submit();
assertEquals(0, new FeedbackCollector(page).collect().size());
page.form.remove(max);
ft = tester.newFormTester("form");
ft.setValue("name", "999999999");
ft.submit();
assertEquals(0, new FeedbackCollector(page).collect().size());
}
use of org.apache.wicket.feedback.FeedbackCollector in project wicket by apache.
the class ValidatorBehaviorTest method actAsValidator.
/**
* Tests validators are treated as validators
*/
@Test
public void actAsValidator() {
TestPage page = new TestPage();
tester.startPage(page);
FormTester ft = tester.newFormTester("form");
ft.setValue("name", "999999999");
ft.submit();
assertEquals(0, new FeedbackCollector(page).collect().size());
MaxLenValidator max = new MaxLenValidator();
page.name.add(max);
ft = tester.newFormTester("form");
ft.setValue("name", "999999999");
ft.submit();
assertEquals(1, new FeedbackCollector(page).collect().size());
// WICKET-5115 variables in default message are not substituted (was the case in 1.5.x)
assertEquals("MAX ${len}", new FeedbackCollector(page).collect().get(0).getMessage().toString());
ft = tester.newFormTester("form");
ft.setValue("name", "22");
ft.submit();
assertEquals(0, new FeedbackCollector(page).collect().size());
MinLenValidator min = new MinLenValidator();
page.name.add(min);
ft = tester.newFormTester("form");
ft.setValue("name", "22");
ft.submit();
assertEquals(1, new FeedbackCollector(page).collect().size());
assertEquals("MINIMUM", new FeedbackCollector(page).collect().get(0).getMessage().toString());
ft = tester.newFormTester("form");
ft.setValue("name", "7777777");
ft.submit();
assertEquals(0, new FeedbackCollector(page).collect().size());
page.name.remove(min);
ft = tester.newFormTester("form");
ft.setValue("name", "22");
ft.submit();
assertEquals(0, new FeedbackCollector(page).collect().size());
page.name.remove(max);
ft = tester.newFormTester("form");
ft.setValue("name", "999999999");
ft.submit();
assertEquals(0, new FeedbackCollector(page).collect().size());
}
use of org.apache.wicket.feedback.FeedbackCollector in project wicket by apache.
the class WebPageRenderer method bindSessionIfNeeded.
/**
* Bind the session if there are feedback messages pending.
* https://issues.apache.org/jira/browse/WICKET-5165
*/
private void bindSessionIfNeeded() {
// check for session feedback messages only
FeedbackCollector collector = new FeedbackCollector();
List<FeedbackMessage> feedbackMessages = collector.collect();
if (feedbackMessages.size() > 0) {
Session.get().bind();
}
}
Aggregations