为什么 UIComponent 中的encodeXxx方法接受FacesContext参数?
我以前从未在 JSF 中创建过自定义组件,所以我现在才注意到 encodeBegin()
、encodeEnd()
等方法接受 FacesContext参数。
FacesContext
实例通常可以通过 FacesContext.getCurrentInstance()
接收。
所以,我想知道这些方法是否有 FacesContext 参数只是为了方便,或者可以在那里传递一些不同的对象(也许来自外部资源..)。如果后者是可能的那么你能举个例子吗?
I haven't ever before created custom components in JSF so I've noticed only now that methods like encodeBegin()
, encodeEnd()
etc accept FacesContext
parameter.
FacesContext
instance can usually be received with FacesContext.getCurrentInstance()
.
So, I wonder whether these methods have FacesContext
parameter just for convenience or some different objects can be passed there (maybe from external resources..). If the latter is possible then could you give an example pls.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它们可能碰巧在不同的线程中运行。
FacesContext#getCurrentIsntance()
只能从 HTTP 请求执行的线程中返回,因为它存储为ThreadLocal
变量。They may happen to run in a different thread.
FacesContext#getCurrentIsntance()
can only for sure be returned from the thread which is executed by the HTTP request since it's stored as aThreadLocal
variable.