java JSF 的最佳实践是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31924/
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-29 10:47:57  来源:igfitidea点击:

What are the best practices for JSF?

javajsf

提问by David Waters

I have done Java and JSP programming in the past, but I am new to Java Server Faces and want to know if there's a set of best practices for JSF development.

我过去做过 Java 和 JSP 编程,但我是 Java Server Faces 的新手,想知道是否有一组 JSF 开发的最佳实践。

采纳答案by Rowan

Some tips: Understand the JSF request lifecycleand where your various pieces of code fit in it. Especially find out why your model values will not be updated if there are validation errors.

一些提示: 了解 JSF 请求生命周期以及您的各种代码片段在其中的位置。尤其要找出如果存在验证错误,为什么您的模型值不会更新。

Choose a tag library and then stick with it. Take your time to determine your needs and prototype different libraries. Mixing different taglibs may cause severe harm to your mental health.

选择一个标签库,然后坚持下去。花点时间确定您的需求并构建不同库的原型。混合不同的标签库可能会对您的心理健康造成严重伤害。

回答by Tim Howland

Consider using facelets- it greatly simplifies the worst parts of JSF development. I'm doing a CMS-based JSF project now without facelets (after doing a project with it) and it feels like my left arm is missing....

考虑使用facelets- 它极大地简化了 JSF 开发中最糟糕的部分。我现在正在做一个没有 facelets 的基于 CMS 的 JSF 项目(在用它做了一个项目之后),感觉就像我的左臂不见了......

回答by David Waters

I would strongly recommend getting someone experienced in JSF to lead your first project in JSF even if this means paying a contractor for 3 months. The JSF approach is very different to JSP. The way you approach and solve problems is very different.

我强烈建议让在 JSF 方面有经验的人领导您在 JSF 中的第一个项目,即使这意味着要支付承包商 3 个月的费用。JSF 方法与 JSP 非常不同。你处理和解决问题的方式是非常不同的。

Libraries

图书馆

Consider the following libraries:

考虑以下库:

Architecture

建筑学

Embrace MVCyou need not only to know what this means but use it extensively.

拥抱MVC,您不仅需要知道这意味着什么,还需要广泛使用它。

There are two main patterns for associating controllers with the views

将控制器与视图相关联有两种主要模式

Dot Net Style, One Request controller per view

点网样式,每个视图一个请求控制器

Every top level page has a request scoped controller (bean) all validation and actions of the page use this class. Also used for filtering and ordering the Model. The Model will be stored on a few session level controllers which will handle talking to the back-end (EJBs, or persistence layer) these session controllers should be implementing the business logic and have no knowledge of JSF,HTML or any presentation technology.

每个顶级页面都有一个请求范围的控制器(bean),页面的所有验证和操作都使用这个类。也用于过滤和排序模型。模型将存储在几个会话级控制器上,这些控制器将处理与后端(EJB 或持久层)的对话,这些会话控制器应该实现业务逻辑并且不了解 JSF、HTML 或任何表示技术。

Controllers are session level

控制器是会话级别的

Design controllers based on your data model, nest them with in each other. (This post is getting too long so I wont go into the nuts and bolts of these).

根据您的数据模型设计控制器,将它们相互嵌套。(这篇文章太长了,所以我不会深入研究这些细节)。

Knowledge Required

所需知识

Everyone:

每个人:

At Least One Person:

至少一人:

  • Creating Custom Components
  • Limitations to JSF (back button, random navigation, etc)
  • Debug 3rd party libraries (At least one person has to be comfortable breaking out the debugger and stepping into the implementation of JSF (easiest with open source implementations like MyFaces))
  • 创建自定义组件
  • JSF 的限制(后退按钮、随机导航等)
  • 调试 3rd 方库(至少有一个人必须能够轻松地打开调试器并进入 JSF 的实现(最容易使用 MyFaces 等开源实现))

回答by Erik I

  • Add my vote for facelets. I've recently upgraded a project to use facelets, and it solves some big issues with jsf, specially giving you a decent template system right out of the box and letting you use standard html when it is appropriate, without wrapping it in "verbatim"-tags.
  • RestFaces is a solution to the get/post problem that many people complain about. It's also well documented and easy to use.
  • Don't use to many taglibs. It makes the job a lot harder when upgrading.
  • SEAM collects many of the JSF best practices, but I haven't used it yet, so I can't really recommend it, just recommend you to take a look at it.
  • 添加我对 facelets 的投票。我最近升级了一个项目以使用 facelets,它解决了 jsf 的一些大问题,特别是为您提供了一个开箱即用的体面模板系统,并让您在适当的时候使用标准 html,而不用“逐字逐句”包装它-标签。
  • RestFaces 是解决很多人抱怨的 get/post 问题的方法。它也有据可查且易于使用。
  • 不要使用很多标签库。升级时它使工作变得更加困难。
  • SEAM收集了很多JSF的最佳实践,但是我还没用过,所以不能真正推荐,只推荐大家看看。

回答by fnCzar

I have been using the IBM implementation of JSf and have some comments. It is not a bad way to go but you have to commit to the IBM 'way-of-life'. They have written their own tag lib which extends the JSF standard. If you can manage to stay inside of Rational Application Developer (RAD) (which does not get updated THAT often), the integration is sometimes buggy but overall decent. Also the integration with WebSphere is pretty good. Unless your employer plays golf with IBM, I think it is better to stay as vanilla as possible.

我一直在使用 JSf 的 IBM 实现,并有一些评论。这不是一个糟糕的方式,但您必须致力于 IBM 的“生活方式”。他们编写了自己的标签库,扩展了 JSF 标准。如果您能够设法留在 Rational Application Developer (RAD)(它不会经常更新),那么集成有时会出错,但总体上还不错。与 WebSphere 的集成也非常好。除非您的雇主与 IBM 打高尔夫球,否则我认为最好保持原样。

回答by fnCzar

I am not yet aware of a "Best Practice" for cross field / form level validation.

我还不知道跨字段/表单级别验证的“最佳实践”。

That is, JSF validation is currently orientated to single field validation. IMO it gets ugly when you look at complex cross field / form level validation.

也就是说,JSF 验证目前面向单字段验证。当您查看复杂的跨字段/表单级别验证时,IMO 会变得丑陋。

Old but still looks acurate to me http://weblogs.java.net/blog/johnreynolds/archive/2004/07/improve_jsf_by_1.html

旧但对我来说仍然很准确 http://weblogs.java.net/blog/johnreynolds/archive/2004/07/improve_jsf_by_1.html

http://www.jroller.com/robwilliams/entry/jsf_multi_field_validation_not

http://www.jroller.com/robwilliams/entry/jsf_multi_field_validation_not

回答by Darkaico

You could check it the following link in where you could find interesting articles

你可以查看以下链接,在那里你可以找到有趣的文章

http://www.jsftutorials.net/

http://www.jsftutorials.net/

回答by ayengin

Select a good component library .Do not use richfaces , i suggest you dont use jsf , use spring mvc,jquery fro view and json in a rest architecture. but if you have to ,use primefaces it easy to use and has enough components.

选择一个好的组件库。不要使用richfaces,我建议你不要使用jsf,在rest架构中使用spring mvc、jquery fro view和json。但是如果必须的话,请使用primefaces,它易于使用并且具有足够的组件。