You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Sebastian Gabriel <Se...@hs-augsburg.de> on 2010/05/12 16:22:31 UTC

AutoCompleteTextField Problem Submitting

Hello,
I have an AutoCompleteTextField which works just fine. But when I select any of the given values from the list the validator tells me : "xxx is not a valid value..." perhaps you have any idea what I can do.

Code:

 private AutoCompleteTextField<Subject> subject = new AutoCompleteTextField<Subject>("subject",
            new Model<Subject>(event.getSubject()), autoCompleteRenderer) {
        
        /**
         * generated UID.
         */
        private static final long serialVersionUID = -928631288762101540L;
        
        @Override
        protected Iterator<Subject> getChoices(String term) {

            List<Subject> ret = new LinkedList<Subject>();
	    List<Subject> subjects = controller.getAllSubjects();
            for (Subject subject : subjects) {
                if (subject.getName().startsWith(term)) {
                    ret.add(subject);
                }
            }
            
            return ret.iterator();
        }
    };

Thanks,
Sebastian

Re: AutoCompleteTextField Problem Submitting

Posted by Zilvinas Vilutis <ci...@gmail.com>.
Wait, I lied a little :)

I use new Model<Type>( null ), so no value is being set to model object.

Actually I've ported the impl of AbstractAutoCompleteTextField as described
in https://cwiki.apache.org/WICKET/autocomplete-using-a-wicket-model.html so
and use the findChoice method for selected value resolution.

Žilvinas Vilutis

Mobile:   (+370) 652 38353
E-mail:   cikasfm@gmail.com


On Wed, May 12, 2010 at 11:32 AM, Sebastian Gabriel <
Sebastian.Gabriel@hs-augsburg.de> wrote:

> Thanks for your fast answer.
> I have a question about your solution. You say setting the model to null
> and adding a "getChoice" method would solve the problem. This means that I
> set the AutoCompleteTextField type to String and the String in the
> AutoCompleteTextField has to be unique in order to identify the right
> object, hasn't it?
>
> Thanks
> Sebastian
>
>
> Am 12.05.2010 um 19:26 schrieb Zilvinas Vilutis:
>
> > I had the same problem, its something related to converters or how your
> text
> > value is converted to ( in your case ) "Subject" - and as there is no
> > converter for that - it is just failing.
> >
> > What I've done is set the model to "null" and added a method "getChoice"
> > which does the conversion.
> >
> > This is not very convenient way but it works.
> >
> > Maybe Igor would have any suggestions how to solve this in a better way?
> >
> >
> > Žilvinas Vilutis
> >
> > Mobile:   (+370) 652 38353
> > E-mail:   cikasfm@gmail.com
> >
> >
> > On Wed, May 12, 2010 at 7:22 AM, Sebastian Gabriel <
> > Sebastian.Gabriel@hs-augsburg.de> wrote:
> >
> >> Hello,
> >> I have an AutoCompleteTextField which works just fine. But when I select
> >> any of the given values from the list the validator tells me : "xxx is
> not a
> >> valid value..." perhaps you have any idea what I can do.
> >>
> >> Code:
> >>
> >> private AutoCompleteTextField<Subject> subject = new
> >> AutoCompleteTextField<Subject>("subject",
> >>           new Model<Subject>(event.getSubject()), autoCompleteRenderer)
> {
> >>
> >>       /**
> >>        * generated UID.
> >>        */
> >>       private static final long serialVersionUID = -928631288762101540L;
> >>
> >>       @Override
> >>       protected Iterator<Subject> getChoices(String term) {
> >>
> >>           List<Subject> ret = new LinkedList<Subject>();
> >>           List<Subject> subjects = controller.getAllSubjects();
> >>           for (Subject subject : subjects) {
> >>               if (subject.getName().startsWith(term)) {
> >>                   ret.add(subject);
> >>               }
> >>           }
> >>
> >>           return ret.iterator();
> >>       }
> >>   };
> >>
> >> Thanks,
> >> Sebastian
>
>

Re: AutoCompleteTextField Problem Submitting

Posted by Sebastian Gabriel <Se...@hs-augsburg.de>.
Thanks for your fast answer. 
I have a question about your solution. You say setting the model to null and adding a "getChoice" method would solve the problem. This means that I set the AutoCompleteTextField type to String and the String in the AutoCompleteTextField has to be unique in order to identify the right object, hasn't it?

Thanks
Sebastian


Am 12.05.2010 um 19:26 schrieb Zilvinas Vilutis:

> I had the same problem, its something related to converters or how your text
> value is converted to ( in your case ) "Subject" - and as there is no
> converter for that - it is just failing.
> 
> What I've done is set the model to "null" and added a method "getChoice"
> which does the conversion.
> 
> This is not very convenient way but it works.
> 
> Maybe Igor would have any suggestions how to solve this in a better way?
> 
> 
> Žilvinas Vilutis
> 
> Mobile:   (+370) 652 38353
> E-mail:   cikasfm@gmail.com
> 
> 
> On Wed, May 12, 2010 at 7:22 AM, Sebastian Gabriel <
> Sebastian.Gabriel@hs-augsburg.de> wrote:
> 
>> Hello,
>> I have an AutoCompleteTextField which works just fine. But when I select
>> any of the given values from the list the validator tells me : "xxx is not a
>> valid value..." perhaps you have any idea what I can do.
>> 
>> Code:
>> 
>> private AutoCompleteTextField<Subject> subject = new
>> AutoCompleteTextField<Subject>("subject",
>>           new Model<Subject>(event.getSubject()), autoCompleteRenderer) {
>> 
>>       /**
>>        * generated UID.
>>        */
>>       private static final long serialVersionUID = -928631288762101540L;
>> 
>>       @Override
>>       protected Iterator<Subject> getChoices(String term) {
>> 
>>           List<Subject> ret = new LinkedList<Subject>();
>>           List<Subject> subjects = controller.getAllSubjects();
>>           for (Subject subject : subjects) {
>>               if (subject.getName().startsWith(term)) {
>>                   ret.add(subject);
>>               }
>>           }
>> 
>>           return ret.iterator();
>>       }
>>   };
>> 
>> Thanks,
>> Sebastian


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: AutoCompleteTextField Problem Submitting

Posted by Zilvinas Vilutis <ci...@gmail.com>.
I had the same problem, its something related to converters or how your text
value is converted to ( in your case ) "Subject" - and as there is no
converter for that - it is just failing.

What I've done is set the model to "null" and added a method "getChoice"
which does the conversion.

This is not very convenient way but it works.

Maybe Igor would have any suggestions how to solve this in a better way?


Žilvinas Vilutis

Mobile:   (+370) 652 38353
E-mail:   cikasfm@gmail.com


On Wed, May 12, 2010 at 7:22 AM, Sebastian Gabriel <
Sebastian.Gabriel@hs-augsburg.de> wrote:

> Hello,
> I have an AutoCompleteTextField which works just fine. But when I select
> any of the given values from the list the validator tells me : "xxx is not a
> valid value..." perhaps you have any idea what I can do.
>
> Code:
>
>  private AutoCompleteTextField<Subject> subject = new
> AutoCompleteTextField<Subject>("subject",
>            new Model<Subject>(event.getSubject()), autoCompleteRenderer) {
>
>        /**
>         * generated UID.
>         */
>        private static final long serialVersionUID = -928631288762101540L;
>
>        @Override
>        protected Iterator<Subject> getChoices(String term) {
>
>            List<Subject> ret = new LinkedList<Subject>();
>            List<Subject> subjects = controller.getAllSubjects();
>            for (Subject subject : subjects) {
>                if (subject.getName().startsWith(term)) {
>                    ret.add(subject);
>                }
>            }
>
>            return ret.iterator();
>        }
>    };
>
> Thanks,
> Sebastian