The previous code was flawed. Here's the right one!
It's far from perfect but as I'm using only IObjectClassAwareModel models
it's working!

public class LazyModelPropertyResolver implements IPropertyResolver {

        @Override
        public Property resolveProperty(final FormComponent<?> component) {
                IModel<?> model = component.getModel();

                while (true) {
                        if (model == null) {
                                return null;
                        }
                        if (model instanceof LazyModel<?>) {
                                break;
                        }
                        if (model instanceof IWrapModel<?>) {
                                model = ((IWrapModel<?>) 
model).getWrappedModel();
                                continue;
                        }
                        return null;
                }

                final LazyModel<?> lazyModel = (LazyModel<?>) model;

                //I'm using only IObjectClassAwareModel
                if (lazyModel.getTarget() instanceof IObjectClassAwareModel) {

                        // le nom de la propritĂ© (qui peut ĂȘtre dans une chaine 
du genre
"foo.bar.baz").
                        String fieldName = lazyModel.getPath();
                        if (fieldName.contains(".")) {
                                fieldName = 
StringUtils.substringAfterLast(fieldName, "."); // on prend
le dernier champ
                        }

                        return new Property(((IObjectClassAwareModel<?>)
lazyModel.getTarget()).getObjectClass(), fieldName);
                }

                return null;
        }
}




--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/wicketstuff-lazymodel-and-wicket-bean-validation-tp4660857p4660872.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to