NewForm.java
public class NewForm extends WebPage {
private Bean bean;
private DropDownClass dropdown;
private String selected = "choice";
void init()
{
bean = new Bean();
dropdown=new DropDownClass("test");
}
public NewForm(final PageParameters page) {
init();
final TextField<String> textname = new TextField<String>("name",Model.of(""));
textname.setRequired(true);
final DropDownChoice<String> dropname = new DropDownChoice<String>("type", new PropertyModel<String>(this, "selected"),
dropdown.getlist());
Form<?> form = new Form<Void>("Form") {
@Override
public void onSubmit() {
final String name = (String) textname.getModelObject();
final String dropdown = (String)dropname.getModelObject();
bean.add(name,dropdown);
final String schema = bean.getJsonSchema().toString();
page.add("schema", schema);
setResponsePage(new NewForm(page));
}
};
Label schemalabel = new Label("schema", page.get("schema"));
add(form);
form.add(textname);
form.add(dropname);
form.add(schemalabel);
}
}
Bean.java
public class Bean
{
private JSONObject jsonSchema;
public JSONObject getJsonSchema() {
return jsonSchema;
}
public void setJsonSchema(JSONObject jsonSchema) {
this.jsonSchema = jsonSchema;
}
public Bean() {
jsonSchema = new JSONObject();
}
public void add(String key,String value)
{
jsonSchema.put(key, value); // I am able to append values each time using "put" or "append" in JSF but not in WICKET.How can I append values in Wicket?
//or jsonSchema.append(key, value); //adding values only once and not appending each time,I enter the values in TextField and DropDown
}
}
在CreateForm.java中 - 我有一个 Textfield 和 DropDown 。当我在TextField和DropDown中输入值时..我能够在 AttributeInfo.java中从方法add(String key,String value)将TextField和DropDown中输入的值转换为 JSON schema 并将架构显示为 - {&#34; name&#34;:&#34; abc&#34;} //其中 name 是在TextField中输入的值, abc 来自DropDown。
我只能在onSubmit上显示一次架构但我需要每次将值附加到架构,我在TextField和DropDown onSubmit中输入并显示在同一页面中。
我怎样才能在Wicket中实现这一目标?
我只是一个初学者。任何帮助将不胜感激。提前谢谢你。