gpt4 book ai didi

java - 将 wicket CompoundPropertyModel 与抽象类一起使用

转载 作者:行者123 更新时间:2023-12-02 05:13:30 24 4
gpt4 key购买 nike

我有以下抽象类:

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(本例中为Author)的类型时会发生此错误找不到所需的 setter/getter 。

但是,我的代码似乎为 name 属性定义了 getter 方法。

最佳答案

我认为您误解了模型的概念。你的 person 类不应该扩展 model,它应该是标准的 pojo。您可以将模型声明为您的 pojo 的通用模型。

MyPage extends GenericWebPage<Author> {

public MyPage(IModel<Author> model) {
super(model);
}

}

关于java - 将 wicket CompoundPropertyModel 与抽象类一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27159521/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com