Apache Wicket Repeater:概述
Wicket 有许多 AbstractRepeater 的实现:ListView、DataView、GridView、Loop、PropertyListView 等。
就我个人而言,我发现很难确定哪种视图最适合哪种场景。我通常坚持使用 DataView,但这只是因为我已经习惯了。也许 GridView 更适合场景 A,PropertyListView 更适合场景 B,...
是否有人知道解释视图差异的博客或任何教程,或者有人可以解释哪种视图最适合哪种用例?
Wicket has many implementations of AbstractRepeaters: ListView, DataView, GridView, Loop, PropertyListView etc.
Personally, I find it hard to determine which view would be ideal for which scenario. I usually stick to DataView but that's simply because I'm used to it. Maybe GridView would be better for scenario A, a PropertyListView for B, ....
Is anyone aware of a blog or any tutorial where the differences of the views are explained or anyone who can explain which view is best for which use case?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Wicket 有很多额外的、琐碎的类,这会导致您的困惑。不同的组件更适合不同的场景,但是有很多 Wicket 组件适用于极少数情况,不会增加任何真正的复杂性。
例如,
RequiredTextField
是一个完整的类,相当于:我认为这源于旧版本,其中所需的设置更加复杂,但它仍然会引起一些混乱。
你们的许多中继器都是相似的。
PropertyListView
只是将模型包装在CompoundPropertyModel
中,使属性表达式更容易(见下文)。但是,您可以轻松地自己进行此更改。因此,这是我的快速总结,因为我无法找到您所描述的最新博客文章:
RepeatingView - 当您没有列表或要添加列表时非常有用不同类型的组件(因此内部标记也不同)。
ListView - 如果您有一个
List
并且要显示整个内容,则非常有用。遗憾的是,它不适用于其他排序的集合。DataView - 如果您从数据库加载,则很有用。其他方法允许您轻松排序、分页和修改数据集。
PropertyListView - 如果您只是通过属性表达式显示值,则很有用。允许您执行操作
而不是
循环 - 如果您想重复
整数
次而不是一组数据,则非常有用。这相当于一个ListView
,其模型对象是一个List
,填充了从0
到length
GridView - 对于获取单个列表(例如 21 个字符串)并使用两组标记(内部/外部)来分组显示该列表(例如 7x3 网格)非常有用。但是,它假设您的标记使用某些 wicket:id,但没有详细记录。我认为您最好使用一对嵌套的 RepeatingView 组件来完成相同的任务。
希望有帮助!
Wicket has a lot of additional, trivial classes, which is causing your confusion. Different components are better for different scenarios, but there are a lot of Wicket components for rare cases that don't add any real complexity.
For example,
RequiredTextField
is an entire class that is equivalent to:I presume this stems from an older version where setting required was more complicated, but it's still there to cause some confusion.
Many of your repeaters are similar.
PropertyListView
just wraps the model in aCompoundPropertyModel
, making property expressions easier (see below). However, you could easily make this change yourself.So, here is my quick summary as I have been unable to find an up-to-date blog post as you've described:
RepeatingView - very useful when you do not have a list or you are adding different types of components (and therefore different internal markup).
ListView - useful if you have a
List
and you're displaying the whole thing. Sadly, it does not work with other sorted collections.DataView - useful if you are loading from a Database. Additional methods allow you to easily sort, page, and modify the data set.
PropertyListView - useful if you are simply displaying values via a property expression. Allows you to do
instead of
Loop - useful if you want to repeat an
Integer
number of times instead of a set list of data. This would be equivalent to aListView
whose model object is aList<Integer>
filled with integers from0
tolength
GridView - useful for taking a single list (e.g. 21 strings) and using two sets of markup (inner/outer) to display that list in groups (e.g. a 7x3 grid). It assumes, however, that your markup uses certain wicket:id's, which is not well documented. I think you would be better off with a pair of nested
RepeatingView
components, which accomplish the same thing.Hope that helps!