JSF的最佳实践是什么?

时间:2021-12-31 15:41:59

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开发的最佳实践。

8 个解决方案

#1


11  

Some tips: Understand the JSF request lifecycle and 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.

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

#2


12  

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 MVC you 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:

  • Life Cycle
  • MDC
  • Component based development
  • 基于组件的开发

  • Tags in h: and f:
  • h:和f中的标签:

At Least One Person:

至少一个人:

  • Creating Custom Components
  • 创建自定义组件

  • Limitations to JSF (back button, random navigation, etc)
  • JSF的限制(后退按钮,随机导航等)

  • 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的实现(最简单的开源实现,如MyFaces))

#3


11  

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开发的最糟糕部分。我正在做一个基于CMS的JSF项目,现在没有facelets(在用它做项目之后),感觉就像我的左臂缺失了....

#4


1  

  • 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.
  • 添加我对facelets的投票。我最近升级了一个使用facelets的项目,它解决了jsf的一些大问题,特别为你提供了一个开箱即用的模板系统,让你在适当的时候使用标准的html,而不是“逐字”包装它标签都有效。

  • RestFaces is a solution to the get/post problem that many people complain about. It's also well documented and easy to use.
  • RestFaces是许多人抱怨的get / post问题的解决方案。它也有很好的文档和易于使用。

  • Don't use to many taglibs. It makes the job a lot harder when upgrading.
  • 不要使用许多taglib。它使升级时的工作变得更加困难。

  • 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.
  • SEAM收集了许多JSF最佳实践,但我还没有使用它,所以我不能真正推荐它,只是建议你去看看它。

#5


0  

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的“生活方式”。他们编写了自己的标记lib,扩展了JSF标准。如果您可以设法留在Rational Application Developer(RAD)(通常不会更新),那么集成有时会出错,但总体上还是不错的。此外,与WebSphere的集成非常好。除非您的雇主与IBM打高尔夫,否则我认为最好尽可能保持香草。

#6


0  

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

#7


0  

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

您可以在以下链接中查看您可以找到有趣文章的位置

http://www.jsftutorials.net/

#8


-1  

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,在休息架构中使用spring mvc,jquery来自view和json。但如果必须,使用primefaces它易于使用,并有足够的组件。

#1


11  

Some tips: Understand the JSF request lifecycle and 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.

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

#2


12  

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 MVC you 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:

  • Life Cycle
  • MDC
  • Component based development
  • 基于组件的开发

  • Tags in h: and f:
  • h:和f中的标签:

At Least One Person:

至少一个人:

  • Creating Custom Components
  • 创建自定义组件

  • Limitations to JSF (back button, random navigation, etc)
  • JSF的限制(后退按钮,随机导航等)

  • 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的实现(最简单的开源实现,如MyFaces))

#3


11  

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开发的最糟糕部分。我正在做一个基于CMS的JSF项目,现在没有facelets(在用它做项目之后),感觉就像我的左臂缺失了....

#4


1  

  • 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.
  • 添加我对facelets的投票。我最近升级了一个使用facelets的项目,它解决了jsf的一些大问题,特别为你提供了一个开箱即用的模板系统,让你在适当的时候使用标准的html,而不是“逐字”包装它标签都有效。

  • RestFaces is a solution to the get/post problem that many people complain about. It's also well documented and easy to use.
  • RestFaces是许多人抱怨的get / post问题的解决方案。它也有很好的文档和易于使用。

  • Don't use to many taglibs. It makes the job a lot harder when upgrading.
  • 不要使用许多taglib。它使升级时的工作变得更加困难。

  • 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.
  • SEAM收集了许多JSF最佳实践,但我还没有使用它,所以我不能真正推荐它,只是建议你去看看它。

#5


0  

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的“生活方式”。他们编写了自己的标记lib,扩展了JSF标准。如果您可以设法留在Rational Application Developer(RAD)(通常不会更新),那么集成有时会出错,但总体上还是不错的。此外,与WebSphere的集成非常好。除非您的雇主与IBM打高尔夫,否则我认为最好尽可能保持香草。

#6


0  

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

#7


0  

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

您可以在以下链接中查看您可以找到有趣文章的位置

http://www.jsftutorials.net/

#8


-1  

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,在休息架构中使用spring mvc,jquery来自view和json。但如果必须,使用primefaces它易于使用,并有足够的组件。