简体   繁体   English

使用JSF 2.0 jsf-2.0处理Bean初始化的最佳实践

[英]Best Practice to Handle Backing Bean initialization with JSF 2.0 jsf-2.0

I have an @PostConstruct init() function in my backing bean that performs a lengthy database query. 我的后备Bean中有一个@PostConstruct init()函数,该函数执行冗长的数据库查询。

The backing bean is @SessionScoped. 支持bean是@SessionScoped。

Every time I perform an Ajax query, I hit that init() and the database query fires off again. 每次我执行Ajax查询时,我都会点击init(),数据库查询会再次触发。

Do I need to check life cycle phase in my init() before firing the database query? 在触发数据库查询之前,是否需要在init()中检查生命周期阶段? Or should I store the details in a more persistent object such as the current User? 还是应该将详细信息存储在更持久的对象(例如当前用户)中?

Best regards, Alan 最好的问候,艾伦

@PostConstruct for @SessionScoped beans is executed only once per user session, so it is the correct place to initialize the bean. @SessionScoped bean的@PostConstruct在每个用户会话中仅执行一次,因此它是初始化bean的正确位置。 Make sure the bean is indeed in session scope, and that the multiple executions of it are not actually coming from different users (=> sessions) 确保bean确实在会话范围内,并且它的多次执行实际上不是来自不同的用户(=>会话)

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

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