2013-02-16 40 views
0

我在页面上有一个带有一个文本字段的面板。我想为我的所有文本字段添加ajax行为,但它仅适用于第一个文本字段 - 仅当我更改ajax请求发送的第一个文本字段时。Wicket Panel中的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)我会发送到TestPanel的PropertyModel,而不是您发送的BigDecimal。 2)首先将'TestPanel'添加到表单中,然后添加表单3)将'TestPanel'放在单独的文件中以获得更清晰的代码。 – 2013-02-16 09:02:51

+0

从输入中删除'id =“amount”'。在TextField上执行'.setOutputMarkupId(true)' – 2013-02-16 09:10:41

+0

“从输入中删除id =”amount“ - 这解决了问题。谢谢! – 2013-02-16 09:22:39

回答

1

<input>删除id="amount"。而不是设置在TextField.setOutputMarkupId(true);