带有自定义日期表的 Wicket AjaxCheckBox
Wicket AjaxCheckBox with Custom DateTables
我正在使用 wicket 1.4 版本并正在使用数据tables 和 ajax 复选框:
我可以在 html 上呈现复选框。当我点击复选框时,ajax onUpdate 方法也被调用,但它没有给我所选复选框的正确值,即 this.getModelValue() 总是选择[的行的第一个值=25=].
我在这里缺少什么?
add(getMyDynamicTable("myTable", provider, 10));
protected CustomDataTable<MyClass> getMyDynamicTable(String tableId, Provider provider, int numRows) {
final List<IColumn<MyClass>> myCloumns = new ArrayList<>();
myCloumns.add(new AbstractColumn<MyClass>(new ResourceModel(
"isSelected")) {
@Override
public void populateItem(Item<ICellPopulator<MyClass>> item,
String componentId, IModel<MyClass> rowModel) {
final MyClass myclass = rowModel.getObject();
CheckBoxPanel checkBoxPanel = new CheckBoxPanel(componentId, new PropertyModel<Boolean>(myclass, "isSelectedForRefund"));
item.add(checkBoxPanel);
}
@Override
public boolean isSortable() {
return true;
}
@Override
public String getSortProperty(){
return "isSelected";
}
});
return new CustomDataTable<MyClass>(tableId, myCloumns, provider, numRows, true);
}
class CheckBoxPanel extends Panel{
private static final String ID_CHECK = "checkBox";
private AjaxCheckBox field;
private IModel model;
public IModel getModel() {
return model;
}
public void setModel(IModel modelObject) {
this.model = modelObject;
}
public CheckBoxPanel(String id, IModel<Boolean> model) {
super(id, model);
System.out.println("clicked here "+ model.toString());
setModel(model);
field = new AjaxCheckBox(ID_CHECK, model) {
@Override
protected void onUpdate(AjaxRequestTarget target) {
target.addComponent(field);
if(this.getModelValue().equals("true")) {
System.out.println("Selected");
}
else if(this.getModelValue().equals("false")) {
System.out.println("UnSelected");
}
}
};
field.setMarkupId(id);
field.add(new SimpleAttributeModifier (ID_CHECK, id));
field.setOutputMarkupId(true);
add(field);
}
public CheckBoxPanel(String id) {
this(id, new Model());
}
}
在我的 html 上,我使用了数据table 标签
<table class="dataview" cellspacing="0" wicket:id="myTable">[table]</table>
您的所有复选框都具有相同的标记 ID。
这混淆了负责为 Ajax 提交收集值的 JavaScript。它使用 document.getElementById('theId').value
并且它始终指向页面中具有该 ID 的第一个元素。
您需要删除 field.setMarkupId(id);
或为所有复选框使用唯一 ID。
我正在使用 wicket 1.4 版本并正在使用数据tables 和 ajax 复选框:
我可以在 html 上呈现复选框。当我点击复选框时,ajax onUpdate 方法也被调用,但它没有给我所选复选框的正确值,即 this.getModelValue() 总是选择[的行的第一个值=25=].
我在这里缺少什么?
add(getMyDynamicTable("myTable", provider, 10));
protected CustomDataTable<MyClass> getMyDynamicTable(String tableId, Provider provider, int numRows) {
final List<IColumn<MyClass>> myCloumns = new ArrayList<>();
myCloumns.add(new AbstractColumn<MyClass>(new ResourceModel(
"isSelected")) {
@Override
public void populateItem(Item<ICellPopulator<MyClass>> item,
String componentId, IModel<MyClass> rowModel) {
final MyClass myclass = rowModel.getObject();
CheckBoxPanel checkBoxPanel = new CheckBoxPanel(componentId, new PropertyModel<Boolean>(myclass, "isSelectedForRefund"));
item.add(checkBoxPanel);
}
@Override
public boolean isSortable() {
return true;
}
@Override
public String getSortProperty(){
return "isSelected";
}
});
return new CustomDataTable<MyClass>(tableId, myCloumns, provider, numRows, true);
}
class CheckBoxPanel extends Panel{
private static final String ID_CHECK = "checkBox";
private AjaxCheckBox field;
private IModel model;
public IModel getModel() {
return model;
}
public void setModel(IModel modelObject) {
this.model = modelObject;
}
public CheckBoxPanel(String id, IModel<Boolean> model) {
super(id, model);
System.out.println("clicked here "+ model.toString());
setModel(model);
field = new AjaxCheckBox(ID_CHECK, model) {
@Override
protected void onUpdate(AjaxRequestTarget target) {
target.addComponent(field);
if(this.getModelValue().equals("true")) {
System.out.println("Selected");
}
else if(this.getModelValue().equals("false")) {
System.out.println("UnSelected");
}
}
};
field.setMarkupId(id);
field.add(new SimpleAttributeModifier (ID_CHECK, id));
field.setOutputMarkupId(true);
add(field);
}
public CheckBoxPanel(String id) {
this(id, new Model());
}
}
在我的 html 上,我使用了数据table 标签
<table class="dataview" cellspacing="0" wicket:id="myTable">[table]</table>
您的所有复选框都具有相同的标记 ID。
这混淆了负责为 Ajax 提交收集值的 JavaScript。它使用 document.getElementById('theId').value
并且它始终指向页面中具有该 ID 的第一个元素。
您需要删除 field.setMarkupId(id);
或为所有复选框使用唯一 ID。