如何选择的多行与
我使用
列出数据库中的数据。我们在页面中有很多记录,现在我想选择多条记录,每行都有一个复选框。我怎样才能实现这个目标?
I use <h:dataTable>
to list data from database. We have many records in page, now I would like to select multiple records with a checkbox in each row. How can I achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您的实体设计良好,具有唯一的技术标识符,例如来自数据库的自动增量序列。
如果没有,您需要添加它。
然后,将
Map属性添加到绑定到表的 bean。
(预初始化也可以发生在(后)构造函数中,你可以选择,至少 JSF 不会为你做这件事;哦,给它一个 getter 方法,setter 不是必需的)
然后,添加一个带有复选框的列,该复选框通过实体 ID 作为键映射到布尔值。
现在,在与删除按钮关联的操作方法中,您可以收集并删除选中的项目,如下所示:
I assume that your entity is that well-designed that it has an unique technical identifier, for example the auto increment sequence from the DB.
If not, you'll need to add it.
Then, add a
Map<Long, Boolean>
property to the bean which is tied to the table.(preinitialization can also happen in (post)constructor, take your pick, at least JSF won't do it for you; oh, give it a getter as well, a setter is not necessary)
Then, add a column with a checkbox which maps to the boolean value by entity ID as key.
Now, in the action method associated with the delete button, you can collect and delete the checked items as follows: