开发者

h:commandButton action is just called one time on two calls

I use JSF 1.2 on my web application. In my page test.xhtml, I have a form containing a commandButton like that :

<h:form>
  <h:commandButton action="#{myBean.myMethod}" value="Call my method" />
</h:form>

In java source, my bean is like that :

public class MyBean {
  public void myMethod() {
    System.out.println("my method called");
  }
}

When I display my page test.xhtml, the first time I click on my command button the action is well invoked. The page is refreshed. Then, I try to click on the command button and the action is not invoked. It's like if JSF Lifecycle goes to RENDER_RESPONSE phase directly without invoking INVOKE_APPLICATION phase.

The page is refreshed and then when I click, the action is well invoked. So, the action is invoked one time on two.

To try to understand, I have added a phase listener very simply :

public class MyPhaseListener implements PhaseListener{

public PhaseId getPhaseId() {
    return PhaseId.ANY_PHASE;
}

public void beforePhase(PhaseEvent event) {
    System.out.println("START PHASE " + event.getPhaseId());
}

public void afterPhase(PhaseEvent event) {
    System.out.println("END PHASE " + event.getPhaseId());
}}

When i run tests click on my page, I have the following output :

START PHASE RESTORE_VIEW 1
END PHASE RESTORE_VIEW 1
START PHASE APPLY_REQUEST_VALUES 2
END PHASE APPLY_REQUEST_VALUES 2
START PHASE PROCESS_VALIDATIONS 3
END PHASE PROCESS_VALIDATIONS 3
START PHASE UPDATE_MODEL_VALUES 4
END PHASE UPDATE_MODEL_VALUES 4
START PHASE INVOKE_APPLICATION 5
my method called
END PHASE INVOKE_APPLICATION 5
START PHASE RENDER_RESPONSE 6
END PHASE RENDER_RESPONSE 6

START PHASE RESTORE_VIEW 1
END PHASE RESTORE_VIEW 1
START PHASE RENDER_RESPONSE 6
END PHASE RENDER_RESPONSE 6

START PHASE RESTORE_VIEW 1
END PHASE RESTORE_VIEW 1
START PHASE APPLY_REQUEST_VALUES 2
END PHASE APPLY_REQUEST_VALUES 2
START PHASE PROCESS_VALIDATIONS 3
END PHASE PROCESS_VALIDATIONS 3
START PHASE UPDATE_MODEL_VALUES 4
END PHASE UPDATE_MODEL_VALUES 4
START PHASE INVOKE_APPLICATION 5
my method called
END PHASE INVOKE_APPLICATION 5
START PHASE RENDER_RESPONSE 6
END PHASE RENDER_RESPONSE 6

START PHASE RESTORE_VIEW 1
END PHASE RESTORE_VIEW 1
START PHASE RENDER_RESPONSE 6
END PHASE RENDER_RESPONSE 6

By using PhaseListener, I see clearly that in the second call at each time the lifecycle goes to RESTORE_VIEW phase to RENDER_RESPONSE directly without action of my part on the lifecycle.

Someone would have and idea to avoid that and execute the lifecycle at each time for that page ? Or a solution to have action executed each time I click on the command button ?

Like you told me, I add some debug informations on the prints like the UIViewRoot object and the session ID. The sequence of action give the following informations now :

START PHASE RESTORE_VIEW 1
UIViewRoot :null
Session ID : 8385AC329B4C75AB4FBCA2CE1FBDFDC7
END PHASE RESTORE_VIEW 1
UIViewRoot :javax.faces.component.UIViewRoot@7cbcb4
Session ID : 8385AC329B4C75AB4FBCA2CE1FBDFDC7
START PHASE APPLY_REQUEST_VALUES 2
UIViewRoot :javax.faces.component.UIViewRoot@7cbcb4
Session ID : 8385AC329B4C75AB4FBCA2CE1FBDFDC7
END PHASE APPLY_REQUEST_VALUES 2
UIViewRoot :javax.faces.component.UIViewRoot@7cbcb4
Session ID : 8385AC329B4C75AB4FBCA2CE1FBDFDC7
START PHASE PROCESS_VALIDATIONS 3
UIViewRoot :javax.faces.component.UIViewRoot@7cbcb4
Session ID : 8385AC329B4C75AB4FBCA2CE1FBDFDC7
END PHASE PROCESS_VALIDATIONS 3
UIViewRoot :javax.faces.component.UIViewRoot@7cbcb4
Session ID : 8385AC329B4C75AB4FBCA2CE1FBDFDC7
START PHASE UPDATE_MODEL_VALUES 4
UIViewRoot :javax.faces.component.UIViewRoot@7cbcb4
Session ID : 8385AC329B4C75AB4FBCA2CE1FBDFDC7
END PHASE UPDATE_MODEL_VALUES 4
UIViewRoot :javax.faces.component.UIViewRoot@7cbcb4
Session ID : 8385AC329B4C75AB4FBCA2CE1FBDFDC7
START PHASE INVOKE_APPLICATION 5
UIViewRoot :javax.faces.component.UIViewRoot@7cbcb4
Session ID : 8385AC329B4C75AB4FBCA2CE1FBDFDC7
my method called
END PHASE INVOKE_APPLICATION 5
UIViewRoot :javax.faces.component.UIViewRoot@7cbcb4
Session ID : 8385AC329B4C75AB4FBCA2CE1FBDFDC7
START PHASE RENDER_RESPONSE 6
UIViewRoot :javax.faces.component.UIViewRoot@7cbcb4
Session ID : 8385AC329B4C75AB4FBCA2CE1FBDFDC7
END PHASE RENDER_RESPONSE 6
UIViewRoot :javax.faces.component.UIViewRoot@7cbcb4
Session ID : 8385AC329B4C75AB4FBCA2CE1FBDFDC7


START PHASE RESTORE_VIEW 1
UIViewRoot :null
Session ID : 8385AC329B4C75AB4FBCA2CE1FBDFDC7
END PHASE RESTORE_VIEW 1
UIViewRoot :javax.faces.component.UIViewRoot@7cbaea
Session ID : 8385AC329B4C75AB4FBCA2CE1FBDFDC7
START PHASE RENDER_RESPONSE 6
UIViewRoot :javax.faces.component.UIViewRoot@7cbaea
Session ID : 8385AC329B4C75AB4FBCA2CE1FBDFDC7
END PHASE RENDER_RESPONSE 6
UIViewRoot :javax.faces.component.UIViewRoot@7cbaea
Session ID : 8385AC329B4C75AB4FBCA2CE1FBDFDC7


START PHASE RESTORE_VIEW 1
UIViewRoot :null
Session ID : 8385AC329B4C75AB4FBCA2CE1FBDFDC7
END PHASE RESTORE_VIEW 1
UIViewRoot :javax.faces.component.UIViewRoot@7ccfa1
Session ID : 8385AC329B4C75AB4FBCA2CE1FBDFDC7
START PHASE APPLY_REQUEST_VALUES 2
UIViewRoot :javax.faces.componen开发者_StackOverflowt.UIViewRoot@7ccfa1
Session ID : 8385AC329B4C75AB4FBCA2CE1FBDFDC7
END PHASE APPLY_REQUEST_VALUES 2
UIViewRoot :javax.faces.component.UIViewRoot@7ccfa1
Session ID : 8385AC329B4C75AB4FBCA2CE1FBDFDC7
START PHASE PROCESS_VALIDATIONS 3
UIViewRoot :javax.faces.component.UIViewRoot@7ccfa1
Session ID : 8385AC329B4C75AB4FBCA2CE1FBDFDC7
END PHASE PROCESS_VALIDATIONS 3
UIViewRoot :javax.faces.component.UIViewRoot@7ccfa1
Session ID : 8385AC329B4C75AB4FBCA2CE1FBDFDC7
START PHASE UPDATE_MODEL_VALUES 4
UIViewRoot :javax.faces.component.UIViewRoot@7ccfa1
Session ID : 8385AC329B4C75AB4FBCA2CE1FBDFDC7
END PHASE UPDATE_MODEL_VALUES 4
UIViewRoot :javax.faces.component.UIViewRoot@7ccfa1
Session ID : 8385AC329B4C75AB4FBCA2CE1FBDFDC7
START PHASE INVOKE_APPLICATION 5
UIViewRoot :javax.faces.component.UIViewRoot@7ccfa1
Session ID : 8385AC329B4C75AB4FBCA2CE1FBDFDC7
my method called
END PHASE INVOKE_APPLICATION 5
UIViewRoot :javax.faces.component.UIViewRoot@7ccfa1
Session ID : 8385AC329B4C75AB4FBCA2CE1FBDFDC7
START PHASE RENDER_RESPONSE 6
UIViewRoot :javax.faces.component.UIViewRoot@7ccfa1
Session ID : 8385AC329B4C75AB4FBCA2CE1FBDFDC7
END PHASE RENDER_RESPONSE 6
UIViewRoot :javax.faces.component.UIViewRoot@7ccfa1
Session ID : 8385AC329B4C75AB4FBCA2CE1FBDFDC7


START PHASE RESTORE_VIEW 1
UIViewRoot :null
Session ID : 8385AC329B4C75AB4FBCA2CE1FBDFDC7
END PHASE RESTORE_VIEW 1
UIViewRoot :javax.faces.component.UIViewRoot@7cac2f
Session ID : 8385AC329B4C75AB4FBCA2CE1FBDFDC7
START PHASE RENDER_RESPONSE 6
UIViewRoot :javax.faces.component.UIViewRoot@7cac2f
Session ID : 8385AC329B4C75AB4FBCA2CE1FBDFDC7
END PHASE RENDER_RESPONSE 6
UIViewRoot :javax.faces.component.UIViewRoot@7cac2f
Session ID : 8385AC329B4C75AB4FBCA2CE1FBDFDC7

The session is always the same between each sequence of call. So, I don't think this is a problem of UIViewRoot. Are there other things that I can do to test the problem ?

Sylvain.


If you haven't read this blog article you should: http://balusc.blogspot.com/2006/09/debug-jsf-lifecycle.html

It looks like you be losing your session as the UIViewRoot doesn't exist and thus there is no UIViewRoot to restore.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜