Help: Backing bean doAction method not getting invoked
Hi,
My dev env is as follows:
Rational Software Architect, portlet jsr 168 api, jsf 1.0, Websphere Portal server 5.1.
I am running into a weird problem. I have a simple jsf fragment having a selectOneList box and a commandButton. When I click command button, the corresponding doAction method is not getting invoked. I have put some SOP statements in processAction and doView of the portlet . These stmts get printed on console but the SOP in doAction (which is in backing bean) is not getting printed.
But when I refresh the page, I get the SOP from doAction getting printed on cosole.
I am not sure why. Any help is appreciated.
Thx
an Action method may not be called for one of the following reasons (maybe more, these are common for me):
1) validation failed
2) rendered flag is false on the component or the component it is contained in.
3) I fat-fingered the action expression - like forgetting a '}'
Regarding Select Validation...
For a Select component, the selectItems that the component was rendered with must be the same selectItems that can be retireved in the Validation Phase. The Validation phase is one of the first phases, before request values are set, and before any non-immediate action.
I found adding a Phase Listener with debug logging has helped enourmously with seeing when getter and setters were called in which phase.
public class DebugPhaseListener implements PhaseListener {
private static final Log LOGGER = LogFactory.getLog(DebugPhaseListener.class);
public PhaseId getPhaseId() {
return PhaseId.ANY_PHASE;
}
public void beforePhase(PhaseEvent event) {
LOGGER.debug("beforePhase(" + event.getPhaseId() + ")");
}
public void afterPhase(PhaseEvent event) {
LOGGER.debug("afterPhase(" + event.getPhaseId() + ")");
}
}
in your faces-config.xml... add
<lifecycle>
<phase-listener>com.mycompany.DebugPhaseListener</phase-listener>
</lifecycle>
Having a phase listener was a nice idea.
From the trace what I could gather was:
After UPDATE_MODEL_VALUES phase, it is skipping INVOKE_APPLICATION phase. But when I refresh the page, it is calling INVOKE_APPLICATION phase. As if it hase queued execution of this phase for a refresh.
No clue what so ever regarding why it is happening. Especially when I am using <h:selectOneListbox> tag.
Any ideas?
The Invoke application phase is skipped when there is a validation issue.
Make sure the values of the select item on the first render are the same values that can be populated when the page is submitted.
<RANT>
IMO: This is ANOTHER design flaw in JSF. Say you have to goto the database to get the list of items to populate a SelectItem list. First Off... on the submission of a form, I only care about the items that were selected from the menu, and not the entire list. Second... what happens when the values in the DB are updated between the first render and the submission of the form? Seems like JSF would say there was a validation issue if say the 100th item was removed, when I had selected the 5th item - a totally valid selection. ARG. ..... sheeesh... really, I'm ok now.
</RANT>