来自托管 bean 的同步对话框调用 [英] Synchronous dialog invocation from managed bean

查看:17
本文介绍了来自托管 bean 的同步对话框调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法使用 PrimeFaces RequestContext 从托管 bean 调用 JSF 中定义的对话框,托管 bean 有一个表单,但是是同步的,这意味着托管 bean 等待其线程执行,直到用户提交表单?

Is there a way to use PrimeFaces RequestContext to call a dialog defined in the JSF from a managed bean, which has a form, but synchronously, meaning that the managed bean wait its thread execution until the user submits the form?

目前,我从托管 bean 成功调用了一个对话框,但调用是异步的,这意味着对话框弹出打开,但托管 bean 线程继续运行,无需等待用户通过对话框提供所需的附加数据.

Currently, I am successfully invoking a dialog from my managed bean but the call is asynchronous, meaning the dialog is popped open but the managed bean thread continues on without waiting for the user to supply the needed additional data via the dialog.

因此,在我的 JSF 中,我将对话框定义如下:

So, in my JSF, I have the dialog defined as follows:

<p:dialog header="My Dialog" widgetVar="myDialog" modal="false" height="100">
    <h:form>
        <h:outputLabel for="inputData" value="Input Data:"/>
        <p:inputText id="inputData" title="Input Data" 
                maxlength="16" required="true" ... >
        </p:inputText>
        <h:commandButton value="Submit"/>
    </h:form>
</p:dialog>  

在我的托管 bean 中,如果满足某些条件,我会有条件地调用对话框:

In my managed bean, I call the dialog conditionally if some criteria is met:

...
if(noteReqd) {
    RequestContext requestContext = RequestContext.getCurrentInstance();  
    requestContext.execute("PF('myDialog').show();");
    //here I want the managed bean to stop until the user supplies the extra data needed
    //but it just proceeds downstream without the data the user enters
}
...

相关:

托管bean提示覆盖额外数据

从托管 bean 调用 JavaScript 函数

推荐答案

不,这是不可能的.Primfaces 的 RequestContext 只能完成他的工作,然后 JSF 生命周期继续并将 javascript 信息(PF('myDialog').show();,例如,要做什么)发送回客户端(浏览器).

No it's not possible. The Primfaces's RequestContext can only do his job then the JSF lifecycle continues and sends the javascript information (PF('myDialog').show();, e.g., what to do) back to the client (browser).

解决方案是以某种方式改变你的逻辑.

A solution would be change your logic in some way.

  1. 用户提供了一些数据
  2. 检查数据是否足够
  3. 如果没有,请重新打开同一个表单(或另一个表单)
  4. 执行步骤 2 + 3,直到提供足够的数据
  5. 继续你的逻辑

这篇关于来自托管 bean 的同步对话框调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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