JSF 与普通 JSP +豆子?

发布于 2024-10-11 20:13:36 字数 357 浏览 3 评论 0原文

我可以选择使用 JSF 或 JSP 来完成我的下一个项目。其他语言/框架不是一个选择。

我不想使用任何可视化组件库,例如 RichFaces、IceFaces 等,因为过去我使用它们的经历非常糟糕,所以我会优先选择 jQuery组件完全做我想要他们做的事情。

同样,我不会为数据访问组件而烦恼。

此外,由于 JSF 对 JSP 有许多限制(例如,不支持 GET、无法避免有状态等),所以我正在考虑一直采用 JSP+Beans。

JSF 中还有其他我会错过的东西吗?

I have the option of doing my next project in either JSF or JSP. Other languages/frameworks are not an option.

I don't want to use any of the visual component libraries like RichFaces, IceFaces, etc, because in the past I've had very bad experiences with them, so I'll be cherry-picking jQuery components to do exactly what I want them to do.

Similarly I won't be bothering with data access components.

Moreover since JSF comes with many restrictions over JSPs (e.g. no support for GET, cannot avoid being stateful, etc.), I'm considering going JSP+Beans all the way.

Are there any other things I'll be missing from JSF?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

友欢 2024-10-18 20:13:36

你所说的限制实际上并不存在。 JSF 绝对支持 GET。事实上,它一直支持这一点,尽管有一些限制。您所做的是将 #{param.some_id} 注入到您的 bean 中,并在 @PostContruct 带注释的方法中执行一些操作。

在 JSF 2.0 中,这种支持得到了极大的扩展,您可以将标准验证器和转换器附加到它们,这是在 JSF 1.x 中无法做到的。

JSF 的优点很多,但在进行普通 JSP 开发时我错过的一件特别的事情是拥有一个可用的转换器和验证器库。无论你做什么类型的Web开发,无论你的客户端代码多么花哨,最终都必须在服务器上执行一些操作,然后你必须进行转换和验证。

使用 JSF,您可以轻松构建自己的转换器和验证器库,或者从许多已经可用的库中进行选择。通过 bean 验证 (Java EE 6),这可以提升到一个新的水平:使用约束注释您的实体,JSF 将在 UI 中为您强制执行这些约束。 (请注意,JSF 本身不包含 bean 验证,但它支持它)。

然后我还发现拥有一种简单但有效的模板语言会非常有帮助。即使您只使用很少或根本不使用 JSF 组件,您也可以创建主模板页面、拥有模板客户端并将基于 jQuery 的 javascript 和 HTML 放入可以在服务器端轻松重用的块中。 JSP 实际上只有 jsp:include 用于模板化,这是相当有限的。

JSF 的另一个方便的小事情是您可以轻松地以编程方式访问与当前请求相对应的请求和响应对象。如果您没有利用 JSF 的许多核心功能,那么在 JSP/Servlet 风格编程中这可能是一个小优势。

但正如 BalusC 已经指出的那样,也许 JSF 不适合您。最大的好处是使用框架的组件。如果您不打算使用这些,一些基于请求的可能更适合您。

The restrictions you speak of are not really there. JSF absolutely supports GET. It has in fact always supported this, although with some limitations. What you did was injecting #{param.some_id} into your bean and taking some action in a @PostContruct annotated method.

With JSF 2.0 this support has been greatly expanded and you can attach standard validators and convertors to them, something you couldn't do in JSF 1.x.

The advantages of JSF are many, but one particular thing I missed when doing plain JSP development is having a library of convertors and validators available. No matter what kind of web development you do, and no matter how fancy your client-code is, eventually some operation has to be performed on the server and then you have to do conversion and validation.

With JSF you can easily build your own library of those convertors and validators, or choose from many of the ones that are already available. With bean validation (Java EE 6) this can be taken to the next level: annotate your entities with constraints and JSF will enforce those for you in the UI. (note that JSF itself doesn't contain bean validation, but it supports it).

Then I also found that having a simple but effective templating language can be very helpful. Even if you only use few or maybe no JSF components at all, you can create master template pages, have template clients and put your jQuery based javascript and HTML in chunks that you can easily reuse at the server side. JSP really only has jsp:include for templating, which is rather limiting.

Another small handy thing with JSF is that you have easy programmatic access to the request and response objects corresponding with the current request. If you're not taking advantage of many of JSF's core features, then in JSP/Servlet style programming this can be a small advantage.

But as BalusC already indicated, maybe JSF is not for you. The greatest benefit is when using the framework for its components. If you don't plan on using these, some request based might fit you better.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文