带有面板列表的检票页面

发布于 2024-12-03 18:41:53 字数 281 浏览 1 评论 0原文

我正在使用 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 技术交流群。

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

发布评论

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

评论(2

妥活 2024-12-10 18:41:53

我发现 RepeatingView 对于此类事情非常灵活,您不应该需要三个单独的页面。它只期望将一个组件添加到转发器中,而不是什么样的组件。只要保持 Wicket ID 一致,您甚至可以混合带有自己标记的组件(例如面板/片段)。

我也不鼓励您使用面板列表。列表包含您的数据,然后根据某个标志添加适当的视图容器,这对于编程来说是很有意义的。

因此,像这样的标记:

<div wicket:id="repeater">
   <div wicket:id="listItem" />
</div>

适用于以下内容:

RepeatingView rv = new RepeatingView("repeater");

for (DataObject o : dataList) {
   // You can probably add to the rv directly, but this is the common usage
   WebMarkupContainer c = new WebMarkupContainer(rv.newChildId());
   rv.add(c);
   if (shortVersion)
       c.add(new ShortPanel("listItem", new Model<DataObject>(o)));
   else
       c.add(new LongPanel("listItem", new Model<DataObject>(o)));
}

您无需向页面提供面板列表,而是从数据库提供相同的数据列表,然后根据当前视图添加不同的面板。

最后,您将获得一个页面(带有视图类型标志)和不同的面板(或片段),用于根据每种视图类型显示数据的外观。

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:

<div wicket:id="repeater">
   <div wicket:id="listItem" />
</div>

Works with something like:

RepeatingView rv = new RepeatingView("repeater");

for (DataObject o : dataList) {
   // You can probably add to the rv directly, but this is the common usage
   WebMarkupContainer c = new WebMarkupContainer(rv.newChildId());
   rv.add(c);
   if (shortVersion)
       c.add(new ShortPanel("listItem", new Model<DataObject>(o)));
   else
       c.add(new LongPanel("listItem", new Model<DataObject>(o)));
}

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.

℡Ms空城旧梦 2024-12-10 18:41:53

我认为您不必对页面进行子类化。据我所知,这一点根本没有改变。所有更改都在面板内。因此,基本上您需要做的就是为您的重复视图提供不同的面板列表。如果差异小到是否显示标题,您甚至不需要为它们创建不同的类。只需将标题设置为空字符串并将其设置为不可见...

基本上是的,您处于正确的轨道之一,也许不是我选择的轨道,但您的也可以...

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...

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