Converter for interface

2011-02-04 Thread Jan Ferko

Hi,

I wrote custom converter for entity class. convertToObject() works fine, 
but I have problem with convertToString(). Since i have different 
implementations for my entity (immutable and mutable version) I work 
with their common interface in my web layer and wicket seems not to 
recognize that it should convert entity with converter and always uses 
default converter. By the way converter is registered globally for whole 
application. Is there any way how to solve this or i have to set 
converter for each component which uses it? Thanks for help.


example:

interface IEntity {
getName();
}

class Entity implements IEntity{
getName(){};
}

interface IMutableEntity extends IEntity{
setName(String name);
}

class MutableEntity implements IMutableEntity {
getName(){};
setName(){};
}

my converter is registered for IEntity interface.

Jan


Re: Converter for interface

2011-02-04 Thread Pedro Santos
You can override the the application converter locator to return your
converter under the instanceof or Class#isAssignableFrom test.
I believe Wicket default converter locator don't do so since it can be
problematic in some cases. If the text field has the Integer type, you can't
use an the NumberConverter because it's contract probably would not specify
that it converts to Integer.

On Fri, Feb 4, 2011 at 11:54 AM, Jan Ferko julyl...@gmail.com wrote:

 Hi,

 I wrote custom converter for entity class. convertToObject() works fine,
 but I have problem with convertToString(). Since i have different
 implementations for my entity (immutable and mutable version) I work with
 their common interface in my web layer and wicket seems not to recognize
 that it should convert entity with converter and always uses default
 converter. By the way converter is registered globally for whole
 application. Is there any way how to solve this or i have to set converter
 for each component which uses it? Thanks for help.

 example:

 interface IEntity {
getName();
 }

 class Entity implements IEntity{
getName(){};
 }

 interface IMutableEntity extends IEntity{
setName(String name);
 }

 class MutableEntity implements IMutableEntity {
getName(){};
setName(){};
 }

 my converter is registered for IEntity interface.

 Jan




-- 
Pedro Henrique Oliveira dos Santos