0

ページに1つのテキストフィールドがあるパネルがいくつかあります。すべてのテキストフィールドにajax動作を追加したいのですが、これは最初のテキストフィールドでのみ機能します-ajaxリクエストが送信する最初のテキストフィールドを変更した場合のみです。

別のコンポーネントを追加してこれらを改善したいので、それらはパネルである必要があります。

聞くのは私のコードです。

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>
4

1 に答える 1

1

から削除id="amount"<input>ます。代わりにTextField .setOutputMarkupId(true);

于 2013-02-16T09:23:55.980 に答える