private ArrayList<MFRList> list;
private ArrayList<STUList> list1 = new ArrayList<STUList>();
public ResultPage(PageParameters params) throws APIException {
Form form = new Form("form");
PageableListView view = new PageableListView("view", list, 10) {
@Override
public void onConfigure() {
super.onConfigure();
setVisible(list.size() > 0);
}
@Override
protected void populateItem(ListItem item) {
final StuList stu= (StuList) item.getModelObject();
item.add(new CheckBox("check", item.getModel()));
item.add(new Label("name", stu.getName()));
item.add(new Label("num", stu.getNumber()));
item.add(new Label("age", stu.getAge()));
item.add(new Label("sex", stu.getSex()));
}
};
Button backtosearchbutton = new Button("backtosearchbutton") {
@Override
public void onSubmit() {
setResponsePage(SearchPage.class);
}
}.setDefaultFormProcessing(false);
Button groupcheckbutton = new Button("groupcheckbutton") {
@Override
public void onSubmit() {
}
}.setDefaultFormProcessing(false);
Button groupuncheckbutton = new Button("groupuncheckbutton") {
@Override
public void onSubmit() {
}
}.setDefaultFormProcessing(false);
Button submitselectionbutton = new Button("submitselectionbutton") {
@Override
public void onSubmit() {
}
}.setDefaultFormProcessing(true);
form.add(view);
form.add(backtosearchbutton);
form.add(submitselectionbutton);
form.add(groupuncheckbutton);
form.add(groupcheckbutton);
add(form);
add(new CustomPagingNavigator("navigator", view));
如何存储所选记录以及如何使用它。我明白,在提交表格时,这些记录已提交,但我不清楚如何以及在何处。
和我的pojo是
public class MFRList implements Serializable {
private String name;
private String num;
private String age;
private String sex;
private Boolean selected = Boolean.FALSE;
public String getName() {
return Name;
}
public void setName(String Name) {
this.Name = Name;
}
public String getnum() {
return num;
}
public void setnum(String num) {
this.num = num;
}
public String getAge() {
return age;
}
public void setsex(String sex) {
this.sex= sex;
}
public String getsex() {
return sex;
}
public void setage(String age) {
this.age = age;
}
public Boolean getSelected() {
return selected;
}
public void setSelected(Boolean selected) {
this.selected = selected;
}
}
保存所选行的位置以及如何检索和使用它。
先谢谢
答案 0 :(得分:1)
您应该使用带有支票的CheckGroup:
public ResultPage(PageParameters params)抛出APIException {
Form form = new Form("form");
CheckGroup selection = new CheckGroup("selection", new ArrayList());
selection.setRenderBodyOnly(false);
form.add(selection);
PageableListView view = new PageableListView("view", list, 10) {
@Override
public void onConfigure() {
super.onConfigure();
setVisible(list.size() > 0);
}
@Override
protected void populateItem(ListItem item) {
final StuList stu= (StuList) item.getModelObject();
item.add(new Check("check", item.getModel()));
item.add(new Label("name", stu.getName()));
item.add(new Label("num", stu.getNumber()));
item.add(new Label("age", stu.getAge()));
item.add(new Label("sex", stu.getSex()));
}
};
selection.add(view);
这样传递给CheckGroup构造函数的arrayList将始终包含所选对象。
答案 1 :(得分:0)
我得到了我想要实现的目标,但如果它是最佳解决方案,我就不会这样做。
我创建了自己的模型,并在选中复选框时将对象添加到列表中。 class SelectedCheckBoxModel扩展AbstractCheckBoxModel {
private final STUList info;
private ArrayList<STUList> list1;
public SelectedCheckBoxModel(STUList info, ArrayList<STUList> list1) {
super();
this.info = info;
this.list1 = list1;
}
@Override
public boolean isSelected() {
// TODO Auto-generated method stub
return list1.contains(info);
}
@Override
public void select() {
// TODO Auto-generated method stub
list1.add(info);
}
@Override
public void unselect() {
// TODO Auto-generated method stub
list1.remove(info);
}
我在我的listview中调用它
check = new CheckBox("check", new SelectedCheckBoxModel(stu, list1));
item.add(check);
如果这不是最佳,请建议
谢谢