简体   繁体   English

从Servlet访问JSF ViewScoped托管bean

[英]Access JSF ViewScoped managed bean from Servlet

How may I access a JSF ViewScoped managed bean from a Servlet? 如何从Servlet访问JSF ViewScoped托管bean?

(Assume that the managed bean in question has already been created, and still not been destroyed) (假设所讨论的托管bean已经创建,但仍未销毁)

View-scoped variables are stored in the view map on the component tree. 视图范围的变量存储在组件树的视图图中 To access this data outside the view context you would have to create a JSF context and restore the view for the request. 要在视图上下文之外访问此数据,您将必须创建JSF上下文并为请求还原视图 This involves rewriting much of the functionality provided by the JSF container . 这涉及重写JSF容器提供的许多功能。

JSF 2 provides mechanisms for interacting with server-side state without a page refresh: AJAX tags and the JSF JavaScript API . JSF 2提供了无需页面刷新即可与服务器端状态进行交互的机制: AJAX标记JSF JavaScript API I would look at utilizing those if possible. 如果可能的话,我会考虑利用它们。

Alternatively, place the data into a scope that is easily accessible via servlets (the session.) 或者,将数据放入可通过servlet(会话)轻松访问的范围。

Since the view state is generally held in the session, it is likely technically possible to access the view state from here. 由于视图状态通常保存在会话中,因此从技术上来说,从此处访问视图状态是可能的。 But this would involve implementation-specific hacks that may not survive an upgrade of the underlying framework. 但这将涉及特定于实现的黑客,这些黑客可能无法在基础框架的升级中幸免。 I wouldn't even look at this as a solution. 我什至不会将其视为解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM