Wicket教程向您展示如何创建一个textarea,多行文本编辑组件,通常用于地址字段。
//Java
import org.apache.wicket.markup.html.form.TextArea;
...
final TextArea<String> address = new TextArea<String>("address",Model.of(""));
form.add(address);
//HTML
<textarea wicket:id="address" rows="6" cols="40"></textarea>
1. Wicket textarea示例
代码以呈现文本字段的地址。
文件:UserPage.java
package com.mkyong.user;
import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextArea;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.model.Model;
public class UserPage extends WebPage {
public UserPage(final PageParameters parameters) {
add(new FeedbackPanel("feedback"));
//create a textarea field for address
final TextArea<String> address = new TextArea<String>("address",Model.of(""));
address.setRequired(true);
address.setLabel(Model.of("Address"));
Form<?> form = new Form<Void>("userForm") {
@Override
protected void onSubmit() {
PageParameters pageParameters = new PageParameters();
pageParameters.add("address", address.getModelObject());
setResponsePage(SuccessPage.class, pageParameters);
}
};
add(form);
form.add(address);
}
}
2. Wicket HTML页面
呈现textarea字段的页面。
文件:UserPage.html
<html>
<head>
<style>
label {
background-color: #eee;
padding: 4px;
float:left;
}
.feedbackPanelERROR {
color: red;
}
</style>
</head>
<body>
<h1>Wicket TextArea Example</h1>
<div wicket:id="feedback"></div>
<form wicket:id="userForm">
<p>
<label>Address :</label>
<textarea wicket:id="address" rows="6" cols="40"></textarea>
</p>
<input type="submit" value="Register" />
</form>
</body>
</html>
3.演示
开始并访问-http:// localhost:8080 / WicketExamples /
![wicket-textarea-example wicket textarea address field](https://www.mkyong.com/wp-content/uploads/2011/05/wicket-textarea-example.png)
下载它– Wicket-textarea-example.zip (8KB)