You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Juha Syrjälä (JIRA)" <ji...@apache.org> on 2010/10/19 09:08:29 UTC

[jira] Commented: (WICKET-3118) ConverterLocator should be class hierarchy aware

    [ https://issues.apache.org/jira/browse/WICKET-3118?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12922467#action_12922467 ] 

Juha Syrjälä commented on WICKET-3118:
--------------------------------------

Current ConverterLocator behaviour is problematic for example with proxies create by hibernate. If you set converter for some.package.MyClass, currently it does not apply to proxied instances such as some.package.MyClass$$EnhancerByCGLIB$$.

> ConverterLocator should be class hierarchy aware
> ------------------------------------------------
>
>                 Key: WICKET-3118
>                 URL: https://issues.apache.org/jira/browse/WICKET-3118
>             Project: Wicket
>          Issue Type: New Feature
>          Components: wicket
>    Affects Versions: 1.4.12
>            Reporter: Juha Syrjälä
>            Priority: Minor
>
> Currently ConverterLocator does return Converters only for those type they are explicitly registered. Specifically, when trying to convert a class that does not have registered converter but one of its superclasses has registered converter, the DefaultConverter is obtained. It would be nice if the super classe's converted is returned instead.
> I am proposing that ConverterLocator is changed to understand class hierarchies, or alternatively, a new ConverterLocator implementation is added that is class hierarchy aware.
> Something like this. Definitely not production ready, but should give the idea:
> public class ClassHierarchyAwareConverterLocator implements IConverterLocator {
> 	private static final long serialVersionUID = 1L;
> 	private ConverterLocator converterLocator;
> 	public ClassHierarchyAwareConverterLocator() {
> 		converterLocator = new ConverterLocator();
> 	}
> 	public IConverter getConverter(Class<?> type) {
> 		IConverter exactConverter = converterLocator.get(type);
> 		if(exactConverter != null) {
> 			return exactConverter;
> 		}
> 		
> 		Class<?> currentType = type;
> 		while(currentType.getSuperclass() != null) {
> 			currentType = currentType.getSuperclass();
> 			IConverter superClassConverter = converterLocator.get(currentType);
> 			if(superClassConverter != null) {
> 				return superClassConverter;
> 			}
> 		}
> 		return converterLocator.getConverter(type);
> 	}
> 	
> 	public final IConverter set(final Class<?> c, final IConverter converter) {
> 		converterLocator.set(c, converter);
> 		return converter;
> 	}
> 	public final IConverter remove(Class<?> c)
> 	{
> 		return converterLocator.remove(c);
> 	}	
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.