(如何)我可以提供自定义类来在 Wicket 中设置页面吗?
我想更改 Wicket 实例化 URL 子集的 Page
实例的方式。通常,我会使用 mount()
将类映射到 URL,在这种情况下,Wicket 选择该类的可用构造函数之一并实例化它。
我的应用程序的一部分是简单的 CRUD 操作,这些操作在不同的实体类型之间有很多共同点。我已经将共同的方面分解到一些工厂和帮助程序类中,现在我的页面留下了一个类层次结构,如下所示:
TemplatePage | AbstractEntityPage | | AbstractVenuePage AbstractEventPage | | | | ViewVenuePage EditVenuePage ViewEventPage EditEventPage
我想删除最后两个级别,因为层次结构开始随着更多实体而蔓延添加了类型,并且这些类中留下的代码非常少,可以轻松地将其分解为更通用的对象。
将 AbstractEntityPage
转换为 EntityPage
类非常容易,该类可根据需要插入特定组件。我通常会使用 Builder 来执行此操作,但我不确定如何告诉 Wicket 使用它?我在 API 文档中找不到相关的钩子。
I would like to change the way Wicket instantiates my Page
instance for a subset of URLs. Normally, I would map a class to a URL with mount()
, in which case Wicket chooses one of the available constructors on that class and instantiates it.
A part of my application are simple CRUD operations that have a lot in common between different entity types. I have factored out the common aspects into some factory and helper classes and now I'm left with a class hierarchy for my pages which looks like this:
TemplatePage | AbstractEntityPage | | AbstractVenuePage AbstractEventPage | | | | ViewVenuePage EditVenuePage ViewEventPage EditEventPage
I would like to cut the last two levels, because the hierarchy starts to sprawl as more entity types are added and there's very little code left in those classes which could be factored out easily to more generic objects.
It's rather easy to transform AbstractEntityPage
into a class EntityPage
that gets specific components plugged in place as needed. I would normally use a Builder to do this, but I'm not sure how I would tell Wicket to use it? I couldn't find a hook for that in the API docs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将默认的 IPageFactory 替换为 org.apache.wicket.settings.ISessionSettings.setPageFactory(IPageFactory) ,并在特殊页面时使用不同的实例化策略。
You can replace the default IPageFactory with org.apache.wicket.settings.ISessionSettings.setPageFactory(IPageFactory) and use different strategy of instantiating the page if it is special one.
您可以使用 EntityPage 并在面板中实现差异,但随后您需要大量类似的面板(或者一些通用面板,如果它们没有真正的不同)。或者您可以看一下 wicket 的快速原型库之一,例如 wicketopia。我不认为它们(我发现和测试的那些)中的任何一个都可以用于生产,但它们可以被用来寻找想法g。
You could use an EntityPage and implement the differences within your panels, but then you'd need a lot of similar panels (or a few generic panels if they don't really differ). Or you could take a look at one of the rapid prototyping libraries for wicket like wicketopia. I wouldn't consider any of them (the ones I found and tested) to be production-ready but they can be salvaged for ideas g.