当两个不同的 wicket 应用程序共享通用功能时,如何重用代码
我有一个 Wicket AuthenticatedWebApplication,其中有几个页面和功能需要在我必须开发的新 AuthenticatedWebApplication 中重用。
我正在使用 Wicket 1.4、Spring 和 Hibernate。
两个应用程序甚至将共享相同的外观(应用程序徽标除外),现在已在基页面中实现。
有人有类似的经历吗?我绝对不想重复复制粘贴代码,因为通用功能实现了一个可以并且将会改变的工作流程。
我可以做什么来保持我的应用程序模块化并实现我的目标?
I have a Wicket AuthenticatedWebApplication which has several pages and features that need to be reused in a new AuthenticatedWebApplication that I have to develop.
I am using Wicket 1.4, Spring and Hibernate.
Both applications will even share the same look (except for Application logo) which is now implemented in a base page.
Has anyone had a similar experience? I definitely don't want to recur to copy-paste code because the common functionality implements a workflow process which can and will change.
What can I do to keep my applications modular, and achieve my goal?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我的公司一直都是这样做的。我们有一个核心包,其中包含基本的 UserApplication、用户帐户、登录、身份验证等。然后,我们开发的每个项目都扩展了这个基本包。存在一些重复 - 例如,几乎所有配置文件在每个文件中看起来都相同 - 但每个文件都有自己的
theme
目录,该目录提供标记,根据应用程序的外观和感觉进行定制。执行此操作时的一些建议:
getXPanel()
方法,每个子应用程序都会重写这些方法。例如,getHeaderPanel()
功能。也是放置 jQuery 导入等的好地方。我们的每个应用程序至少分为 4 个模块。例如:
ScienceApplication 扩展了 UserAppication
。FoundationsApplication extends ScienceApplication
InquiryApplication extends ScienceApplication
我们的两个科学应用程序具有不同的标头,甚至几个不同的页面,但是
ScienceApplication
有我上面描述的那些方法。My company does this all the time. We have a core package that holds the base UserApplication, User accounts, login, authentication, etc. Then, every project we develop extends this base package. There is some duplication - e.g. almost all of the configuration files look identical in each - but each one has it's own
theme
directory that supplies the markup, customized to the look and feel of the application.Some suggestions as you do this:
getXPanel()
methods that each sub-application overrides. For example,getHeaderPanel()
<wicket:extend>
features. Also a good place to put your jQuery import, ec.Each of our applications is divided into at least 4 modules. For example:
ScienceApplication extends UserAppication
.FoundationsApplication extends ScienceApplication
InquiryApplication extends ScienceApplication
Our two science applications have different headers and even a few different pages, but
ScienceApplication
has a those methods I described above.这是基于组件的框架的要点。
将公共代码(组件、行为、会话基类、应用程序等)放在单独的 java 项目 (.jar) 中。稍后在特定的 .war 项目中依赖此项目(将 .jar 放在 WEB-INF/lib 中)。瞧!
This is the main point of component based frameworks.
Put the common code (components, behaviors, base classes as session, application, ...) in a separate java project (.jar). Later depend on this project in the specific .war projects (put the .jar in WEB-INF/lib). Voila!
从您的其他评论和答案来看:
根据您当前的实现,您可以通过实现两个不同的图像资源或通过从新项目向基本页面提供不同的模型来更改徽标,或者您可以将图像 URL 放入您的属性中并在应用程序中提供不同的属性文件。
这对于数据库或表同样有效...例如,使用 JPA,您可以将所有全局使用的实体推送到您的基础,并使用不同的表名称实现两个不同的用户实体。您甚至可以使用共享的抽象基本用户实体来减少那里的代码重复。
Judging from your other comments and answers:
Depending on your current implementation, you can change your logo by implementing two different imageresources or by providing different models from your new projects to your basebasepage or you could put the image-url into your properties and supply different propertyfiles in your applications.
The same is valid for databases or tables... For example with JPA you colud push all the global used entities to your base and implement two different user-entities using different table names. You could even use a shared abstract baseUser-entity to reduce code duplication there.
从你的问题来看,我猜你主要关心的是页面。那么这是我的建议:
首先,您应该指定页面的哪些部分可以从一个应用程序更改为另一个应用程序。然后你要把这些部分的数据拿出来才能得到模板。现在您应该决定(根据您的要求)如何存储数据(例如,在 xml 文件、DB 中)。
现在,您可以根据需要从在线或离线模板编译页面。
From your question I guess your main concern is about pages. Then this is my suggestion:
First, you should specify which parts of the pages can change from one application to another application. Then you have to take out the data of these parts to get the templates. Now you should decide (based on your requirement) how you want to store data (e.g., in xml files, DB).
Now you can compile your pages from templates online or offline based on your needs.