Ajax component updates before actionListener called?

China☆狼群 提交于 2019-12-25 04:05:08

问题


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::BackingBeanAconstructor. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!