当UI可以用jQuery和AngularJS等JavaScript库来实现时,需要什么JSF [英] What is the need of JSF, when UI can be achieved with JavaScript libraries such as jQuery and AngularJS

查看:22
本文介绍了当UI可以用jQuery和AngularJS等JavaScript库来实现时,需要什么JSF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读到 JSF 是一个 UI 框架并提供了一些 UI 组件.但是它与 jQueryUI、AngularJS、React、Vue.js、ExtJS 甚至纯 HTML、CSS 和 JavaScript 中可用的组件数量相比有什么优势或不同.

I was reading about JSF that it's a UI framework and provides some UI components. But how is it better or different from number of components that are available from jQueryUI, AngularJS, React, Vue.js, ExtJS, or even plain HTML, CSS and JavaScript.

为什么要学习 JSF?

Why should someone learn JSF?

推荐答案

JSF 到普通 JSP/Servlet/HTML/CSS/JS 就像 jQuery 到普通 JS:用更少的代码做更多的事情.以 PrimeFaces(基于 jQuery + jQuery UI)为例,浏览它的 showcase 查看完整的代码示例.BootsFaces(基于 jQuery + Bootstrap UI)也有一个 展示 完整的代码示例.如果您仔细研究这些示例,您会发现您基本上需要一个简单的 Javabean 类作为模型和一个 XHTML 文件作为视图.

JSF to plain JSP/Servlet/HTML/CSS/JS is like as jQuery to plain JS: do more with less code. To take PrimeFaces (jQuery + jQuery UI based) as an example, browse through its showcase to see complete code examples. BootsFaces (jQuery + Bootstrap UI based) has also a showcase with complete code examples. If you study those examples closely, then you'll see that you basically need a simple Javabean class as model and a XHTML file as view.

请注意,您不应将 JSF 视为单独的 HTML/CSS/JS 的替代品,您还应该考虑服务器端部分(特别是:JSP/Servlet).JSF 消除了收集 HTTP 请求参数、转换/验证它们、更新模型值、执行正确的 Java 方法来完成业务以及生成 HTML/CSS/JS 样板代码的所有样板的需要.使用 JSF,您基本上最终会得到一个 XHTML 页面作为视图定义和一个 Javabean 类作为模型定义.这大大加快了开发速度.

Note that you should not see JSF as replacement of alone HTML/CSS/JS, you should also take the server side part into account (specifically: JSP/Servlet). JSF removes the need of all the boilerplate of gathering HTTP request parameters, converting/validating them, updating the model values, executing the right Java method to do the business stuff and generating the HTML/CSS/JS boilerplate code. With JSF you basically end up with a XHTML page as view definition and a Javabean class as model definition. This greatly speeds up development.

与每个基于组件的 Web MVC 框架一样,您在 JSF 中对呈现的 HTML/CSS/JS 的控制不那么细粒度.添加自定义 JS 代码并不容易,因为您还必须考虑服务器端的 JSF 视图状态(例如,在 JS 端启用禁用按钮不会在 JSF 端启用按钮,这反过来又是一个巨大的安全优势).然而,如果这是一个主要的表演者,那么不如寻找一个基于动作的 Web MVC 框架,比如 Spring MVC.您只需考虑您必须自己编写所有 HTML/CSS/JS 代码(以及防止 XSS、CSRF 和 DOM 操作!)自己.此外,如果您从 Facelets 退回到 JSP,您也会错过高级模板功能.

As with every component based web MVC framework, you have in JSF less fine-grained control over the rendered HTML/CSS/JS. Adding custom JS code isn't that easy as you have to take the JSF view state in the server side into account as well (e.g. enabling a disabled button in JS side won't enable the button in JSF side, which is in turn a huge security advantage). If that is however a major showstopper, then rather look for an action based web MVC framework like Spring MVC. You'll only take into account that you have to write all that HTML/CSS/JS code (and prevention against XSS, CSRF and DOM-manipulation!) yourself. Also if you fall back from Facelets to JSP, you'll miss advanced templating capabilities as well.

另一方面,如果您有一个基于 JSP/Servlet/HTML/CSS/JS/jQuery 的大型网站,并且您想将重复的 JSP/Servlet/HTML/CSS/JS/jQuery 样板代码重构为可重用的组件,那么解决方案之一就是 JSF.自定义模板、标记文件和组件可以帮助实现这一点.从这个角度来看,JSF 高于 JSP/Servlet/HTML/CSS/JS/jQuery(这也是为什么在深入研究 JSF 之前了解这些基础知识非常重要的原因).

On the other hand, if you have a big JSP/Servlet/HTML/CSS/JS/jQuery based website and you'd like to refactor the repeated JSP/Servlet/HTML/CSS/JS/jQuery boilerplate code into reusable components, then one of the solutions would be JSF. Custom templates, tagfiles and components can aid in this. In that perspective, JSF stands above JSP/Servlet/HTML/CSS/JS/jQuery (and that's also why it's pretty important to understand those basics before diving into JSF).

你可以在这里找到一个基于 JSF 的真实项目:Java EE Kickoff App.你会看到它包含在 JSF 一样好 HTML5, CSS3jQuery.

You can find a real world kickoff JSF based project here: Java EE Kickoff App. You'll see that it contains next to JSF as good HTML5, CSS3 and jQuery.

这篇关于当UI可以用jQuery和AngularJS等JavaScript库来实现时,需要什么JSF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆