Java-EE:更干净、更简单的 JSF 替代品

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6307205/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 15:18:29  来源:igfitidea点击:

Java-EE: Cleaner and simpler alternatives to JSF

javajakarta-ee

提问by SDReyes

We are starting to develop a web application using Java EE 6.

我们开始使用 Java EE 6 开发 Web 应用程序。

We got surprised with the complexity of the JSF's generated HTML. I mean even a simple link has some javascript handling code. and this is, in my opinion, a usability problem because browser's gestures (as "ctrl+click" over a link) simply doesn't work. Also, I'm suspecting this could get worse when we need to maintain that code or tweak the UI design with javascript frameworks like jQuery. it reassembles me: Webforms vs ASP.Net MVC. complexity against simplicity.

我们对 JSF 生成的 HTML 的复杂性感到惊讶。我的意思是即使是一个简单的链接也有一些 javascript 处理代码。在我看来,这是一个可用性问题,因为浏览器的手势(如链接上的“ctrl+click”)根本不起作用。此外,我怀疑当我们需要维护该代码或使用 jQuery 等 javascript 框架调整 UI 设计时,情况可能会变得更糟。它重新组合了我:Webforms 与 ASP.Net MVC。复杂对简单。

Anyway this is my first time with JSF. so I really would like to read your experiences with it.

无论如何,这是我第一次使用 JSF。所以我真的很想阅读你的经验。

Do you know a simpler rendering engine for Java EE?

你知道一个更简单的 Java EE 渲染引擎吗?

How has your development experience with JSF been?

您使用 JSF 的开发经验如何?

Have you developed a web app using JSF and lots of jQuery/Dojo/Script.aculo.us?

您是否使用 JSF 和大量 jQuery/Dojo/Script.aculo.us 开发了 Web 应用程序?

采纳答案by maple_shaft

It is hard to define what "simple" means when you ask about a "simpler rendering engine". JSF is a very unique animal and I am afraid there isn't anything simpler that is also similar in the Java world.

当您询问“更简单的渲染引擎”时,很难定义“简单”的含义。JSF 是一种非常独特的动物,恐怕在 Java 世界中没有比这更简单的东西了。

My experience with JSF has been EXTREMELY positive, and this is coming from someone with years of experience developing under ASP.NET. The learning curve is still steep, and I can't imagine complex enterprise systems being possible without some form of custom Javascript and possibly even custom components, however in my opinion it is simplerthan ASP.NET and much less heavyas well. They addressed a lot of the issues that made ASP.NET so difficult to work with, (Eg. simple client ids for the DOM, XHTML compliance).

我对 JSF 的体验非常好,这是来自在 ASP.NET 下有多年开发经验的人。学习曲线仍然很陡峭,我无法想象如果没有某种形式的自定义 Javascript 甚至自定义组件,复杂的企业系统是可能的,但是在我看来,它比 ASP.NET更简单,也更轻。他们解决了许多使 ASP.NET 难以使用的问题(例如,DOM 的简单客户端 ID、XHTML 合规性)。

I recently developed an application that will be going to production shortly using only Primefaces components, standard Mojarra facelets, one custom component, and a handful of Javascript/hidden input field workarounds for component framework bugs. It was stunningly easy aside from the few workarounds I needed to implement. I am extremely happy with the results, the stakeholders LOVE IT and I will absolutely use it again in my next project.

我最近开发了一个应用程序,该应用程序将很快投入生产,仅使用 Primefaces 组件、标准 Mojarra facelets、一个自定义组件和一些针对组件框架错误的 Javascript/隐藏输入字段变通方法。除了我需要实施的少数解决方法之外,这非常容易。我对结果非常满意,利益相关者喜欢它,我绝对会在下一个项目中再次使用它。

In formulating a team my real world experiences with it tell me that it is best to put a highly experienced web application developer as a lead on the project, someone with superb experience in Javascript, CSS and Java web technologies. The rest of team could be entry level developers with a modicum of guidance.

在组建团队时,我的实际经验告诉我,最好让一位经验丰富的 Web 应用程序开发人员作为项目的负责人,他在 Javascript、CSS 和 Java Web 技术方面拥有丰富的经验。团队的其他成员可能是具有少量指导的入门级开发人员。

回答by Adam Davies

I've been working with JSF on a large project. I have experience of working with JQuery, normal HTML/css/javascript, GWT and Gxt. And I can tell you that JSF is the worst of the bunch. If you like your back-end code to be separate and independent of your front-end code then JSP is not the way to go. It littery ties your front-end to your back-end with no clear separation of concerns. The other problem with JSF is that it is very hard to get your head around. Creating great AJAX pages in using frontend technology (e.g. javascript, html and css) is very easy. My 14 year of son gets taught how to do it at school. Getting the same effect using JSF is incredibly complicated. Take a look at how to define as link: <h:commandLink value="New" immediate="true" action="#{projectUiService.showProjectCreate}" />. And there is no way to specify a form action url. You have to use the JSF managed beans and navigation semantics. It's a completely new front-end language. So even if you want to style up the front-end or add JQuery in you'll be stuffed.

我一直在与 JSF 合作进行一个大型项目。我有使用 JQuery、普通 HTML/css/javascript、GWT 和 Gxt 的经验。我可以告诉你,JSF 是最糟糕的。如果您希望您的后端代码独立于您的前端代码,那么 JSP 不是要走的路。它乱七八糟地将您的前端与后端联系在一起,而没有明确的关注点分离。JSF 的另一个问题是很难理解。使用前端技术(例如 javascript、html 和 css)创建出色的 AJAX 页面非常容易。我 14 岁的儿子在学校学习如何做。使用 JSF 获得相同的效果非常复杂。看看如何定义为链接:<h:commandLink value="New" immediate="true" action="#{projectUiService.showProjectCreate}" />. 并且无法指定表单操作 url。您必须使用 JSF 托管 bean 和导航语义。这是一种全新的前端语言。因此,即使您想设置前端样式或在其中添加 JQuery,您也会被塞满。

Configuring your build and runtime environment is also a pain. There are so many inter-dependencies among jar files that if you don't have the right combination of JSF, Richfaces, and Spring Jars, then you have no hope of getting your application even out of the build build environment. If you want to get a hint at this then go to the maven search site and look for the class javax.faces.component.UIViewRoot. Everyone and their dog has it. Also take note at the javax.faces and com.sun.faces - what's the difference? Who knows, but they don't work together. And some version only work with specific version of RichFaces.

配置构建和运行时环境也很痛苦。jar 文件之间有如此多的相互依赖关系,如果您没有 JSF、Richfaces 和 Spring Jars 的正确组合,那么您就没有希望使您的应用程序甚至脱离构建构建环境。如果您想获得这方面的提示,请访问 maven 搜索站点并查找类javax.faces.component.UIViewRoot。每个人和他们的狗都有。还要注意 javax.faces 和 com.sun.faces - 有什么区别?谁知道,但他们不一起工作。并且某些版本仅适用于特定版本的 RichFaces。

My advice - stay well clear. Give your app a spring back-end and a normal HTML front-end. There is no way you can write a decent large enterprise scale application in JSF. It would be just too complicated. You'll end up with a huge monolithic code base that would be almost impossible to maintain.

我的建议 - 保持清醒。为您的应用程序提供一个弹簧后端和一个普通的 HTML 前端。您无法在 JSF 中编写体面的大型企业级应用程序。那就太复杂了。您最终会得到一个几乎不可能维护的庞大的单体代码库。

回答by Steven Benitez

Do you actually need a component-based framework like JSF or are you looking for a more traditional web request-based MVC framework? If so, you may want to look into Apache Struts2or Spring MVC. Spring MVC requires that you use the core Spring library.

您是否真的需要像 JSF 这样的基于组件的框架,还是正在寻找更传统的基于 Web 请求的 MVC 框架?如果是这样,您可能需要查看Apache Struts2Spring MVC。Spring MVC 要求您使用核心 Spring 库。

回答by Cosmin Cosmin


I've been working with JSF for 3 years and I can say that the most powerful thing about it is that it abstracts the communication between browser (form input or actions) http request and Java.
There are rich libraries available for JSF, like: ICEfaces, RichFaces, ADF Faces, PrimeFaces, which gives you a big amount of rich components that may be enough for you.
JSF tries to make development of web applications more close to desktop applications. It addresses the most common tasks for a web application (no matter the technology) and automates them using its LifeCycle.
However if you want in some cases a certain behaviour that's different from how a component works, you have to make some workarounds, or build your own components (which may be hard, except for composite components).
I have integrated JS successfully for tasks that didn't need to trigger some action in Javalike select all checkboxes, hide/show some parts of the page, and so on.
JSF is very easy, yet very powerful, and requires a certain expertise for some tasks.
The last version of JSF, 2.0, addresses the common problems JSF had, because of its POST nature, so now I'm very happy with it.
Regarding users gestures like ctrl+click, the way web applications in JSF work is a little different than normal ones, buttons Back, Forward, Refresh might not work as expected sometimes. But hey, great web applications have the same behaviour: Try Ctrl+Click in PayPal.. or try Back Button in Vodafone.ro
If you want full control over your HTML, use plain JSP. But when you have a huge web application, JSF is a good option for Rapid Application Development(RAD).


我使用 JSF 已经 3 年了,我可以说它最强大的地方在于它抽象了浏览器(表单输入或操作)http 请求和 Java 之间的通信。
JSF 有丰富的库可用,比如:ICEfaces、RichFaces、ADF Faces、PrimeFaces,它们为您提供了大量丰富的组件,可能足以满足您的需求。
JSF 试图使 Web 应用程序的开发更接近桌面应用程序。它解决了 Web 应用程序(无论采用何种技术)最常见的任务,并使用其生命周期将它们自动化。
但是,如果您在某些情况下想要与组件的工作方式不同的特定行为,则必须采取一些变通方法,或构建自己的组件(这可能很难,复合组件除外)。
我已经成功地将 JS 集成到不需要在 Java 中触发某些操作的任务,例如选择所有复选框、隐藏/显示页面的某些部分等。
JSF 非常简单,但功能非常强大,并且需要对某些任务具有一定的专业知识。
JSF 的最后一个版本 2.0 解决了 JSF 的常见问题,因为它具有 POST 性质,所以现在我对它非常满意。
对于像 ctrl+click 这样的用户手势,JSF 中的 Web 应用程序的工作方式与正常的有点不同,按钮后退、前进、刷新有时可能无法按预期工作。但是,嘿,优秀的 Web 应用程序具有相同的行为:在PayPal 中尝试 Ctrl+Click .. 或在Vodafone.ro 中尝试后退按钮
如果您想完全控制您的 HTML,请使用普通的 JSP。但是,当您拥有一个庞大的 Web 应用程序时,JSF 是快速应用程序开发 (RAD) 的不错选择。

回答by Dima

Do you know a simpler rendering engine for Java EE?

你知道一个更简单的 Java EE 渲染引擎吗?

JSF IS the most powerful technology for presentation layer in the mainstream Java EE. That became true only after introduction of "Composite Components". However the less known HybridJavasolution is non less powerful but yet simpler than JSF.

JSF是主流Java EE中最强大的表示层技术。只有在引入“复合组件”之后,这才成为现实。然而,鲜为人知的HybridJava解决方案同样强大,但比 JSF 更简单。