开发者

wicket DropDownChoice No get method defined for class

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" )));


You're trying to inject an User into a String property (searchPerson.name). Either make users a List<Strings>, or make the DropDownChoice have a IModel<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 property username from it, which obviously doesn't exist, since it's a String, not an User.

[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 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.

topicDropDown = new DropDownChoice<Topic>("topicOptions", new PropertyModel<Topic>       (this.top, "topicOptions"), new LoadableDetachableModel<List<Topic>>() {
        @Override
        protected List<Topic> load() {
            return top.getAllTopics();

        }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜