我的页面上有一些带有一个文本字段的面板。我想在我的所有文本字段中添加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>
答案 0 :(得分:1)
从id="amount"
移除<input>
。而是设置在TextField
.setOutputMarkupId(true);