昨天我看了一个关于Java Server Faces 2.0的演示,它看起来确实令人印象深刻,尽管我现在是一个快乐的ASP。asp.net MVC / jQuery开发。我最喜欢JSF的地方是它有大量支持ajax的UI组件,这使得开发比使用ASP要快得多。NET MVC,特别是在ajax较多的站点上。集成测试看起来也很不错。

由于这个演示只强调了JSF的优点,所以我也想听听其他方面的情况。

所以我的问题是:

Java Server Faces 2.0的主要缺点是什么? 什么会使JSF开发人员考虑使用ASP。NET MVC而不是JSF?


当前回答

在使用JSF工作了5年之后,我认为我可以添加我的2分。

Two major JSF drawbacks: Big learning curve. JSF is complex, that's just true. Its component nature. Component-based framework tries to hide the true nature of the Web, which comes with a huge amount of complications and disasters (like not supporting GET in JSF within almost 5 years). IMHO hiding HTTP Request/Response from the developer is an enormous mistake. From my experience, every component-based framework adds abstraction to the Web development, and that abstraction results in unnecessary overhead and higher complexity.

And minor drawbacks that come to my mind: By default ID of the object is composed of its parents' ids, for example form1:button1. No easy way to comment-out incorrect page's fragment. Tag <ui:remove> needs syntactically correct content which is parsed anyway. Low quality 3rd party components which e.g. don't check isRendered() inside processXxx() method before continuing. Incorporating LESS & Sencha is hard. Doesn't play well with REST. Not so easy for UX designers, because ready-to-use components have their own CSS styles, that need to be overwritten.

不要误会我的意思。作为一个组件框架,JSF在版本2中确实很好,但它仍然是基于组件的,而且永远是……

请看看Tapestry、Wicket的低人气以及有经验的JSF开发人员的低热情(这是更有意义的)。 作为对比,看看Rails、Grails、Django、Play!框架——它们都是基于动作的,不会试图向程序员隐藏真实的请求/响应和web的无状态特性。

对我来说,这是JSF的主要缺点。恕我直言,JSF可以适合某些类型的应用程序(内部网、表单密集型),但对于现实生活中的web应用程序来说,它不是一个好方法。

希望它能帮助一些人做出关于前端的选择。

其他回答

我想到了一些缺点:

JSF is a component-based framework. This has inherent restrictions that have to do with obeying the component-model. AFAIK JSF supports only POST, so if you want a GET somewhere you have to do a plain servlet/JSP. Most components try to provide abstractions over domains like relational databases and front-end JavaScript, and many time these abstractions are "leaky" and very hard to debug. These abstractions might be a good starting point for a junior developer or someone not comfortable with a particular domain (e.g. front-end JavaScript), but are very hard to optimise for performance, since there are several layers involved, and most people that use them have little understanding of what is going on under the hood. The templating mechanisms that are usually used with JSF have nothing to do with how web desigers work. The WYSIWYG editors for JSF are primitive and in any case, your designer will give you HTML/CSS that you'll have to spend ages converting. Things like EL expressions are not statically checked and both the compiler and IDEs are not doing a good job at finding errors, so you'll end up with errors that you'll have to catch at run-time. This might be fine for dynamically typed language like Ruby or PHP, but if I have to withstand the sheer bloat of the Java ecosystem, I demand typing for my templates.

总而言之:使用JSF节省的时间,从避免编写JSP/servlet/bean样板代码,您将花费10倍的时间来使其可伸缩并完全按照您的要求进行操作。

在使用JSF工作了5年之后,我认为我可以添加我的2分。

Two major JSF drawbacks: Big learning curve. JSF is complex, that's just true. Its component nature. Component-based framework tries to hide the true nature of the Web, which comes with a huge amount of complications and disasters (like not supporting GET in JSF within almost 5 years). IMHO hiding HTTP Request/Response from the developer is an enormous mistake. From my experience, every component-based framework adds abstraction to the Web development, and that abstraction results in unnecessary overhead and higher complexity.

And minor drawbacks that come to my mind: By default ID of the object is composed of its parents' ids, for example form1:button1. No easy way to comment-out incorrect page's fragment. Tag <ui:remove> needs syntactically correct content which is parsed anyway. Low quality 3rd party components which e.g. don't check isRendered() inside processXxx() method before continuing. Incorporating LESS & Sencha is hard. Doesn't play well with REST. Not so easy for UX designers, because ready-to-use components have their own CSS styles, that need to be overwritten.

不要误会我的意思。作为一个组件框架,JSF在版本2中确实很好,但它仍然是基于组件的,而且永远是……

请看看Tapestry、Wicket的低人气以及有经验的JSF开发人员的低热情(这是更有意义的)。 作为对比,看看Rails、Grails、Django、Play!框架——它们都是基于动作的,不会试图向程序员隐藏真实的请求/响应和web的无状态特性。

对我来说,这是JSF的主要缺点。恕我直言,JSF可以适合某些类型的应用程序(内部网、表单密集型),但对于现实生活中的web应用程序来说,它不是一个好方法。

希望它能帮助一些人做出关于前端的选择。

Inexperienced developers usually will create applications that are painfully slow and code will be really ugly and hard to maintain. Its deceptively simple to start, but actually requires some investment in learning if you want to write good programs. At least at the start you will often "stuck" on some problem and will spend more time reading balusc posts on internet than actually working :) After a while it will be less and less of that, but it still can be annoying. Even more annoying when you find out that the problem is not due to you lack of knowledge/mistake but actually a bug. Mojarra was(is?) quite buggy, and another layer of components adds even more problems. Richfaces was biggest piece of crap software ever written :) Don't know how it is now on version 4. We have Primefaces which is better, but still you will run into bugs or lack of features especially with more exotic components. And now you will need to pay for Primefaces updates. So I would say its buggy but its getting better especially after 2.2 version fixed some problems with spec. Framework getting more mature but still far from perfect (maybe myfaces better?). I don't find it especially flexible. Often if you need something very very customized and there are no components that does that - it will be a bit painful. Again I'm talking from average developer perspective - the one with deadlines, quick reading tutorials, and searching stackoverflow when getting stuck because no time to learn how it really works :) Often some components seems to have "almost" what you need, but not exactly and sometimes you might spend too much time to make it do something you want :) Need to be careful in evaluating if its better to create your own or torture existing component. Actually if you are creating something really unique I would not recommend JSF.

简而言之,我的缺点是:复杂,开发过程不流畅,漏洞百出,缺乏灵活性。

当然也有好处,但这不是你问的。不管怎样,这是我使用框架的经验,其他人可能有不同的意见,所以最好的方法是尝试一段时间,看看它是否适合你(只是一些更复杂的东西-不是天真的例子- JSF真的很出色:)依我看,JSF的最佳用例是业务应用程序,如crm等…

评论我过去几个月的Primefaces/JSF体验:

如果你可以使用“现成的”组件,我想这并不可怕。 然而,当你走到外面并需要定制ui时,它就不能很好地发挥作用。-例如,我们需要在项目中使用Twitter的bootstrap。(不是primefaces bootstrap)。 现在我们的页面工作如下: 页面加载。 用户与具有ajax功能的Primefaces交互 Bootstrap的javascript绑定中断 我们运行额外的javascript来重新绑定所有内容

JSF避免编写javascript的承诺变成了编写比不使用Primefaces时更多的javascript——而javascript是用来修复Primefaces破坏的。

这是一个时间消耗器——除非你再次使用现成的东西。当不得不与Selenium一起工作时,也非常丑陋(Primefaces)。这些都是可以做到的,但是时间有限。

如果你和UX/设计团队一起工作,并且需要快速迭代UI,你可以通过学习jquery/编写直接的HTML来节省时间,或者查看react/angular。

在所有的“主流”框架中,如Spring MVC、Wicket、Tapestry等,Java EE的JSF及其复合组件是所提供的最精细的表示层和面向组件的技术。与HybridJava提供的解决方案相比,它有点麻烦和不完整。