You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Gabriel Landon <gl...@piti.pf> on 2013/08/13 05:16:06 UTC
wicketstuff-lazymodel and wicket-bean-validation
Hi,
I've been using wicketstuff-lazymodel for weeks now and I love it!
Now I'm trying to use it with wicket-bean-validation, but I've got the
following error :
/Could not resolve Property from component: [TextField [Component id =
code]]. Either specify the Property in the constructor or use a model that
works in combination with a IPropertyResolver to resolve the Property
automatically/
So I have 2 solutions :
-Have LazyModel implements IPropertyReflectionAwareModel
Or
-Implement a new IPropertyResolver like the DefaultPropertyResolver
2nd solution seems easier. I should return a
org.apache.wicket.bean.validation.Property :
"public Property(Class<?> owner, String propertyName)"
I know how to get the class from LazyModel with "getObjectClass()", but how
can I get the field name?
Any help on this would be very nice.
Regards,
Gabriel.
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/wicketstuff-lazymodel-and-wicket-bean-validation-tp4660857.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: wicketstuff-lazymodel and wicket-bean-validation
Posted by Sven Meier <sv...@meiers.net>.
Hi Gariel,
that's just an expected debug output, when LazyModel cannot detect the
target type.
Note that the test doesn't fail.
Sven
On 08/16/2013 09:31 PM, Gabriel Landon wrote:
> Thank you very much Sven.
>
> I've grabbed the new source code, but there seems to have something wrong
> with the unit test (mvn test) :
>
> 369 [main] INFO org.apache.wicket.Application -
> [WicketTesterApplication-e6fcee33-24d3-4380-803d-4903860437c6] init: Wicket
> extensions initializer
> 371 [main] WARN RequestCycleExtra - ********************************
> 371 [main] WARN RequestCycleExtra - Handling the following exception
> org.apache.wicket.WicketRuntimeException: cannot detect target type
> at org.wicketstuff.lazymodel.LazyModel.getPath(LazyModel.java:363)
> at org.wicketstuff.lazymodel.LazyModel.toString(LazyModel.java:342)
> at java.lang.String.valueOf(String.java:2854)
> at java.lang.StringBuilder.append(StringBuilder.java:128)
> at
> org.apache.wicket.markup.html.form.AbstractTextComponent.getModelType(AbstractTextComponent.java:170)
> at
> org.apache.wicket.markup.html.form.AbstractTextComponent.resolveType(AbstractTextComponent.java:152)
> at
> org.apache.wicket.markup.html.form.AbstractTextComponent.onBeforeRender(AbstractTextComponent.java:142)
> at
> org.apache.wicket.Component.internalBeforeRender(Component.java:922)
> at org.apache.wicket.Component.beforeRender(Component.java:990)
> at
> org.apache.wicket.MarkupContainer.onBeforeRenderChildren(MarkupContainer.java:1681)
> at org.apache.wicket.Component.onBeforeRender(Component.java:3843)
> at
> org.apache.wicket.markup.html.form.Form.onBeforeRender(Form.java:1743)
> at
> org.apache.wicket.Component.internalBeforeRender(Component.java:922)
> at org.apache.wicket.Component.beforeRender(Component.java:990)
> at
> org.apache.wicket.MarkupContainer.onBeforeRenderChildren(MarkupContainer.java:1681)
> at org.apache.wicket.Component.onBeforeRender(Component.java:3843)
> at org.apache.wicket.Page.onBeforeRender(Page.java:798)
> at
> org.apache.wicket.Component.internalBeforeRender(Component.java:922)
> at org.apache.wicket.Component.beforeRender(Component.java:990)
> at
> org.apache.wicket.Component.internalPrepareForRender(Component.java:2213)
> at org.apache.wicket.Page.internalPrepareForRender(Page.java:241)
> at org.apache.wicket.Component.render(Component.java:2302)
> at org.apache.wicket.Page.renderPage(Page.java:1010)
> at
> org.apache.wicket.request.handler.render.WebPageRenderer.renderPage(WebPageRenderer.java:116)
> at
> org.apache.wicket.request.handler.render.WebPageRenderer.respond(WebPageRenderer.java:249)
> at
> org.apache.wicket.core.request.handler.RenderPageRequestHandler.respond(RenderPageRequestHandler.java:165)
> at
> org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:861)
> at
> org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64)
> at
> org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:261)
> at
> org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:218)
> at
> org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:289)
> at
> org.apache.wicket.util.tester.BaseWicketTester.processRequest(BaseWicketTester.java:654)
> at
> org.apache.wicket.util.tester.BaseWicketTester.processRequest(BaseWicketTester.java:593)
> at
> org.apache.wicket.util.tester.BaseWicketTester.startPage(BaseWicketTester.java:818)
> at
> org.apache.wicket.util.tester.BaseWicketTester.startPage(BaseWicketTester.java:835)
> at
> org.wicketstuff.lazymodel.FormComponentTest.nullTargetInTypeErasedModel(FormComponentTest.java:118)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:601)
> at
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
> at
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
> at
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
> at
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
> at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
> at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
> at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
> at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
> at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
> at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
> at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
> at
> org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
> at
> org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
> at
> org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:601)
> at
> org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
> at
> org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
> at
> org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
> at
> org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
> at
> org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)
> 377 [main] WARN RequestCycleExtra - ********************************
> Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.536 sec
> Running org.wicketstuff.lazymodel.LazyColumnTest
>
> Regards,
>
> Gabriel.
>
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/wicketstuff-lazymodel-and-wicket-bean-validation-tp4660857p4660935.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: wicketstuff-lazymodel and wicket-bean-validation
Posted by Gabriel Landon <gl...@piti.pf>.
Thank you very much Sven.
I've grabbed the new source code, but there seems to have something wrong
with the unit test (mvn test) :
369 [main] INFO org.apache.wicket.Application -
[WicketTesterApplication-e6fcee33-24d3-4380-803d-4903860437c6] init: Wicket
extensions initializer
371 [main] WARN RequestCycleExtra - ********************************
371 [main] WARN RequestCycleExtra - Handling the following exception
org.apache.wicket.WicketRuntimeException: cannot detect target type
at org.wicketstuff.lazymodel.LazyModel.getPath(LazyModel.java:363)
at org.wicketstuff.lazymodel.LazyModel.toString(LazyModel.java:342)
at java.lang.String.valueOf(String.java:2854)
at java.lang.StringBuilder.append(StringBuilder.java:128)
at
org.apache.wicket.markup.html.form.AbstractTextComponent.getModelType(AbstractTextComponent.java:170)
at
org.apache.wicket.markup.html.form.AbstractTextComponent.resolveType(AbstractTextComponent.java:152)
at
org.apache.wicket.markup.html.form.AbstractTextComponent.onBeforeRender(AbstractTextComponent.java:142)
at
org.apache.wicket.Component.internalBeforeRender(Component.java:922)
at org.apache.wicket.Component.beforeRender(Component.java:990)
at
org.apache.wicket.MarkupContainer.onBeforeRenderChildren(MarkupContainer.java:1681)
at org.apache.wicket.Component.onBeforeRender(Component.java:3843)
at
org.apache.wicket.markup.html.form.Form.onBeforeRender(Form.java:1743)
at
org.apache.wicket.Component.internalBeforeRender(Component.java:922)
at org.apache.wicket.Component.beforeRender(Component.java:990)
at
org.apache.wicket.MarkupContainer.onBeforeRenderChildren(MarkupContainer.java:1681)
at org.apache.wicket.Component.onBeforeRender(Component.java:3843)
at org.apache.wicket.Page.onBeforeRender(Page.java:798)
at
org.apache.wicket.Component.internalBeforeRender(Component.java:922)
at org.apache.wicket.Component.beforeRender(Component.java:990)
at
org.apache.wicket.Component.internalPrepareForRender(Component.java:2213)
at org.apache.wicket.Page.internalPrepareForRender(Page.java:241)
at org.apache.wicket.Component.render(Component.java:2302)
at org.apache.wicket.Page.renderPage(Page.java:1010)
at
org.apache.wicket.request.handler.render.WebPageRenderer.renderPage(WebPageRenderer.java:116)
at
org.apache.wicket.request.handler.render.WebPageRenderer.respond(WebPageRenderer.java:249)
at
org.apache.wicket.core.request.handler.RenderPageRequestHandler.respond(RenderPageRequestHandler.java:165)
at
org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:861)
at
org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64)
at
org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:261)
at
org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:218)
at
org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:289)
at
org.apache.wicket.util.tester.BaseWicketTester.processRequest(BaseWicketTester.java:654)
at
org.apache.wicket.util.tester.BaseWicketTester.processRequest(BaseWicketTester.java:593)
at
org.apache.wicket.util.tester.BaseWicketTester.startPage(BaseWicketTester.java:818)
at
org.apache.wicket.util.tester.BaseWicketTester.startPage(BaseWicketTester.java:835)
at
org.wicketstuff.lazymodel.FormComponentTest.nullTargetInTypeErasedModel(FormComponentTest.java:118)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at
org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
at
org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
at
org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at
org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
at
org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
at
org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
at
org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
at
org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)
377 [main] WARN RequestCycleExtra - ********************************
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.536 sec
Running org.wicketstuff.lazymodel.LazyColumnTest
Regards,
Gabriel.
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/wicketstuff-lazymodel-and-wicket-bean-validation-tp4660857p4660935.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: wicketstuff-lazymodel and wicket-bean-validation
Posted by Sven Meier <sv...@meiers.net>.
Hi Gabriel,
LazyModel implements IPropertyReflectionAwareModel now, so integration
with beanvalidation should work out-of-the-box with the next release.
Best regards
Sven
On 08/13/2013 09:40 PM, Gabriel Landon wrote:
> 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: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: wicketstuff-lazymodel and wicket-bean-validation
Posted by Gabriel Landon <gl...@piti.pf>.
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: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: wicketstuff-lazymodel and wicket-bean-validation
Posted by Gabriel Landon <gl...@piti.pf>.
Thank you very Sven.
Here's what I've done for the 2nd solution (base on DefaultPropertyResolver)
:
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;
// 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(lazyModel.getObjectClass(), fieldName);
}
}
For the 1st solution I cannot overrides/extends LazyModel as its construtor
is private.
Also I'm not a reflection guru, so I'm a bit lost on how to get the getter
and setter from the LazyModel.
I need to provide those 3 methods :
-public Field getPropertyField();
-public Method getPropertyGetter();
-public Method getPropertySetter();
I've seen methods like "methodResolver.getSetter" and
"methodResolver.getMethod" in the StackIterator but have not found how to
use them...
Any help on this would be nice also :-).
Gabriel.
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/wicketstuff-lazymodel-and-wicket-bean-validation-tp4660857p4660871.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: wicketstuff-lazymodel and wicket-bean-validation
Posted by Sven Meier <sv...@meiers.net>.
Hi,
you can call #getPath() on LazyModel and drop everything before the last
dot:
"foo.bar.baz" -> "baz"
Since IPropertyReflectionAwareModel is in wicket-core (I wasn't aware of
that), your first solution should be possible too.
Regards
Sven
On 08/13/2013 05:16 AM, Gabriel Landon wrote:
> Hi,
>
> I've been using wicketstuff-lazymodel for weeks now and I love it!
>
> Now I'm trying to use it with wicket-bean-validation, but I've got the
> following error :
> /Could not resolve Property from component: [TextField [Component id =
> code]]. Either specify the Property in the constructor or use a model that
> works in combination with a IPropertyResolver to resolve the Property
> automatically/
>
> So I have 2 solutions :
> -Have LazyModel implements IPropertyReflectionAwareModel
> Or
> -Implement a new IPropertyResolver like the DefaultPropertyResolver
>
> 2nd solution seems easier. I should return a
> org.apache.wicket.bean.validation.Property :
> "public Property(Class<?> owner, String propertyName)"
>
> I know how to get the class from LazyModel with "getObjectClass()", but how
> can I get the field name?
>
> Any help on this would be very nice.
> Regards,
>
> Gabriel.
>
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/wicketstuff-lazymodel-and-wicket-bean-validation-tp4660857.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org