Search in sources :

Example 1 with IMarkupResourceStreamProvider

use of org.apache.wicket.markup.IMarkupResourceStreamProvider in project wicket by apache.

the class EnclosureTest method testAtrribute.

/**
 * https://issues.apache.org/jira/browse/WICKET-3842
 */
@Test
public void testAtrribute() {
    /**
     * Page for the test
     */
    class TestPage extends WebPage implements IMarkupResourceStreamProvider {

        private static final long serialVersionUID = 1L;

        public TestPage() {
            final Label l = new Label("msg", "$label$");
            add(l);
            add(new Link<Void>("b") {

                private static final long serialVersionUID = 1L;

                @Override
                public void onClick() {
                    l.setVisible(!l.isVisible());
                }
            });
        }

        @Override
        public IResourceStream getMarkupResourceStream(MarkupContainer container, Class<?> containerClass) {
            return new StringResourceStream("<html><body><div wicket:enclosure='msg'><span wicket:id='msg'></span></div><input type='button' value='Toggle' wicket:id='b'/></body></html>");
        }
    }
    tester.startPage(new TestPage());
    assertTrue(tester.getLastResponseAsString().contains("$label$"));
    // toggle visibility of enclosure to false
    tester.clickLink("b");
    assertFalse(tester.getLastResponseAsString().contains("$label$"));
    // toggle visibility of enclosure to back to true
    tester.clickLink("b");
    assertTrue(tester.getLastResponseAsString().contains("$label$"));
}
Also used : WebPage(org.apache.wicket.markup.html.WebPage) MarkupContainer(org.apache.wicket.MarkupContainer) Label(org.apache.wicket.markup.html.basic.Label) StringResourceStream(org.apache.wicket.util.resource.StringResourceStream) IMarkupResourceStreamProvider(org.apache.wicket.markup.IMarkupResourceStreamProvider) Test(org.junit.Test)

Example 2 with IMarkupResourceStreamProvider

use of org.apache.wicket.markup.IMarkupResourceStreamProvider in project wicket by apache.

the class FormTesterSubmitLinkTest method radioComponentValueEncoding.

@Test
public void radioComponentValueEncoding() {
    class TestPage extends WebPage implements IMarkupResourceStreamProvider {

        private static final long serialVersionUID = 1L;

        private String value;

        private boolean submitted;

        public TestPage() {
            Form<Void> form = new Form<Void>("form");
            add(form);
            RadioGroup<String> group = new RadioGroup<String>("group", new PropertyModel<String>(this, "value"));
            form.add(group);
            value = "a";
            group.add(new Radio<String>("a", Model.of("a")));
            group.add(new Radio<String>("b", Model.of("b")));
            form.add(new AjaxSubmitLink("submit") {

                @Override
                protected void onSubmit(AjaxRequestTarget target) {
                    submitted = true;
                }

                @Override
                protected void onError(AjaxRequestTarget target) {
                }
            });
        }

        @Override
        public IResourceStream getMarkupResourceStream(MarkupContainer container, Class<?> containerClass) {
            return new StringResourceStream("<html><body><form wicket:id='form'><div wicket:id='group'><input type='radio' wicket:id='a'/><input type='radio' wicket:id='b'/></div><input wicket:id='submit' type='submit'/></form></body></html>");
        }
    }
    TestPage page = new TestPage();
    WicketTester tester = new WicketTester();
    tester.startPage(page);
    // clicking an ajax submit link will force the form to be ajax-serialized, current values of
    // form components copied into request. this will check that the value of radio is correctly
    // serialized.
    tester.clickLink("form:submit");
    assertTrue(page.submitted);
    assertEquals("a", page.value);
}
Also used : WebPage(org.apache.wicket.markup.html.WebPage) MarkupContainer(org.apache.wicket.MarkupContainer) RadioGroup(org.apache.wicket.markup.html.form.RadioGroup) Form(org.apache.wicket.markup.html.form.Form) AjaxSubmitLink(org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink) IMarkupResourceStreamProvider(org.apache.wicket.markup.IMarkupResourceStreamProvider) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) StringResourceStream(org.apache.wicket.util.resource.StringResourceStream) Test(org.junit.Test)

Aggregations

MarkupContainer (org.apache.wicket.MarkupContainer)2 IMarkupResourceStreamProvider (org.apache.wicket.markup.IMarkupResourceStreamProvider)2 WebPage (org.apache.wicket.markup.html.WebPage)2 StringResourceStream (org.apache.wicket.util.resource.StringResourceStream)2 Test (org.junit.Test)2 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)1 AjaxSubmitLink (org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink)1 Label (org.apache.wicket.markup.html.basic.Label)1 Form (org.apache.wicket.markup.html.form.Form)1 RadioGroup (org.apache.wicket.markup.html.form.RadioGroup)1