简体   繁体   English

自定义PhaseListener在jsf 2中调用两次

[英]Custom PhaseListener called twice in jsf 2

I was working with the PhaseListener in JSF 2.0. 我正在使用JSF 2.0中的PhaseListener。 But it's methods are getting called twice every time. 但它的方法每次都被调用两次。

@Override
public void beforePhase(PhaseEvent arg0) {
    System.out.println("Start Phase "+arg0.getPhaseId()+" here the value "+ ++i +" object "+this);  
}

and output is like this 和输出是这样的

Start Phase RESTORE_VIEW 1 here the value 1 object com.phaseListener.MyPhaseListener@cc8c29
Start Phase RESTORE_VIEW 1 here the value 1 object com.phaseListener.MyPhaseListener@106054a

each time it is being called by two different objects. 每次被两个不同的对象调用。

Please let me know, why it is like so?? 请让我知道,为什么会这样?

In case this helps someone googling for this problem. 如果这有助于某人谷歌搜索此问题。

In my case, I moved from Glassfish 3 to Tomcat 7 and I noticed that my custom phase listener was being registered twice causing duplicated log entries. 在我的情况下,我从Glassfish 3移动到Tomcat 7,我注意到我的自定义阶段监听器被注册两次导致重复的日志条目。

In my web.xml I had a ConfigureListener which was required for Glassfish 3 but triggers a second registration on Tomcat 7: 在我的web.xml中,我有一个ConfigureListener,它是Glassfish 3所必需的,但会在Tomcat 7上触发第二次注册:

<listener>
    <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>

I simply removed this block and it resolved the issue. 我只是删除了这个块,它解决了这个问题。

It's because you've registered your phase listener twice in the JSF application. 这是因为你已经在JSF应用程序中两次注册了你的阶段监听器。 The "why" for that is in turn not constuctively answerable. 对此而言,“为什么”反过来又不具有建设性的责任。 If you're bothered about the same phase listener being registered twice, just remove the second registration. 如果您对同一个阶段监听器被注册两次感到困扰,只需删除第二个注册。

This problem appears if you are using Tomcat 7.0.4x. 如果您使用Tomcat 7.0.4x,则会出现此问题。 Try to downgrade Tomcat to at least 7.0.39 or below. 尝试将Tomcat降级到至少7.0.39或更低。 The problem is very likely to be be resolved. 问题很可能得到解决。 I still do not know the reason but it works. 我仍然不知道原因,但它的工作原理。 Hope it helps. 希望能帮助到你。

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

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