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

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

问题描述

有没有办法使用PrimeFaces RequestContext 来调用JSF中定义的对话框,该对话框具有一种形式,但同步地表示该托管bean等待线程执行直到用户提交表单?



目前,我已经成功地从我的托管bean调用了一个对话框,但调用是异步的,意味着弹出对话框但是管理的bean线程继续进行,而不用等待用户通过对话框提供所需的附加数据。



所以,在我的JSF中,我有如下定义的对话框:

 < p:dialog header =我的对话框widgetVar =myDialogmodal =falseheight =100 > 
< h:form>
< h:outputLabel for =inputDatavalue =Input Data:/>
< p:inputText id =inputDatatitle =Input Data
maxlength =16required =true...>
< / p:inputText>
< h:commandButton value =提交/>
< / h:form>
< / p:dialog>

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

  ... 
if(noteReqd){
RequestContext requestContext = RequestContext.getCurrentInstance();
requestContext.execute(PF('myDialog')。show(););
//这里我希望托管bean停止,直到用户提供所需的额外数据
//但它只是在下游没有用户输入的数据
}
..

相关:



管理bean提供额外数据覆盖



调用javascript管理Bean的功能

解决方案

不可以。 Primfaces的RequestContext只能执行他的工作,然后JSF生命周期继续下去并发送javascript信息( PF('myDialog')。show(); ,例如,该怎么做)回到客户端(浏览器)。



解决方案会以某种方式改变您的逻辑。


  1. 用户提供一些数据

  2. 检查数据是否足够

  3. 如果没有,重新打开相同的表单(或另一个)

  4. 执行步骤2 + 3,直到提供足够的数据

  5. 继续使用逻辑


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?

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.

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>  

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

RELATED:

Prompting overlay for extra data by managed bean

Calling a javascript function from Managed Bean

解决方案

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. user supplies some data
  2. check if data was enough
  3. if not, reopen the same form (or another one)
  4. do step 2 + 3 until enough data is supplied
  5. continue with your logic

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

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