Hi,
i'm trying to implement an AutoCompleteTextField that selects from a List of POJOs. In my example i want to select an
Artist from a Database. (see code at end of the mail)
I ran into two problems there...
1.) generic implementation
all classes are generic and of type "Artist", but AutoCompleteTextField's getModelObject() returns String althought it
should return Artist. (see comment in code below with "ClassCastException".
Maybe it is wanted that the autocompletetextfield only returns String as Object, but then the generic implementation has
bugs.
I really would like it to get a POJO back, so i wont have to retrieve it
manually by the selected string again.
2.) the default selection is not put through the given IAutoCompleteRenderer<T>.
When i load my form, the return value of my POJO's .toString() method is value
of the textfield. (which can be alot of text)
It should use the renderer for the deault selection too.
best regards,
Daniel
code:
==========================================================================
final IAutoCompleteRenderer<Artist> cr = new
AbstractAutoCompleteTextRenderer<Artist>() {
@Override
protected String getTextValue(Artist object) {
return object.getName().getName();
}
};
final AutoCompleteTextField<Artist> field =
new AutoCompleteTextField<Artist>("ac", new
Model<Artist>(new SingleArtistBean()), cr) {
@Override
protected Iterator<Artist>
getChoices(String input) {
final List<Artist> artists = new
ArrayList<Artist>();
// stripped in this mail...
getting artists in here from DAO
return artists.iterator();
}
};
field.add(new AjaxFormComponentUpdatingBehavior("onchange") {
@Override
protected void onUpdate(AjaxRequestTarget target) {
log.debug("selection model: " +
field.getModel());
// java.lang.ClassCastException:
// java.lang.String cannot be cast to
de.idealo.mdb.model.Artist
Artist a = field.getModelObject();
}
});
add(field);
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]