如何在加载页面时触发ActionListener?

时间:2012-06-26 11:16:29

标签: jsf primefaces

使用JSF 2.0(和Primefaces),是否有办法在加载页面时触发ActionListener?

由于

1 个答案:

答案 0 :(得分:1)

取决于您的需求,例如,如果您想在bean中初始化某些内容,可以将f:eventpreRenderView一起使用:

检查此链接: 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;
    }