当两个不同的 wicket 应用程序共享通用功能时,如何重用代码

发布于 2024-11-18 21:41:59 字数 285 浏览 2 评论 0原文

我有一个 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 技术交流群。

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

发布评论

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

评论(4

温柔一刀 2024-11-25 21:41:59

我的公司一直都是这样做的。我们有一个核心包,其中包含基本的 UserApplication、用户帐户、登录、身份验证等。然后,我们开发的每个项目都扩展了这个基本包。存在一些重复 - 例如,几乎所有配置文件在每个文件中看起来都相同 - 但每个文件都有自己的 theme 目录,该目录提供标记,根据应用程序的外观和感觉进行定制。

执行此操作时的一些建议:

  1. 核心应用程序应该有相当数量的 getXPanel() 方法,每个子应用程序都会重写这些方法。例如,getHeaderPanel()
  2. 使用每个人都扩展的“BasePage”类。您可以在此处设置整体外观,在子应用程序主题文件夹中覆盖,并大量使用 功能。也是放置 jQuery 导入等的好地方。
  3. 请记住,标记很容易被覆盖。您的子应用程序不需要创建页面的 java 扩展来更改徽标。只需使用不同的标记即可。

我们的每个应用程序至少分为 4 个模块。例如:

  1. base - Wicket 依赖项、基本事件日志记录
  2. 数据 - UserApplication、AdminPage、User hibernate 对象。每个页面都有自己的标记,但通常会被覆盖。
  3. science - 一个核心项目,包含大量用于显示科学教科书的代码。 ScienceApplication 扩展了 UserAppication
  4. Foundations - 针对小学生的主题特定实现 FoundationsApplication extends ScienceApplication
  5. 查询 - 针对高中生的不同主题特定实现 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:

  1. The core application should have a fair number of getXPanel() methods that each sub-application overrides. For example, getHeaderPanel()
  2. Use a "BasePage" class that everyone extends. This is where you set up your overall look-and-feel, overridden in sub-application theme folders, and make heavy use of <wicket:extend> features. Also a good place to put your jQuery import, ec.
  3. Keep in mind that markup is easily overridden. Your sub-application doesn't need to create java extensions of pages in order to change the logos. Just use different markup.

Each of our applications is divided into at least 4 modules. For example:

  1. base - Wicket dependency, basic event logging
  2. data - UserApplication, AdminPage, User hibernate obect. Each page has its own markup, but is usually overridden.
  3. science - A core project with a lot of code for displaying a science textbook. ScienceApplication extends UserAppication.
  4. foundations - A theme specific implementation for elementary students FoundationsApplication extends ScienceApplication
  5. inquiry - A different theme specific implementation for high school students 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.

鸩远一方 2024-11-25 21:41:59

这是基于组件的框架的要点。
将公共代码(组件、行为、会话基类、应用程序等)放在单独的 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!

从您的其他评论和答案来看:

  1. 重构您的应用程序并将所有通用代码推送到(抽象)基类。
  2. 将它们移至新项目并将 2 个新应用程序项目的 BuildPath 设置为需要基础包。
  3. 扩展您的基类以实现不断变化的功能。

根据您当前的实现,您可以通过实现两个不同的图像资源或通过从新项目向基本页面提供不同的模型来更改徽标,或者您可以将图像 URL 放入您的属性中并在应用程序中提供不同的属性文件。
这对于数据库或表同样有效...例如,使用 JPA,您可以将所有全局使用的实体推送到您的基础,并使用不同的表名称实现两个不同的用户实体。您甚至可以使用共享的抽象基本用户实体来减少那里的代码重复。

Judging from your other comments and answers:

  1. Refactor your application and push all common code to (abstract) base classes.
  2. Move these to a new project and set the BuildPath of your 2 new application-projects to require the base package.
  3. Extend your base classes to implement the changing functionality.

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.

时光磨忆 2024-11-25 21:41:59

从你的问题来看,我猜你主要关心的是页面。那么这是我的建议:
首先,您应该指定页面的哪些部分可以从一个应用程序更改为另一个应用程序。然后你要把这些部分的数据拿出来才能得到模板。现在您应该决定(根据您的要求)如何存储数据(例如,在 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.

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