我将一个简单的 jsf 生命周期监听器连接到我的 webbapp:
public class LifeCycleListener implements PhaseListener
{
@Override
public PhaseId getPhaseId() {
return PhaseId.ANY_PHASE;
}
@Override
public void beforePhase(PhaseEvent event) {
System.out.println("START PHASE " + event.getPhaseId());
}
@Override
public void afterPhase(PhaseEvent event) {
System.out.println("END PHASE " + event.getPhaseId());
}
}
在其中一页上,我有这样的东西:
<h:form>
<h:commandLink id="avdertAddedToMainPage" action="#{topView.showMainPage}">
Main Page
</h:commandLink>
</h:form>
其中 topView 是在 faces-config 中配置为请求范围的简单 bean:
public class TopView {
public TopView() {
}
public String showAddAdvert()
{
return "addAdvert";
}
public String showMainPage()
{
return "itemList";
}
}
让我感到奇怪的是,如果我点击上面的链接,一切似乎都可以正常工作,但根据 LiceCycleListener 的输出,每个阶段在页面加载之前运行了 2 次(昨天我数了 4 次,但这是因为线程问题)向上。这是正常行为吗?如果这表明我的代码中存在某种错误,我应该在哪里寻找它?
我在 Glassfish 3.0.1 上使用 Mojarra 2.0.2
这是我今天尝试的输出。生命周期只有两轮,但昨天我有 4 轮。当我查看昨天的日志时,我发现我有多个线程,所以我猜这与在服务器运行时修改我的应用程序有关。但我仍然不知道 2 轮生命周期是否是一件好事。另请注意,关于设置字符编码的警告很少,但我不知道这是否重要。
FINE: [Web-Security] Policy Context ID was: Powypadkowe/Powypadkowe
FINE: [Web-Security] hasUserDataPermission perm: (javax.security.jacc.WebUserDataPermission /faces/AdvertAddedCl.xhtml POST)
FINE: [Web-Security] hasUserDataPermission isGranted: true
FINE: [Web-Security] Policy Context ID was: Powypadkowe/Powypadkowe
FINE: [Web-Security] hasResource isGranted: true
FINE: [Web-Security] hasResource perm: (javax.security.jacc.WebResourcePermission /faces/AdvertAddedCl.xhtml POST)
WARNING: PWC4011: Unable to set request character encoding to UTF-8 from context /powypadkowe, because request parameters have already been read, or ServletRequest.getReader() has already been called
WARNING: PWC4011: Unable to set request character encoding to UTF-8 from context /powypadkowe, because request parameters have already been read, or ServletRequest.getReader() has already been called
INFO: START PHASE RESTORE_VIEW 1
INFO: END PHASE RESTORE_VIEW 1
INFO: START PHASE APPLY_REQUEST_VALUES 2
INFO: END PHASE APPLY_REQUEST_VALUES 2
INFO: START PHASE PROCESS_VALIDATIONS 3
INFO: END PHASE PROCESS_VALIDATIONS 3
INFO: START PHASE UPDATE_MODEL_VALUES 4
INFO: END PHASE UPDATE_MODEL_VALUES 4
INFO: START PHASE INVOKE_APPLICATION 5
INFO: END PHASE INVOKE_APPLICATION 5
INFO: START PHASE RENDER_RESPONSE 6
INFO: ------- some hibernate sql selects -------
INFO: END PHASE RENDER_RESPONSE 6
FINE: SecurityContext: setCurrentSecurityContext method called
FINE: [Web-Security] Policy Context ID was: Powypadkowe/Powypadkowe
FINE: [Web-Security] hasUserDataPermission perm: (javax.security.jacc.WebUserDataPermission /faces/photos/nowy17@mail.pl/Atojest/item_1/1m.jpg GET)
FINE: [Web-Security] hasUserDataPermission isGranted: true
FINE: [Web-Security] Policy Context ID was: Powypadkowe/Powypadkowe
FINE: [Web-Security] hasResource isGranted: true
FINE: [Web-Security] hasResource perm: (javax.security.jacc.WebResourcePermission /faces/photos/nowy17@mail.pl/Atojest/item_1/1m.jpg GET)
WARNING: PWC4011: Unable to set request character encoding to UTF-8 from context /powypadkowe, because request parameters have already been read, or ServletRequest.getReader() has already been called
WARNING: PWC4011: Unable to set request character encoding to UTF-8 from context /powypadkowe, because request parameters have already been read, or ServletRequest.getReader() has already been called
INFO: START PHASE RESTORE_VIEW 1
INFO: END PHASE RESTORE_VIEW 1
INFO: START PHASE APPLY_REQUEST_VALUES 2
INFO: END PHASE APPLY_REQUEST_VALUES 2
INFO: START PHASE PROCESS_VALIDATIONS 3
INFO: END PHASE PROCESS_VALIDATIONS 3
INFO: START PHASE UPDATE_MODEL_VALUES 4
INFO: END PHASE UPDATE_MODEL_VALUES 4
INFO: START PHASE INVOKE_APPLICATION 5
INFO: END PHASE INVOKE_APPLICATION 5
INFO: START PHASE RENDER_RESPONSE 6
INFO: END PHASE RENDER_RESPONSE 6
FINE: SecurityContext: setCurrentSecurityContext method called
还有昨天的日志片段:
[#|2012-06-04T22:05:49.158+0200|INFO|glassfish3.0.1|javax.enterprise.system.std.com.sun.enterprise.v3.services.impl|_ThreadID=30;_ThreadName=Thread-1;|END PHASE UPDATE_MODEL_VALUES 4|#]
[#|2012-06-04T22:05:49.158+0200|INFO|glassfish3.0.1|javax.enterprise.system.std.com.sun.enterprise.v3.services.impl|_ThreadID=33;_ThreadName=Thread-1;|START PHASE RESTORE_VIEW 1|#]
[#|2012-06-04T22:05:49.161+0200|INFO|glassfish3.0.1|javax.enterprise.system.std.com.sun.enterprise.v3.services.impl|_ThreadID=31;_ThreadName=Thread-1;|START PHASE RENDER_RESPONSE 6|#]
[#|2012-06-04T22:05:49.162+0200|INFO|glassfish3.0.1|javax.enterprise.system.std.com.sun.enterprise.v3.services.impl|_ThreadID=33;_ThreadName=Thread-1;|END PHASE RESTORE_VIEW 1|#]
[#|2012-06-04T22:05:49.163+0200|INFO|glassfish3.0.1|javax.enterprise.system.std.com.sun.enterprise.v3.services.impl|_ThreadID=33;_ThreadName=Thread-1;|START PHASE APPLY_REQUEST_VALUES 2|#]
[#|2012-06-04T22:05:49.261+0200|INFO|glassfish3.0.1|javax.enterprise.system.std.com.sun.enterprise.v3.services.impl|_ThreadID=32;_ThreadName=Thread-1;|START PHASE APPLY_REQUEST_VALUES 2|#]
[#|2012-06-04T22:05:49.261+0200|INFO|glassfish3.0.1|javax.enterprise.system.std.com.sun.enterprise.v3.services.impl|_ThreadID=33;_ThreadName=Thread-1;|END PHASE APPLY_REQUEST_VALUES 2|#]