You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Alexandros Karypidis <ak...@yahoo.gr> on 2010/08/19 21:46:18 UTC

AutoCompleteTextField: converter seems to be ignored

  Hi,

I'm using AutoCompleteTextFiled with Wicket 1.4.9.  My model is a POJO 
that is specified as a generic:

         searchTextField = new AutoCompleteTextField<SomePOJO>(...

Therefore I return an Iterator of such POJOs with:

             protected Iterator<SomePOJO> getChoices(String input) {

I'm trying to customize the text displayed (which defaults to 
SomePOJO.toString()) using a converter:

             public IConverter getConverter(Class<?> type) {
                 System.err.println("Looking up converter for: " + 
type.getCanonicalName());
                 if (SomePOJO.class.isAssignableFrom(type)) {
                     return new IConverter() { ...

However, wicket never calls the getConverter() method and simply uses 
SomePOJO.toString() to retrieve the text for the choices. What am I 
doing wrong?



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


Re: AutoCompleteTextField: converter seems to be ignored

Posted by Alexandros Karypidis <ak...@yahoo.gr>.
>>> However, wicket never calls the getConverter() method and simply uses
>>> SomePOJO.toString() to retrieve the text for the choices. What am I
>>> doing wrong?
>> One possibility is that in all the nested classes in the typical 
>> Wicket source file you have added the method to the wrong class. Try 
>> adding @Override to indicate that you intend to override a superclass 
>> method, and see if the compiler or IDE complains
> Good idea but unfortunately that's not it. The method in the correct 
> place (within an anonymous class extending AutoCompleteTextField) and 
> already has an @Override.
>
> In fact, the converter does get called, but only after I've made a 
> selection. By then, the "type" argument is already a java.lang.String.

After looking at Wicket's source code, I've found that AutoTextField 
does not use converters. Instead, you need to declare a renderer as follows:

         IAutoCompleteRenderer<SomePOJO> myRenderer = new 
AbstractAutoCompleteTextRenderer<SomePOJO>() {
             @Override
             protected String getTextValue(SomePOJO object) {
                 return ....;
             }
         };


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


Re: AutoCompleteTextField: converter seems to be ignored

Posted by Alexandros Karypidis <ak...@yahoo.gr>.
  On 20/8/2010 09:23, Wilhelmsen Tor Iver wrote:
>> However, wicket never calls the getConverter() method and simply uses
>> SomePOJO.toString() to retrieve the text for the choices. What am I
>> doing wrong?
> One possibility is that in all the nested classes in the typical Wicket source file you have added the method to the wrong class. Try adding @Override to indicate that you intend to override a superclass method, and see if the compiler or IDE complains
Good idea but unfortunately that's not it. The method in the correct 
place (within an anonymous class extending AutoCompleteTextField) and 
already has an @Override.

In fact, the converter does get called, but only after I've made a 
selection. By then, the "type" argument is already a java.lang.String.


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


Re: AutoCompleteTextField: converter seems to be ignored

Posted by Wilhelmsen Tor Iver <To...@arrive.no>.
> However, wicket never calls the getConverter() method and simply uses
> SomePOJO.toString() to retrieve the text for the choices. What am I
> doing wrong?

One possibility is that in all the nested classes in the typical Wicket source file you have added the method to the wrong class. Try adding @Override to indicate that you intend to override a superclass method, and see if the compiler or IDE complains.

- Tor Iver

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