触发前称为BEFORE的JSF getter方法 [英] JSF getter methods called BEFORE beforePhase fires

查看:52
本文介绍了触发前称为BEFORE的JSF getter方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建议将给定页面的所有数据查找都放在beforePhase中,但是,由于我正在做更深入的分析,因此似乎在触发beforePhase之前已调用了一些getter方法.

I got a recommendation to put all data lookups in the beforePhase for a given page, however, now that I am doing some deeper analysis it appears that some getter methods are being called before the beforePhase is fired.

当我添加了对url参数的支持并且在beforePhase调用中初始化的对象上获取了NPE时,这变得非常明显.

It became very obvious when I added support for a url parameter and I was getting NPEs on objects that are initialized in the beforePhase call.

有什么想法吗?我设置错了.

Any thoughts? Something I have set wrong.

我的JSP页面中有此内容

I have this in my JSP page:

<f:view beforePhase="#{someController.beforePhaseSummary}">

那只是JSP文件中的第五行,就在标记库之后.

That is only the 5th line in the JSP file and is right after the taglibs.

这是beforePhaseSummary方法中的代码:

Here is the code that is in the beforePhaseSummary method:

public void beforePhaseSummary(PhaseEvent event) {
    logger.debug("Fired Before Phase Summary: " + event.getPhaseId());
    if (event.getPhaseId() == PhaseId.RENDER_RESPONSE) {
        HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
        if (request.getParameter("application_id") != null) {
            loadApplication(Long.parseLong(request.getParameter("application_id")));
        }
        /* Do data fetches here */
    } 
}

上面的日志输出表明已触发事件. Servlet请求用于捕获url参数.数据获取收集数据.但是,日志记录输出如下:

The logging output above indicates that an event is fired. The servlet request is used to capture the url parameters. The data fetches gather data. However, the logging output is below:

2010-04-23 13:44:46,968 [http-8080-4] DEBUG ...SomeController 61 - Get Permit
2010-04-23 13:44:46,968 [http-8080-4] DEBUG ...SomeController 107 - Getting UnsubmittedCount
2010-04-23 13:44:46,984 [http-8080-4] DEBUG ...SomeController 61 - Get Permit
2010-04-23 13:44:47,031 [http-8080-4] DEBUG ...SomeController 133 - Fired Before Phase Summary: RENDER_RESPONSE(6)

日志表明在触发beforePhase之前有2次调用getPermit方法,而有1次调用getUnsubmittedCount.

The logs indicate 2 calls to the getPermit method and one to getUnsubmittedCount before the beforePhase is fired.

推荐答案

弄清楚了这一点.如果您的页面中混有JSTL,则这些方法可能/将在调用JSF方法之前触发.我有类似的方法:

Figured this out. If you have JSTL mixed into your page those methods may/will fire before the JSF methods are called. I had methods like:

<c:if test="${someController.logic == true}">
    <p>Some Text</p>
</c:if>

someController.logic调用在someController.beforePhase调用之前触发.

The someController.logic call was firing before the someController.beforePhase call.

我将上面的内容替换为

<h:outputText rendered="#{someController.logic == true}">
    <p>Some Text</p>
</h:outputText>

现在事情以正确的顺序发生.我还发现我的应用程序中的其他页面在将JSTL与JSF混合时具有奇怪的结果.因此,我现在正在从应用程序中删除JSTL.

Now things fire in the correct order. I also found other pages in my app that had strange results when mixing JSTL with JSF. So I am in the process of banishing the JSTL from the application now.

这篇关于触发前称为BEFORE的JSF getter方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆