简体   繁体   English

如何在呈现页面之前执行bean方法?

[英]How to execute a bean method before page is rendered?

What is the best approach to execute a method in a bean before the JSF page using that bean is rendered? 在呈现使用该bean的JSF页面之前在bean中执行方法的最佳方法是什么?

Update : I am trying to execute a method which would populate some data used by the JSF backing bean. 更新 :我正在尝试执行一个方法,该方法将填充JSF支持bean使用的一些数据。 This backing bean is used in a form on a JSP page, where I need some prepopulated data. 这个支持bean在JSP页面上以一种形式使用,我需要一些预先填充的数据。

在JSF2中,您也可以使用系统事件。

<f:event type="preRenderView" listener="#{customerBean.loadData}"/>

Constructor of bean / post construct @PostConstruct methods will do it. bean / post构造@PostConstruct方法的构造函数就可以了。

But the best approach is greatly depends on the functionality you are implementing , 但最好的方法在很大程度上取决于您正在实施的功能,

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

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