On Wed, May 21, 2008 at 4:20 AM, Daniel Peters <[EMAIL PROTECTED]> wrote:
> 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.

this is because you are free to enter any string, even if it doesnt
match any existing artist in the list.

-igor



>
> 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]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to