Wicket 中的复选框问题
我发现使用
item.add(new CheckBox("selected",new PropertyModel(this, "checked")).setEnabled(false));
获取默认检查的复选框计数时出现问题任何帮助表示赞赏。
我的 Listview 类:
ExampleListView(String id, List<Extended> lists, PageParameters params){
protected void populateItem(ListItem<Extended> item)
{
item.add(new CheckBox("selected",new PropertyModel(this, "checked")).setEnabled(false));
}
boolean checked= true;
public boolean isChecked() { return checked; }
public void setChecked(boolean checked) { this.checked = checked; }
}
我需要选中并禁用该复选框(某种只读选中的复选框)。在其他情况下,我还需要 item.add(new CheckBox("selected", new PropertyModel(this, "checked")));
如上面的代码所示,我引入了 Checked 布尔值,这会在 UI 中显示选定的复选框,但选定的计数列表不会
在 My Form 类构造函数中递增:
public class ExampleForm{
public ExampleForm(String id, List<Extended> list, PageParameters params){
add(new ExampleListView("Rows", list,params));
AjaxButton<Void> button= new AjaxButton<Void>("Button"){
@Override
public void onClick(AjaxRequestTarget target) {
for (Extended extn : list) {
if (((Extended)extn).isSelected()) {
selected.add(extn);
}
}
};
}
add(button);
}
}
my Html file :
<input class="simpleLink" wicket:id="selected" type="checkbox"/>
Class file:
public class Extended implements Serializable {
private transient boolean selected = false;
public boolean isSelected() {
return selected;
}
public void setSelected (Boolean selected) {
this. selected = selected;
}
}
I am finding an issue in getting the checkboxes count that are checked by default using,
item.add(new CheckBox("selected",new PropertyModel(this, "checked")).setEnabled(false));
Any help is appreciated.
My Listview class:
ExampleListView(String id, List<Extended> lists, PageParameters params){
protected void populateItem(ListItem<Extended> item)
{
item.add(new CheckBox("selected",new PropertyModel(this, "checked")).setEnabled(false));
}
boolean checked= true;
public boolean isChecked() { return checked; }
public void setChecked(boolean checked) { this.checked = checked; }
}
This I need to have the checkbox selected and disabled (kind of read only selected checkbox). In other scenario I also need to have item.add(new CheckBox("selected", new PropertyModel(this, "checked")));
As shown in above code, I introduced, Checked boolean, this displays a selected checkbox in UI, but the selected count list did not get incremented
In My Form class constructor:
public class ExampleForm{
public ExampleForm(String id, List<Extended> list, PageParameters params){
add(new ExampleListView("Rows", list,params));
AjaxButton<Void> button= new AjaxButton<Void>("Button"){
@Override
public void onClick(AjaxRequestTarget target) {
for (Extended extn : list) {
if (((Extended)extn).isSelected()) {
selected.add(extn);
}
}
};
}
add(button);
}
}
my Html file :
<input class="simpleLink" wicket:id="selected" type="checkbox"/>
Class file:
public class Extended implements Serializable {
private transient boolean selected = false;
public boolean isSelected() {
return selected;
}
public void setSelected (Boolean selected) {
this. selected = selected;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的所有复选框的检查模型都是相同的(使用
PropertyModel
映射到ExampleListView.checked
),是出于目的吗?Your checked model is the same for all your checkboxes (using a
PropertyModel
mapping toExampleListView.checked
), is it by purpose ?