wicket DropDownChoice 没有为类定义 get 方法
我正在使用 DropDownChoice,它的键和值是 User 对象的 username 属性。但是当我提交时,出现以下错误 No get method Defined for class: class java.lang.String expression: username。
提交表单时,我希望将表单输入设置到 SearchPerson 对象的 name 属性上,我使用用户(用户列表)加载下拉列表。我的选择框的显示和值都是用户名
<select name="select" wicket:id="name" id="select">
<option value="test">test</option>
</select>
form.add(new DropDownChoice("name",new PropertyModel(searchPerson, "name"),users,new ChoiceRenderer( "username", "username" )));
I am using a DropDownChoice, its key and value are username property of User object. But when I submit I get the following error No get method defined for class: class java.lang.String expression: username.
When the form is submitted, I want the form input to be set onto name property of the SearchPerson object, I am loading the dropdown using the users(list of user). My select box's display and value are both username
<select name="select" wicket:id="name" id="select">
<option value="test">test</option>
</select>
form.add(new DropDownChoice("name",new PropertyModel(searchPerson, "name"),users,new ChoiceRenderer( "username", "username" )));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在尝试将
User
注入String
属性 (searchPerson.name
)。将users
设置为List
,或者将 DropDownChoice 设置为IModel
。[编辑]
并且,该错误可能发生是因为组件正在尝试获取当前模型值的关键属性。因此,它需要
searchPerson.name
并尝试从中获取属性username
的值,该属性显然不存在,因为它是一个String,而不是
用户
。[更新]
如果您想要自动完成文本字段,您可以尝试 wicket-extensions 中的
DefaultCssAutocompleteTextField
。您可以直接在数据库(我想是 Hibernate)中查询用户名而不是用户,而不是迭代内存中的用户列表。You're trying to inject an
User
into aString
property (searchPerson.name
). Either makeusers
aList<Strings>
, or make the DropDownChoice have aIModel<User>
.[edited]
And, that error probably is happening because the component is trying to get the current model value's key property. So, it takes
searchPerson.name
and try to get the value of the propertyusername
from it, which obviously doesn't exist, since it's aString
, not anUser
.[updated]
If what you want is auto-complete of a text field, you could try
DefaultCssAutocompleteTextField
from wicket-extensions. And you could query the database (Hibernate, I suppose) for usernames directly instead of Users, instead of iterating the users list in memory.PropertyModel 是解决此类问题的不错选择。 Topic是一个对象,有一个字符串名称。我已经重写了Topic中的toString()方法来命名并且它工作正常。我建议使用这个方法。
PropertyModel is good choice for such problems. Topic is an object and has a string name.I have override the toString() method in Topic to name and it is working properly.I suggest using this method.