【发布时间】:2012-10-07 15:09:51
【问题描述】:
我有一个奇怪的问题,我使用的是 JSF 2.1.6 和 Primefaces 3.4。
问题是我的@ViewScoped bean 中的@PostConstruct 在 onSelectNavigate 之后再次被触发,这会导致 NPE,因为 Flash Scope 中不再设置东西。
我有以下init()方法
@PostConstruct 公共无效初始化(){
log.debug("initing DashBoard");
epsDashboardVos = new ArrayList<>();
for (Eps eps : epsService.getEpss()) {
/// do some stufff
}
}
在同一个 bean 中使用以下导航方法
public void onSelectedEpsNavigate(EpsDashboardVo selectedEps) {
log.debug("Selecting eps and moving to detail screen : "
+ selectedEps.getEps().getName());
FacesContext.getCurrentInstance().getExternalContext().getFlash()
.put("selectedEps", selectedEps.getEps());
// adjust header
menuController.setCurrentPage("View EPS Status - "
+ selectedEps.getEps().getName());
ConfigurableNavigationHandler configurableNavigationHandler = (ConfigurableNavigationHandler) FacesContext
.getCurrentInstance().getApplication().getNavigationHandler();
configurableNavigationHandler
.performNavigation("epsdashboard-detail-view?faces-redirect=true");
}
然后我在日志中看到的是,调用了 navigate 方法,但随后再次调用了同一个 bean 中的 init() 方法。
17 Oct 2012 11:54:07,244 DEBUG com.xxxx.eps.subscription.controller.EpsDashboardViewController : initing DashBoard
17 Oct 2012 11:54:09,550 DEBUG com.xxxx.eps.subscription.controller.EpsDashboardViewController : Selecting eps and moving to detail screen : M0951-EPS2X-DEV-Commercial
17 Oct 2012 11:54:09,553 DEBUG com.xxxx.eps.subscription.controller.EpsDashboardViewController : initing DashBoard
17 Oct 2012 11:54:09,639 DEBUG com.xxxx.eps.subscription.controller.EpsDashboardDetailViewController : initing DashBoard
【问题讨论】:
标签: jsf-2 primefaces