Ajax组件在actionListener调用之前更新? [英] Ajax component updates before actionListener called?

查看:121
本文介绍了Ajax组件在actionListener调用之前更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PrimeFaces < p:dialog> 启动一个弹出HTML页面,并使用< p:commandButton> 将其关闭:

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();"/>

问题在于 fileTreeID 在操作之前已更新侦听器完成。
如何强制先调用 actionOk(),然后再更新 fileTreeID

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?

编辑

问题是弹出页面B( BackingBeanB )需要计算并保存父页面A在其 BackingBeanA :: BackingBeanA 构造函数中加载和使用的某些值。发生的情况是在子页面B之前 构造父页面A,调用其 BackingBeanB :: actionOk()。需要更新 fileTreeID 的组件位于页面A中,并且取决于页面A构造函数中计算的值,因此将使用旧值(而不是新值)进行更新。在 BackingBeanB :: actionOk()中进行计算。

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().

推荐答案

您的bean显然在请求范围内。

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 {}

这样,bean可以生存很长时间

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.

更新是绝对不会在调用该操作之前 执行。仅在渲染响应期间不一定执行后备bean的可能构造。它可能已经在还原视图阶段发生。

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.

这篇关于Ajax组件在actionListener调用之前更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆