带有面板列表的检票页面
我正在使用 Apache Wicket 开发一个 Web 应用程序,并且我有三种类型的页面,它们基本上是一个编号列表。每个之间的区别在于列表中项目的显示方式。 (即一个有标题行和一个段落,另一个只有段落)。最终,数据将来自数据库,但目前尚不可用。
我想我可以通过创建一个显示 RepeatingView 的页面来做到这一点,该页面从面板的 ArrayList 获取其项目。我会为每种类型的列表项创建一个不同的面板。然后我可以将上述页面扩展到三个子类,一个子类对应我想要的每种特定类型的面板。我走在正确的道路上吗,或者有更好的方法吗?
I'm working on a web application using Apache Wicket and I have three types of page that are basically a numbered list. The difference between each is how the items in the list are displayed. (i.e. one has a header line and a paragraph, another just has the paragraph). Eventually, the data will come from a database, but that is not available at the moment.
I think I can do this by creating a Page that displays a RepeatingView that gets its items from an ArrayList of Panels. I would create a different Panel for each type of list item. Then I could extend the aforementioned Page to three subclasses, one for each specific type of Panels I want. Am I on the right track, or is there a better way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我发现 RepeatingView 对于此类事情非常灵活,您不应该需要三个单独的页面。它只期望将一个组件添加到转发器中,而不是什么样的组件。只要保持 Wicket ID 一致,您甚至可以混合带有自己标记的组件(例如面板/片段)。
我也不鼓励您使用面板列表。列表包含您的数据,然后根据某个标志添加适当的视图容器,这对于编程来说是很有意义的。
因此,像这样的标记:
适用于以下内容:
您无需向页面提供面板列表,而是从数据库提供相同的数据列表,然后根据当前视图添加不同的面板。
最后,您将获得一个页面(带有视图类型标志)和不同的面板(或片段),用于根据每种视图类型显示数据的外观。
I find RepeatingView to be very flexible with this sort of thing and you shouldn't require three separate pages. It only expects a component to be added to the repeater, not what kind of component. As long as you keep your Wicket IDs consistent, you can even mix components that come with their own markup (e.g. Panel/Fragment).
I also discourage you from using a List of Panels. It just makes good programming sense for the list to contain your data and then add the appropriate view container based on some flag.
So, markup like this:
Works with something like:
Instead of providing a List of Panels to your page, you provide the same list of Data from the database and then add different panels based on the current view.
In the end, you have one page (with a flag for view type) and different panels (or fragments) for how your data should look according to each view type.
我认为您不必对页面进行子类化。据我所知,这一点根本没有改变。所有更改都在面板内。因此,基本上您需要做的就是为您的重复视图提供不同的面板列表。如果差异小到是否显示标题,您甚至不需要为它们创建不同的类。只需将标题设置为空字符串并将其设置为不可见...
基本上是的,您处于正确的轨道之一,也许不是我选择的轨道,但您的也可以...
I don't think you'll have to subclass your Page. As far as I can see, this one doesn't change at all. All the changes are within the panels. So basically all you need to do is to provide your repeating-view with different lists of panels. You wouldn't even need to create different classes for these if the differences are as small as presenting a headline or not. Just set the headline to an empty string and set it to invisible...
Basically yes, you're on one of the right tracks, maybe not the one I'd choose but yours will work too...