Migrating a three-tier Java desktop app to web: how to make only Presentation layer's View in React and keep the rest in Java?

huangapple go评论87阅读模式
英文:

Migrating a three-tier Java desktop app to web: how to make only Presentation layer's View in React and keep the rest in Java?

问题

我想将一个Java桌面应用迁移到Web,使用React作为前端,并将所有内容放在Microsoft Azure云上,但我在这些领域只是初步了解。

在网上很容易找到建议构建标准的Java+React Web应用程序,后端通常由Spring支持,并通过某种HTTP API调用后端的React GUI。如果我的应用程序是一个三层应用程序(具有MVC的表示层/业务逻辑/数据存储),那么我是否正确理解上述意味着第一层将被完全替换为完全重写的React应用程序,而其他两层将仍然保持在Java中,并且只有轻微的更改(添加HTTP API)才能成为后端?

如果是这样,我看到一些不利之处:

  • 在表示层中,我希望尽量减少工作量;只需用一些漂亮和现代的东西替代丑陋的Swing视图,不要太多。但是相反,我发现自己被迫重写GUI逻辑、控制器等 - 而且这是一门我不太熟悉的语言(即JavaScript)。
  • 我有一些被表示层和业务层同时使用的实用函数和库(包含某些pojo或操作文件的函数)。如果我将第一层完全迁移到React,这意味着我需要在JavaScript中复制这些工具,这将是耗时且容易出错的。

我的观察是否正确?如果是这样,我是否可以将我的桌面应用程序分成两个部分:客户端(当前表示层)和服务器(业务和数据层),以便在客户端中,仅从我的当前MVC中重新编写View部分为JavaScript,而Model和Controller将保留在Java中?如何做到这一点?

经过一些搜索,我只看到以下可能性:

  1. 创建前端不是使用纯React,而是与GWT或Vaadin集成React的片段。
  2. 使用转换器(JSweet?)将我的Java代码翻译成JavaScript。

然而,我不想添加一个需要学习并依赖的框架,尤其是一个似乎不太活跃开发和支持的框架。使用转换器有其限制,最好避免。

如果有正当理由,我可以考虑在React之上选择一些其他流行的框架,如Angular或Vue。

英文:

I want to migrate a Java desktop app to web, using React on the front-end and putting everything on Microsoft Azure cloud, but I'm only making first steps in these topics.

It's easy to find in the web suggestions to build a standard Java+React web app with back-end in Java (usually powered by Spring) and React GUI calling the back-end via some HTTP API. If my app is a 3-tier app (presentation layer with MVC / business logic / data storage), do I understand correctly that the above essentially means that the first layer would be fully substituted with a totally rewritten React app, while the other two would remain in Java and with only slight changes (addition of HTTP API) become the back-end?

If so, I see some disadvantages:

  • In the presentation layer I would prefer to make as little work as possible; only substitute ugly Swing views with something nice and modern, not much more. But instead I find myself forced to rewrite also the GUI logic, controllers etc. - and this in a language I don't know well (i.e., Java Script).
  • I have some utility functions and libraries used by both presentation and business layer (containing, for example, certain pojos or functions operating on files). If I move the first layer completely to React, this means I will need to duplicate these tools in JavaScript, which will be time-consuming and error-prone.

Are my observations correct? If so, may I split my desktop app in two: client (current presentation layer) and server (business and data layer), in a way that in the client, out of my current MVC only the View part will be rewritten in JavaScript, while Model and Controller will remain in Java? How to do it?

After some search I only see the following possibilities:

  1. Creating front-end not with pure React, but GWT or Vaadin framework integrated with pieces of React.
  2. Using a transpiler (JSweet?) to translate my Java code to JavaScript.

However, I wouldn't like to add one more framework to learn and depend on, especially one that seems not very actively developed and supported. And using a transpiler has it's limitations, better to be avoided.

If justified, I could consider choosing some other popular framework like Angular or Vue over React.

答案1

得分: 1

只有Vaadin的部分翻译:

使用 Vaadin Flow,您可能能够非常轻松地重新创建您现有的Swing视图。小部件和布局管理器的概念非常相似。您可以使用类似于Swing代码的纯Java代码。或者,您可以使用他们的商业可视编辑器产品

Vaadin应用程序位于服务器上,UI和业务逻辑均以Java编写,并在服务器上的JVM中执行。

Vaadin会自动生成呈现您的表单所需的HTML/CSS/JavaScript,使用标准Web技术在Web客户端远程呈现。用户事件(鼠标点击,字段之间的切换等)会自动传送回服务器Java代码,以响应您的Java代码运行。

完全不需要React,因为Vaadin会透明处理单页面应用DOM操作。您无需编写任何JavaScript。

Vaadin与SpringJakarta CDI兼容。或者您可以选择使用普通的Jakarta Servlets

查看Vaadin Ltd公司页面,了解将Swing应用程序迁移到Vaadin Flow的概述,SWING TO VAADIN

Vaadin在标准Java和标准Jakarta Servlet技术之上部署。因此,正如您提到的那样,您当然可以部署到云端,比如Microsoft Azure,如公司的教程中所示。

英文:

Just Java with Vaadin

With Vaadin Flow, you may be able to very easily recreate your existing Swing views. The concepts of widgets and layout managers are quite similar. You can use straight Java code that reads similarly to Swing code. Alternatively, you can use their commercial visual-editor product.

A Vaadin app lives on the server, both UI and business logic written in Java and executing in JVM on server.

Vaadin automatically generates the HTML/CSS/JavaScript necessary to render your forms remotely in the web client using standard Web technologies. User events (mouse clicks, tabbing between fields, etc.) are automatically transmitted back to server Java code to run your Java code in response.

No need for React at all, as Vaadin handles transparently the single-page-app DOM manipulation. No need for you to write any JavaScript at all.

Vaadin works with Spring and Jakarta CDI. Or you may choose to use plain Jakarta Servlets.

See the Vaadin Ltd company page, SWING TO VAADIN overview for migrating Swing apps to Vaadin Flow.

Vaadin deploys on top of standard Java with standard Jakarta Servlet technologies. So you can certainly deploy to the cloud such as Microsoft Azure as you mentioned, as shown in the company's tutorial.

答案2

得分: 0

Actually, you did a great job in planning for the changes.
首先,我认为您需要将演示逻辑与业务逻辑分开,作为MVC的最佳实践,业务层不能调用演示层或依赖于它,这样您就可以随意更改演示层而不必担心任何问题。

更多阅读:MVC Martin Fawler

我认为在将它们分开时不会有重复,因为您将遵循单一责任原则,并消除了层之间的耦合。

因此,无论您选择GWT(不建议)还是前端框架,这种分离都是强制性的。

还要了解前端的 MVVM

英文:

Actually, you did a great job in planning for the changes.
First, I think you need to separate the presentation logic from the business logic as a best practice in MVC, the business layer cant call the presentation layer or depend on it at all so that you can then change the presentation layer as you want with no concerns.

More Reading : MVC Martin Fawler

And I think that there will be no duplication when separating them as you will be conforming to the Single Responsibility Principle & removing the coupling between layers.

So whether you choose GWT(Not Recommended) or a front end framework this separation is mandatory.

Read About MVVM too for front end

huangapple
  • 本文由 发表于 2020年7月28日 06:55:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/63124781.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定