H: commandButton action is called only once in two calls

I am using JSF 1.2 in my web application. In my test.xhtml page, I have a form containing commandButton:

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

In the java source, my bean looks like this:

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

When I show my test.xhtml page, the first time I click on my command button, the action gets called well. The page has been updated. Then I try to click on the command button and the action will not be called. It is like JSF Lifecycle goes directly to the RENDER_RESPONSE step without calling the INVOKE_APPLICATION phase.

The page refreshes, and then when I click, the action gets called well. Thus, the action is called once in two.

To try to understand, I 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());
}}

, , :

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

PhaseListener, , RESTORE_VIEW RENDER_RESPONSE .

- ? , ?

, , UIViewRoot . :

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.component.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

. , , UIViewRoot. , , ?

Sylvain.

+3
1
+1

All Articles