如何使用带有表单的[Wicket] ListView?

时间:2013-07-11 10:51:12

标签: wicket

我在提交时添加了Form我必须添加更多wicket控件,如标签,文本字段和带有Ajex链接的按钮。但是无法获得正确的HTML。有人可以帮我摆脱它吗?

voucherPanel.html

<html xmlns:wicket>
<head>
</head>
<body>
  <wicket:panel>
    <div class="form-block">
      <div wicket:id="form">
        <wicket:message key="lbl.vouchercode" />
        <div wicket:id="list">
          <input wicket:id="word" type="text" />
        </div>
        <div wicket:id="vouchercode"></div>
      <button wicket:id="submit"><wicket:message key="submitText"/></button>   
      </div>
    </div>
  </wicket:panel>
</body>
</html>

voucherPanel.java

public class VoucherPanel extends Panel
{
  private static final long serialVersionUID = 1L;

  public VoucherPanel(final String id)
  {
    super(id);

    final TextField<String> voucherCodeField = new TextField<String>("vouchercode", Model.of(""));
    voucherCodeField.setRequired(true);

    final Button button = new Button("submit");

    Form<?> form = new Form<Void>("form")
    {

      @Override
      protected void onSubmit()
      {

              numberOfFields = new ArrayList<String>();

              int noOfVocuhers = getNoOfAllowedVoucher();// just returing the number
              for (int i = 0; i < noOfVocuhers; i++) {
                numberOfFields.add(new String(""));
            }

            add(new ListView<Object>("list", numberOfFields) {
                private static final long serialVersionUID = 1L;

                @Override
                protected void populateItem(ListItem<Object> item) {
                    final String word = (String) item.getModelObject();
                    System.out.println( "word   =" +word );
                    TextField<String> textField = new TextField<String>("word",  Model.of(""));
                    textField.setOutputMarkupId(true);
                    item.add(textField);
                }
            });

        }
      }
    };

    add(form);

    form.add(voucherCodeField);
    form.add(button);
  }
}

1 个答案:

答案 0 :(得分:1)

  1. 您尝试将Textfield分配给<div>元素(voucherCode),而您需要<input type="text">
  2. 您需要立即在表单中添加listonSubmit为时已晚。只需将其设置为外部,类似于button,并在提交表单时致电myListView.setList
  3. 这是我发现的两件事......如果您仍有问题,请告诉我们您收到的错误消息。