我有以下抽象类:
public abstract class Person extends Model {
private Serializable id;
private String name;
private Integer year;
private String nationality;
private String deathYear;
@Override
protected Serializable getId() {
return id;
}
@Override
protected Model byId() {
return null;
}
public String getName() {
return name;
}
public abstract void add();
public abstract void update();
public abstract void delete();
public abstract String getDeathYear();
public abstract int getYear();
public abstract String getNationality();
public abstract List<Book> getBooks();
}
以下类扩展了它:
public class Author extends Person {
private Serializable id;
private String name;
private Integer year;
private String nationality;
private String deathYear;
private List<Prize> prizes;
private List<Book> books;
public Author() {
}
@Override
public String getNationality() {
return nationality;
}
@Override
public String getName() {
return name;
}
@Override
public int getYear() {
return year;
}
@Override
public String getDeathYear() {
return deathYear;
}
@Override
public List<Book> getBooks() {
return books;
}
public List<Prize> getPrizes() {
return prizes;
}
public void setName(String name) {
this.name = name;
}//plus some unrelated stuff
我正在尝试创建一个这样的表单:
public class AdminAuthorPage extends AdminBasePage {
Author inputAuthor;
public AdminAuthorPage() {
this(new Author());
}
public AdminAuthorPage(Author author) {
this.inputAuthor = author;
this.add(new ListView<Author>("authorList", Author.all()) {
@Override
protected void populateItem(ListItem<Author> item) {
final Author author = item.getModelObject();
item.add(new PersonLink("authorLink", author));
item.add(new Link("editLink") {
@Override
public void onClick() {
setResponsePage(new AdminAuthorPage(author));
}
});
item.add(new Link("deleteLink") {
@Override
public void onClick() {
author.delete();
setResponsePage(new AdminAuthorPage());
}
});
}
});
Form authorForm = new Form("authorForm", new CompoundPropertyModel(
this.inputAuthor));
authorForm.add(new RequiredTextField<String>("name"));
//....
然而,当我浏览相应的页面时,我收到以下错误:
Last cause: null
WicketMessage:
Error attaching this container for rendering: [Form
[Component id = authorForm]]
据我所知,当CompoundPropertyModel的类型(在这种情况下是作者)时会发生此错误 找不到所需的吸气剂。
但是,似乎我的代码已经为name属性定义了getter方法。
答案 0 :(得分:2)
我认为你误解了模型的概念。你的人类不应该扩展模型,它应该是标准的pojo。你要声明模型对你的pojo是通用的。
MyPage extends GenericWebPage<Author> {
public MyPage(IModel<Author> model) {
super(model);
}
}