JSF 2 部分请求不使用工厂中的 FacesContext
部分请求似乎不使用由 FacesContextFactory 实现创建的 faces 上下文实例。
这是 UIViewRoot#processDecodes
中的代码,它表明了相同的情况。
if (context.getPartialViewContext().isPartialRequest() &&
!context.getPartialViewContext().isExecuteAll()) {
context.getPartialViewContext().processPartial(PhaseId.APPLY_REQUEST_VALUES);
} else {
super.processDecodes(context);
}
PartialViewContext 似乎在其中存储了默认的 FacesContextImpl 实现,并使用它来调用生命周期方法。 (请注意,processPartial 方法不采用上下文对象,因为它使用自己内部存储的对象)
这是一个错误还是出于特定原因而存在此代码?
谢谢
It seems like the partial requests don't use the faces context instances that are created by FacesContextFactory
implementations.
Here's the code in UIViewRoot#processDecodes
that indicates the same
if (context.getPartialViewContext().isPartialRequest() &&
!context.getPartialViewContext().isExecuteAll()) {
context.getPartialViewContext().processPartial(PhaseId.APPLY_REQUEST_VALUES);
} else {
super.processDecodes(context);
}
It seems like the PartialViewContext stores the default FacesContextImpl implementation within it and uses it to call lifecycle methods. (Notice that the processPartial method doesn't take a context object, because it uses it own internally stored one)
Is this a bug or this code in there for a specific reason?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
FacesContext
实例对于每个线程都是唯一的,FacesServlet
在请求开始时创建一个ThreadLocal
,同时获取FacesContext
(这是FacesContextFactory#getFacesContext 的协定)
并在与 HTTP servlet 请求关联的响应末尾删除它(通过调用FacesContext#release
)。每当您在 JSF 代码中执行
FacesContext#getCurrentInstance()
时,在整个 HTTP servlet 请求/响应处理过程中,您将始终获得相同的实例。关于该方法
UIViewRoot# processDecodes
,我真的没有看到任何一行可能表明该方法使用它自己创建的实例而不是传递的实例。哪一句台词让你这么想?在
FacesServlet#service
方法中可以看到,它从FacesContextFactory
创建了FacesContext
,这里摘录自< code>FacesServlet#service 方法显示了这一点 -考虑到这一点,我认为
UIViewRoot#processDecodes
不能拥有FacesContext
实例,而该实例不是来自FacesContextFactory
。既然你说 - 你已经为从
FacesContextFactory
返回的FacesContext
设置了一些附加参数,这意味着您有自己的FacesContextFactory
自定义实现,如果是这种情况,那么您确定您的实例被注入到FacesServlet
而不是 mojarra 的com.sun 中。 faces.context.FacesContextFactoryImpl(如果您使用的是mojarra)?
FacesContext
instances are unique per thread, and TheFacesServlet
creates aThreadLocal<FacesContext>
on the beginning of the request while acquiring theFacesContext
(which is the contract ofFacesContextFactory#getFacesContext)
and removes it on the end of the response associated with the HTTP servlet request (by calling theFacesContext#release
).Whenever you do a
FacesContext#getCurrentInstance()
in your JSF code, you'll always get the same instance throughout the entire HTTP servlet request/response processing.About the method
UIViewRoot#processDecodes
,I really don't see any line which probably can indicate that method uses it's own created instance rather than the passed one. Which line made you think that?It can be seen in the
FacesServlet#service
method that it creates theFacesContext
from TheFacesContextFactory
, here is a excerpt from theFacesServlet#service
method which shows this -Considering this, I don't feel
UIViewRoot#processDecodes
can have theFacesContext
instance which is not fromFacesContextFactory
.Since you're saying - you have set some additional parameters to the
FacesContext
which get returned fromFacesContextFactory
, that means you have your own custom implementation ofFacesContextFactory
, if this is the case then are you sure that your instance is injected in theFacesServlet
and not mojarra'scom.sun.faces.context.FacesContextFactoryImpl
(if you're using mojarra)?这是我让它发挥作用的方法。下面是我的自定义面孔上下文工厂中的代码
Here's how i got it to work. Below is the code in my custom faces context factory