Re: Action not firing before defined PhaseId

Splash Forums PrettyFaces Users Action not firing before defined PhaseId Re: Action not firing before defined PhaseId

#21786

clemmonsm
Participant

What exactly do you mean with “components being in scope”?

For example, say I have a h:panelGroup component on the page item.jspx that is bound to a bean like so:

<h:panelGroup id="pgModels" binding="#{bean.pgModels}"/>

In my action method bean.loadItem, I attempt to dynamically add components, such as h:outputLabel or h:outputText, to the panel group pgModels.

When I call bean.loadItem as phaseEvent method from the JSPX view tag, the h:panelGroup object, pgModels, can be accessed successfully inside of bean.loadItem and I can add components to pgModels dynamically. Here is my code for this approach:

JSPX view tag:

<f:view beforePhase="#{bean.loadItem}">
...
</f:view>

Bean method:

public void loadItem(PhaseEvent phaseEvent) {
// code here
}

pretty-config:

<url-mapping id="item">
<pattern value="/category/#{item}/" />
<view-id value="/faces/pages/item.jspx" />
</url-mapping>

However, when I call loadItem using a url-mapping action, the h:panelGroup object, pgModels, is null inside loadItem. Here is my code for this configuration:

JSPX view tag:

<f:view>
...
</f:view>

Bean method:

public String loadItem() {
// code here
}

pretty-config:

<url-mapping id="item">
<pattern value="/category/#{item}/" />
<view-id value="/faces/pages/item.jspx" />
<action phaseId="RENDER_RESPONSE">#{bean.loadItem}</action>
</url-mapping>

The differing results are why I think the method is being called at different points of the lifecycle. I will add “Thread.dumpStack()” to see if I can get more info.

Yes, if a user defines a phaseId of RENDER RESPONSE the action should be called from within beforePhase()! However I think there may be exceptions to this rule. But only if FacesContext.responseComplete() is set (which is the case only in some special cases) or if dynaview is used.

What would the exceptions be? What would cause them? Where would one set FacesContext.responseComplete(), in the mapping action?