Wicket 中的复选框问题

发布于 2024-12-06 11:53:37 字数 1860 浏览 0 评论 0原文

我发现使用

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

海螺姑娘 2024-12-13 11:53:37

您的所有复选框的检查模型都是相同的(使用 PropertyModel 映射到 ExampleListView.checked),是出于目的吗?

Your checked model is the same for all your checkboxes (using a PropertyModel mapping to ExampleListView.checked), is it by purpose ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文