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
Userinto aStringproperty (searchPerson.name). Either makeusersaList<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.nameand try to get the value of the propertyusernamefrom 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
DefaultCssAutocompleteTextFieldfrom 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.