如何在 JSF 数据表或数据模型中保持顺序
我正在使用 JSF,并且有一个复杂的数据表,用户可以在其中按列标题排序、重新排序各个条目等。该表本身包含由只读和可自由编辑的复选框和文本字段组成的行。数据表的每个实例平均约为 50 行,但最多可以扩展到 250 行左右。
鉴于(从数据库中)检索到的数据可以(由用户)调整,我已经沿着 ArrayList 创建包装器集合的路径,其中包含排序、移动数据的能力等。然而,真正的问题是我需要在提交时将行条目的内容和顺序“保留”到数据库中。
我当前的集合正在物理地移动对象,因为我不想维护单独的索引列表,因为担心它们会不同步。这也是我选择将检索到的数据和捕获的数据合并到一个对象中的原因。
这是正确的方法吗?我确实研究了 JSF DataModel,但不确定它是否允许我像物理移动元素一样轻松地以当前排序顺序保留数据。
I'm using JSF and I have a complex datatable where the user can sort by column headings, re-order individual entries, etc. The table itself contains rows that are made up of BOTH read-only and freely editable checkboxes and textfields. Each instance of the datatable averages about 50 rows but can scale up to 250 or so.
Given that retrieved data (from the database) can be adjusted (by the user) I have gone down the path of creating a wrapper collection around an ArrayList that contains sorting, the ability to move data, etc. The real butt kicker however is that I need to "persist" both the contents and the order of the row entries to the database on submit.
My current collection is physically moving the objects around as I didn't want to maintain a separate list of indexes for fear that they would become out of sync. This is also why I choose to combine both the retrieved and captured data into a single object.
Is this the right approach here? I did investigate the JSF DataModel but was not sure if it would allow me to persist the data in the current sort order as easily as physically moving the elements around.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此处,以物理方式移动对象是正确的方法,因为元素数量很少会超过 50 行平均值,因此性能不是问题。
由于对象是物理移动的,因此可以依赖列表的自然索引,而无需为需要不断同步的索引维护单独的数据结构。
Physically moving the objects around was the right approach here as the number of elements would rarely exceeds the 50 row average so performance was not an issue.
Since the objects were physically moved, the natural indexes of the list could be relied upon without having to maintain a separate data structure for the indexes which would need to be constantly synced.