开发者

JSF2 SessionBean to be initialized before page access

We are using JSF2 and Tomcat6. We need to initialize a session bean with backend values before the开发者_StackOverflow中文版 user access the first page. May I know how to do this?


If you just want to access common, session scoped data, from a page, you could

  • write a session bean just for that data
  • use that session bean in all pages that need access to this data; a page doesn't need to use only one bean, you could use some bean for most page specific data and one for common data
  • use that session bean as a "managed property" (@ManagedProperty annotation in jsf2) in all beans that require access to this common data


What you ask is strictly spoken not possible. A session is created exactly once a user does his first request. You can in general not create sessions in advance for users that have never requested any page on your server.

Any session scoped bean that is referenced from a page will be initialized during the first call to that page, and only during that first call. This is the best you can get.

(If you actually mean a SessionBean and not a session scoped managed bean, then things are a little different. As you haven't used the EJB tag on your question I suppose it's the latter.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜