问题
I am using PrimeFaces <p:dialog>
to launch a popup html page and <p:commandButton>
to close it:
This is what I do when Ok button is pressed:
<p:commandButton id="submitButton"
value="OK"
actionListener="#{MultiFileSelectMgmtBean.actionOk}"
update=":formID:fileTreeID"
oncomplete="dlg1.hide();"/>
Problem is that fileTreeID
is updated before action listener is done.
How do I force actionOk()
to be called first, and then fileTreeID
to be updated?
Edit:
The problem is that popup page B (BackingBeanB
) needs to calculate and save some values that parent page A loads and uses in its BackingBeanA::BackingBeanA
constructor. What happens is that parent page A is constructed before child page B calls its BackingBeanB::actionOk()
. The component that needs to be updated fileTreeID
is in page A, and depends on the values calculated in page A constructor, so it gets updated with old values, and not with new ones to be calculated in BackingBeanB::actionOk()
.
回答1:
Your beans are apparently in the request scope. Put the beans in the view scope instead.
@ManagedBean
@ViewScoped
public class BeanA {}
@ManagedBean
@ViewScoped
public class BeanB {}
This way the beans will live as long as you're interacting with the same view and not be reconstructed on every single HTTP request.
The update
is definitely not performed before the action is invoked. Possible construction of the backing beans is not necessarily performed during render response only. It can happen during restore view phase already.
来源:https://stackoverflow.com/questions/10317922/ajax-component-updates-before-actionlistener-called