首先,我想说我看到了一个网站:
https://cwiki.apache.org/WICKET/autocomplete-using-a-wicket-model.html
自动完成在检票口采用了先进的模型
我仍然有一些问题与实现。
上下文
我有我想要编辑的窗体在我的数据库中订购。 我想在窗体中自动完成客户端名称并将其保存到数据库。
问题
我可以看到客户端名称的建议,我可以选择,我会使用哪个客户的名字。 只是当我提交表单新客户端将不会保存在数据库中的顺序。 我不知道如何将表单模型与AutoCompleteTextField输入相关联。
任何想法?
我的课的伪代码:
Order{
Long id;
String date;
Client client;
Status status;
...
}
Client{
Long id;
String name;
String nip;
String address;
String postcode;
String city;
String phone;
String mail;
...
}
Status{
Long id;
String name;
String value;
}
编辑:
是的,你是对的。
我从网站AbstractAutoCompleteTextField的实现:
form = new Form("orderForm", new CompoundPropertyModel(order)) {
@Override
public void onSubmit() {
orderService.update((Order) getDefaultModelObject());
setResponsePage(OrdersPage.class);
// Form validation successful. Display message showing edited
// model.
}
};
有了这个代码,我得到:
你问AbstractAutoCompleteRenderer autoCompleteRenderer = new AbstractAutoCompleteRenderer() {
protected final String getTextValue(final Object object) {
Client client = (Client) object;
return client.getName();
}
protected final void renderChoice(final Object object, final Response response, final String criteria) {
response.write(getTextValue(object));
}
};
// textfield
AbstractAutoCompleteTextField<Client> name = new AbstractAutoCompleteTextField<Client>("name", new PropertyModel(order, "client"), autoCompleteRenderer) {
protected final List<Client> getChoiceList(final String input) {
return clientService.findByNames(10, 0, input);
}
protected final String getChoiceValue(final Client choice) throws Throwable {
return choice.getId().toString();
}
};
form.add(name);
我的形式实施“ 'Hurtownia Techniczna “ADA”' 是不妥当的客户端“。 (从波兰语翻译)在反馈小组。
所以,如果我得到这个权利,您的自动完成功能正在工作,但表单中选择的值不会在表单提交时被存储?如果是这样的话,我们可能需要查看一些你如何处理表单提交的代码。 – Tim
in orderService.update()'你也更新客户端吗? – Nicktar
我想我应该。当我使用DropDownChoice编辑状态时就足够了。我在我的问题中添加了Status类。 – bandit