FacesContext 有何用途?

发布于 2024-11-04 20:46:08 字数 47 浏览 1 评论 0 原文

FacesContext 的用途是什么?

它具体是在哪里实现的?

What is FacesContext used for?

And where exactly is it implemented?

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

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

发布评论

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

评论(4

苹果你个爱泡泡 2024-11-11 20:46:08

引用 JSF 2.0 规范第 6.1 章:

FacesContext

JSF 定义
javax.faces.context.FacesContext
用于表示的抽象基类
所有的上下文信息
与处理传入的
请求,并创建
相应的响应。

一个FacesContext
实例由 JSF 创建
在开始实施之前
请求处理生命周期,由
调用 getFacesContext 方法
FacesContextFactory,如中所述
第 6.6 节“FacesContextFactory”。

当请求处理生命周期
已完成,JSF
实现将调用发布
方法,它给出了 JSF
实施的机会
释放任何获取的资源,如
以及汇集和回收
FacesContext 实例而不是
为每个请求创建新的请求。

它在类 javax.faces.context 中指定.FacesContext 和 Mojarra 中在类 com.sun.faces.context.FacesContextImpl 并在类 org.apache.myfaces.context.servlet.FacesContextImpl

另请参阅:

Quote from chapter 6.1 of JSF 2.0 specification:

FacesContext

JSF defines the
javax.faces.context.FacesContext
abstract base class for representing
all of the contextual information
associated with processing an incoming
request, and creating the
corresponding response.

A FacesContext
instance is created by the JSF
implementation, prior to beginning the
request processing lifecycle, by a
call to the getFacesContext method of
FacesContextFactory, as described in
Section 6.6 “FacesContextFactory”.

When the request processing lifecycle
has been completed, the JSF
implementation will call the release
method, which gives JSF
implementations the opportunity to
release any acquired resources, as
well as to pool and recycle
FacesContext instances rather than
creating new ones for each request.

It is specified in class javax.faces.context.FacesContext and in Mojarra implemented in class com.sun.faces.context.FacesContextImpl and in MyFaces implemented in class org.apache.myfaces.context.servlet.FacesContextImpl.

See also:

烙印 2024-11-11 20:46:08

每个新请求都会创建 FacesContext 的新实例。 FacesContext 的主要任务是提供与其关联的特定请求相关的所有信息。
例如:要在某些验证或转换失败后添加消息,您可以简单地将消息添加到 FacesContext,最终在屏幕上显示所需的消息。
您还可以通过调用查看甚至随时停止 JSF 生命周期

    FacesContext.responseComplete();

A new instance of FacesContext gets created with every new request. The main task of FacesContext is to provide all the information regarding the particular request with which it is associated.
For example : to add messages after certain validation or conversion failure, you can simply add the message to the FacesContext which ultimately displays the desired message on the screen.
Also you can take a look and even stop the JSF lifecycle at any point by calling

    FacesContext.responseComplete();
拥醉 2024-11-11 20:46:08

FacesContext 包含与单个 JavaServer Faces 请求的处理以及相应响应的呈现相关的所有每个请求状态信息。它被传递到请求处理生命周期的每个阶段,并可能被其修改。

在请求处理开始时,通过调用与当前 Web 应用程序关联的 FacesContextFactory 实例的 getFacesContext() 方法,将 FacesContext 实例与特定请求关联起来。该实例保持活动状态,直到调用其release()方法为止,之后不允许进一步引用该实例。当 FacesContext 实例处于活动状态时,除了执行此 Web 应用程序的 Servlet 容器用于处理此请求的线程之外,不得从任何线程引用它。

参考:

http://docs.oracle.com/ javaee/6/api/javax/faces/context/FacesContext.html

FacesContext contains all of the per-request state information related to the processing of a single JavaServer Faces request, and the rendering of the corresponding response. It is passed to, and potentially modified by, each phase of the request processing lifecycle.

A FacesContext instance is associated with a particular request at the beginning of request processing, by a call to the getFacesContext() method of the FacesContextFactory instance associated with the current web application. The instance remains active until its release() method is called, after which no further references to this instance are allowed. While a FacesContext instance is active, it must not be referenced from any thread other than the one upon which the servlet container executing this web application utilizes for the processing of this request.

reference:

http://docs.oracle.com/javaee/6/api/javax/faces/context/FacesContext.html

樱花坊 2024-11-11 20:46:08

Facescontext 是连接到框架的锚点,并且
容器特定服务。例如,您可以获得
页面请求的底层 httprequest 和上下文对象
通过 Facescontext 访问您的支持 bean。那
包括网页请求正在运行的安全上下文。

JSF 背后的总体理念是用户提供的组件
应该足够抽象,不依赖于诸如是否
他们在传统的 JSP 环境或其他环境中运行
异国情调,所以如果 bean 中存在 Facescontext 引用,那么它就是
不良设计的潜在迹象,特别是因为豆类预计会
将东西注入其中,而不是出去寻找东西。

但是,有时出于某种原因,到达很方便
从支持 bean 中获取外围信息,所以它是
如果你需要的话就在那里。

参考:Facescontext Context Object有什么用

The Facescontext is the anchor point for connecting to framework-and
container- specific services. For example, you can obtain the
underlying httprequest and context objects for the page request that's
accessing your backing bean by going through the Facescontext. That
includes the security context a web page request is running under.

The general philosophy behind JSF is that the user-provided components
should be abstract enough not to depend on such details as to whether
they're running in a traditional JSP environment or something more
exotic, so if there's a Facescontext reference in the bean, it's a
potential sign of bad design, especially since beans are expected to
have things injected into them, not go out looking for stuff.

However, sometimes for one reason or another, it's convenient to reach
out of the backing bean and obtain the outlying information, so it's
there if you need it.

Reference: What is the use of Facescontext Context Object

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