我创建了一个CustomListView,其中一部分是一个TextField,我想在其中设置实体问题的值:
customListView = new ListView<Issue>("fields", issuesModel) {
@Override
protected void populateItem(final ListItem<Issue> item) {
Issue issue = item.getModelObject();
item.add(new label("name", issue.getName()));
TextField<String> customTextField = new TextField("customTextField", new PropertyModel<String>(issue, "value"));
item.add(customTextField);}}
然后我有另一个类,在我添加这个 ListView 组件的地方有一个表单,每个问题都有几个 TextField,我可以在其中写入值:
IModel<List<Issue>> issuesModel = new CompoundPropertyModel<List<Issue>>(issueValues) {
@Override
public List<Issue> getObject() {
issueValues = new ArrayList<Issue>();
Issue issue;
for (BasicIssue basicIssue : basicIssuesList) {
issue = new Issue();
issue.setName(basicIssue.getname());
issueValues.add(issue);
}
return issueValues;
}
};
customListView = new CustomListView("customListView", issuesModel);
editBasicIssueForm = new Form("form") {
@Override
protected void onSubmit() {
basicIssue.setIssues(issueValues);
};
editIssuesForm.add(customListView);
当我为每个问题填写所有 TextFields 时,只有最后一个值设置为最后一个问题。之前的所有 Issue 值都是 NULL;我不知道问题是什么。
我的基本问题看起来像:
@Entity
public class BasicIssue implements Serializable {
private Long id;
@OneToMany(cascade = CascadeType.ALL)
private List<Issue> issueList;
}
我以前错过了一些东西,但是我使用 customListView 中的 issuesModel 来设置问题的值。在表单中,我需要将此问题列表设置为 BasicIssue。但是列表是空的。