You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Rafael Winterhalter (JIRA)" <ji...@apache.org> on 2012/09/19 16:06:07 UTC
[jira] [Updated] (WICKET-4767) PropertyModel fails to identifiy
generic properties
[ https://issues.apache.org/jira/browse/WICKET-4767?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Rafael Winterhalter updated WICKET-4767:
----------------------------------------
Summary: PropertyModel fails to identifiy generic properties (was: PropertyModel fails to find generic properties)
> PropertyModel fails to identifiy generic properties
> ---------------------------------------------------
>
> Key: WICKET-4767
> URL: https://issues.apache.org/jira/browse/WICKET-4767
> Project: Wicket
> Issue Type: Bug
> Components: wicket
> Affects Versions: 1.5.8
> Reporter: Rafael Winterhalter
> Labels: Generics, PropertyModel
>
> If I use e.g. PropertyModel<String>(new Bean<String>(), "value") on a generic bean Bean<T> { T value; } this will not work in Wicket by its property resolver. If I replace the generic type by its actual type, Wicket's property resolver works just fine for me.
> However, in my opinion Wicket should try to resolve this issue by using the property object's actual type instead of just giving up since the PropertyModel already compromizes type safety.
> PS: Fixed it, this works totally fine for me: (Using the Apache Commons PropertyUtils, why does Wicket use its own implementation anyways?)
> import java.lang.reflect.InvocationTargetException;
> import org.apache.commons.beanutils.PropertyUtils;
> import org.apache.wicket.model.IModel;
> @SuppressWarnings("serial")
> public class GenericCompatiblePropertyModel<T> implements IModel<T> {
>
> private String propertyExpression;
> private Object target;
>
> public GenericCompatiblePropertyModel(Object target, String propertyExpression) {
> this.propertyExpression = propertyExpression;
> this.target = target;
>
> if(target == null)
> throw new IllegalArgumentException("[target] must not be null");
>
> }
>
> @SuppressWarnings("unchecked")
> @Override
> public T getObject() {
> try {
> return (T) PropertyUtils.getProperty(target, propertyExpression);
> } catch (IllegalAccessException e) {
> throw new RuntimeException("Property '" + propertyExpression +
> "' access is illegal for " + target.getClass().getSimpleName(), e);
> } catch (InvocationTargetException e) {
> throw new RuntimeException("Property '" + propertyExpression +
> "' cannot be resolved for " + target.getClass().getSimpleName(), e);
> } catch (NoSuchMethodException e) {
> throw new RuntimeException("Property '" + propertyExpression +
> "' cannot be found for " + target.getClass().getSimpleName(), e);
> }
> }
> @Override
> public void setObject(T object) {
> try {
> PropertyUtils.setProperty(target, propertyExpression, object);
> } catch (IllegalAccessException e) {
> throw new RuntimeException("Property '" + propertyExpression +
> "' access is illegal for " + target.getClass().getSimpleName(), e);
> } catch (InvocationTargetException e) {
> throw new RuntimeException("Property '" + propertyExpression +
> "' cannot be resolved for " + target.getClass().getSimpleName(), e);
> } catch (NoSuchMethodException e) {
> throw new RuntimeException("Property '" + propertyExpression +
> "' cannot be found for " + target.getClass().getSimpleName(), e);
> }
> }
> @Override
> public void detach() {
> /* empty */
> }
> }
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira