开发者

(How) can I provide a custom class to set up pages in Wicket?

开发者 https://www.devze.com 2023-03-21 23:03 出处:网络
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 constru

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 th开发者_运维知识库is:

                          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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号