Reputation: 65
I have the need to execute three actions one another from my backing bean but the second and third ones seems to be fired before the first one finish executing.
The result is that the second/third action is called but not executed.
How do I manage to execute the first action, wait until if finishes and than start the second/third action?
Actions are
RequestContext.getCurrentInstance().execute("PF('dlgConfirmApplicationDelete').hide();");
h:panelGroup
componentRequestContext.getCurrentInstance().update("j_idt3:panelGroupHolder");
h:panelGroup
component RequestContext.getCurrentInstance().update("j_idt3:center_westBody");
Upvotes: 2
Views: 2405
Reputation: 20899
I need to perform an action in the database and depending on the result I need to close the window and right after update the other two panelGroups with the updated information
You could do this without calling actions from java code.
Without knowing your exact layout, the task you are asking for would usually look like this:
<p:commandLink
process="@form"
actionListener="#{bean1.updateDatabase}"
update="j_idt3:panelGroupHolde;j_idt3:center_westBody"
oncomplete="if (args.updateSuccessfull) PF('dlgConfirmApplicationDelete').hide();">
and inside your bean1.updateDatabase
method, you specify args.updateSuccessfull
depending on the actual result of the query.
Boolean updateSuccessfull = false;
RequestContext.getCurrentInstance().addCallbackParam("updateSuccessfull", updateSuccessfull);
In the example you mentioned the order is not important, as each action will have it's predetermined outcome and is dedicated to a certain phase in the life-cycle (update always comes before oncomplete):
update=
has no impact and the dialog stays visible due to the CallBack-Param. If this is not the case, then you have code inside the RenderResponse
-Phase, which should rather be executed in the InvokeApplication
-Phase (or earlier).
A common misstake causing the later is to call "methods containing heavy code" from the xhtml (while other listings ("second update") depend on that values as well), like
<ui:repeat values="#{bean1.queryDatabaseForXY()}" ...>
Obviously now the SECOND update needs to come after the first update, cause it also requires some data from bean1.queryDatabaseForXY()
.
Rather than that you should perform data loading and/or calculations in the proper phase and simply refer to a getter
returning an already known collection when generating the response:
<ui:repeat values="#{bean1.getUsers()}" ...>
or more precicesly
<ui:repeat values="#{bean1.users}" ...>
(The actual loading would be either @PostConstruct
, an <f:viewAction>
or just the already existing list inside a view- or session-scoped bean)
Upvotes: 3