简体   繁体   中英

Ajax in Wicket Panel doesn't work

I have some panels with one text field on my page. I'd like to add ajax behavior to all my text fields but it works only for the first text field - only when I change the first text field the ajax request is sending.

They must be panels because I'd like to improve these adding another components.

Hear is my code.

public class TestPage extends WebPage {

    private BigDecimal test1 = new BigDecimal("1");
    private BigDecimal test2 = new BigDecimal("2");
    private BigDecimal test3 = new BigDecimal("3");
    private BigDecimal test4 = new BigDecimal("4");

    public TestPage() {
        Form<?> form = new Form<Void>("form");
        add(form);

        form.add(new TestPanel("test1", test1));
        form.add(new TestPanel("test2", test2));
        form.add(new TestPanel("test3", test3));
        form.add(new TestPanel("test4", test4));
    }

    private class TestPanel extends Panel {
        private BigDecimal amount;

        private TestPanel(String id, BigDecimal amount) {
            super(id);
            this.amount = amount;

            TextField<BigDecimal> = new TextField<BigDecimal>("amount", new PropertyModel<BigDecimal>(this, "amount"));
            add(textField);
            textField.add(new TestBehavior());
            textField.setRequired(true);
        }
    }

    public class TestBehavior extends OnChangeAjaxBehavior {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            //this text is pirinting only when I change the first text field
            System.out.println("---------- TestBehavior.onUpdate() ----------------");
        }
    }
}

TestPage.html

<html xmlns:wicket="http://wicket.apache.org">
<body>
    <form wicket:id="form" class="form-horizontal">
        <span wicket:id="test1"></span>
        <span wicket:id="test2"></span>
        <span wicket:id="test3"></span>
        <span wicket:id="test4"></span>
    </form>
</body>
</html>

TestPage$TestPanel.html

<html xmlns:wicket="http://wicket.apache.org">
<body>
<wicket:panel xmlns:wicket="http://wicket.apache.org">
    <input wicket:id="amount" id="amount" type="text" class="input-small"/>
</wicket:panel>
</body>
</html>

Remove id="amount" from the <input> . Instead set on the TextField .setOutputMarkupId(true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM