wicketstuff-lazymodel and inheritance

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

wicketstuff-lazymodel and inheritance

Gabriel Landon
Hi Sven,

Wicketstuff-lazymodel does not work with inheritance.

For example I've got the following classes:
@MappedSuperclass
public abstract class AbstractParam implements Serializable {
         /** serialVersionUID. */
        private static final long serialVersionUID = 1L;

        /** Code. */
        private String code;

        /**
         * @return the code
         */
        @NotNull
        @NaturalId
        @Size(min = 1, max = 64)
        public String getCode() {
                return code;
        }

        /**
         * @param varCode the code to set
         */
        public void setCode(final String varCode) {
                code = varCode;
        }
}

@Entity
public class Agence extends AbstractParam {
        /** serialVersionUID. */
        private static final long serialVersionUID = 1L;
}


When I use it in a lazyModel "model(from(Agence.class).getCode())", I've got the following error :

Caused by: java.lang.IllegalArgumentException: unknown method pf.satnui.gamax.bean.param.Agence#code
        at org.wicketstuff.lazymodel.reflect.DefaultMethodResolver.getMethod(DefaultMethodResolver.java:46) ~[wicketstuff-lazymodel-6.10.0.jar:6.10.0]
        at org.wicketstuff.lazymodel.reflect.CachingMethodResolver.getMethod(CachingMethodResolver.java:49) ~[wicketstuff-lazymodel-6.10.0.jar:6.10.0]
        at org.wicketstuff.lazymodel.LazyModel$StackIterator.next(LazyModel.java:481) ~[wicketstuff-lazymodel-6.10.0.jar:6.10.0]
        at org.wicketstuff.lazymodel.LazyModel.getObjectType(LazyModel.java:147) ~[wicketstuff-lazymodel-6.10.0.jar:6.10.0]
        at org.wicketstuff.lazymodel.LazyModel.getObjectClass(LazyModel.java:126) ~[wicketstuff-lazymodel-6.10.0.jar:6.10.0]


In the getMethod function to parse the methods you use "getDeclaredMethods" which excludes inherited methods :
        /**
         * Inverse operation of {@link #getId(Method)}.
         */
        @Override
        public Method getMethod(Class<?> owner, Serializable id) {
                for (Method method : owner.getDeclaredMethods()) {
                        if (id.equals(getId(method))) {
                                try {
                                        method.setAccessible(true);
                                } catch (SecurityException accessNotAllowed) {
                                }
                                return method;
                        }
                }
                throw new IllegalArgumentException(String.format(
                                "unknown method %s#%s", owner.getName(), id));
        }

Was there a special reason for not using "getMethods()" instead?

Regards,

Gabriel.

Reply | Threaded
Open this post in threaded view
|

Re: wicketstuff-lazymodel and inheritance

Gabriel Landon
This has been solved in next release:
https://github.com/wicketstuff/core/issues/257

Thank you Sven.