Igor>but you can create a testcase, reproducing the bare bits of code in a
testcase just like you did in the email below. the advantage would be
that i would have something i can play with which makes it much easier
to find the problem.
I will work on a quick start tonight, when I'm not at work. But here's what I'd
like to do, possibly extending Metagen. I have a Report object which includes
an abstract Document object. Document has 3 concrete subclasses, Book,
Article, and Monograph. I have FormComponentPanels for each, which I'd like to
swap in and out. I've used Metagen to create ReportMeta, DocumentMeta,
BookMeta, etc. I'd like to extend Metagen so I can write code like
IModel<Book> bookModel =
MetaModel.of(report).get(ReportMeta.document).as(Book.class);
and
IModel<String> isbnModel =
MetaModel.of(report).get(ReportMeta.document).as(Book.class).get(BookMeta.isbn);
Since I don't want to modify the MetaModel class on my own, I've written a
SubClassModel class like so:
private static class SubClassModel<T> extends MetaModel<T> {
private static final long serialVersionUID =
3511732306311269529L;
public SubClassModel(MetaModel<? super T> superModel, Class<T>
clazz) {
super(superModel);
}
@Override
public T getObject() {
return (T) super.getObject();
}
@Override
public void detach() {
super.detach();
}
public static <T> MetaModel<T> as(MetaModel<? super T>
superModel, Class<T> clazz) {
return new SubClassModel<T>(superModel, clazz);
}
}
}
Unfortunately, when the validation system gets its hands on this, it throws a
NPE as it adds the property validators:
Caused by: java.lang.NullPointerException
at
net.ftlines.wicket.validation.bean.ReflectableProperty.init(ReflectableProperty.java:46)
at
net.ftlines.wicket.validation.bean.ReflectableProperty.<init>(ReflectableProperty.java:98)
at
net.ftlines.wicket.validation.bean.ModelPropertyResolver.resolve(ModelPropertyResolver.java:35)
at
net.ftlines.wicket.validation.bean.ValidationContext.resolveProperty(ValidationContext.java:80)
at
net.ftlines.wicket.validation.bean.ValidationForm$1.component(ValidationForm.java:170)
at
net.ftlines.wicket.validation.bean.ValidationForm$1.component(ValidationForm.java:163)
at org.apache.wicket.util.visit.Visits.visitChildren(Visits.java:143)
at org.apache.wicket.util.visit.Visits.visitChildren(Visits.java:161)
at org.apache.wicket.util.visit.Visits.visitChildren(Visits.java:122)
at
org.apache.wicket.MarkupContainer.visitChildren(MarkupContainer.java:908)
at
net.ftlines.wicket.validation.bean.ValidationForm.addPropertyValidators(ValidationForm.java:162)
at
net.ftlines.wicket.validation.bean.ValidationForm.onBeforeRender(ValidationForm.java:155)
at org.apache.wicket.Component.internalBeforeRender(Component.java:981)
at org.apache.wicket.Component.beforeRender(Component.java:1015)
at
org.apache.wicket.MarkupContainer.onBeforeRenderChildren(MarkupContainer.java:1785)
... 52 more
This happens when Model is that SubclassModel<Book>.
How would you use Metagen for this case? Is it worth extending it?
Respectfully,
Eric Jablow
This communication, along with any attachments, is covered by federal and state
law governing electronic communications and may contain company proprietary and
legally privileged information. If the reader of this message is not the
intended recipient, you are hereby notified that any dissemination,
distribution, use or copying of this message is strictly prohibited. If you
have received this in error, please reply immediately to the sender and delete
this message. Thank you.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]