<input type="submit" wicket:id="submit" />
上記の処理(FormをSubmitする)をボタンではなく下記のようなリンクを使用して同様の事を実現したい場合
<a wicket:id="submit" >Submit</a>
この場合はorg.apache.wicket.markup.html.form.SubmitLinkを使用すると実現可能。
public class SubmitLinkPage extends WebPage {
private String input;
public SubmitLinkPage() {
Form form = new Form("form");
add(form);
form.add(new TextField("text",new PropertyModel(this, "input")));
form.add(new Label("label",new PropertyModel(this, "input")));
form.add(new SubmitLink("submitLink"));
}
}
<html xmlns:wicket>
<head></head>
<body>
<form wicket:id="form">
<span wicket:id="label"></span>
<input type="text" wicket:id="text"/>
<a wicket:id="submitLink">Submit Link</a>
</form>
</body>
</html>
また、下記のようにリンクがformタグの外側にある場合
<html xmlns:wicket>
<head></head>
<body>
<form wicket:id="form">
<span wicket:id="label"></span>
<input type="text" wicket:id="text"/>
</form>
<!-- fromの外側に移動 -->
<a wicket:id="submitLink">Submit Link</a>
</body>
</html>
Java側ではSubmitLinkのコンストラクタの第2引数にサブミットしたいFormオブジェクトを指定する。
public class SubmitLinkPage extends WebPage {
private String input;
public SubmitLinkPage() {
Form form = new Form("form");
add(form);
form.add(new TextField("text",new PropertyModel(this, "input")));
form.add(new Label("label",new PropertyModel(this, "input")));
//ここ重要!
add(new SubmitLink("submitLink",form));
}
}