使用 JSF 2.0(和 Primefaces),有没有办法在加载页面时触发 ActionListener?
谢谢
取决于您的需要,例如,如果您想在 bean 中初始化某些东西,可以使用f:event
with :preRenderView
检查此链接: http ://www.mkyong.com/jsf2/jsf-2-prerenderviewevent-example/
但是您应该知道每个请求都会调用该事件:ajax,验证失败...。您可以检查它是否是这样的新请求:
public boolean isNewRequest() {
final FacesContext fc = FacesContext.getCurrentInstance();
final boolean getMethod = ((HttpServletRequest) fc.getExternalContext().getRequest()).getMethod().equals("GET");
final boolean ajaxRequest = fc.getPartialViewContext().isAjaxRequest();
final boolean validationFailed = fc.isValidationFailed();
return getMethod && !ajaxRequest && !validationFailed;
}