【问题标题】:Synchronous dialog invocation from managed bean来自托管 bean 的同步对话框调用
【发布时间】:2015-07-02 22:34:10
【问题描述】:

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

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

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

<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 中,如果满足某些条件,我会有条件地调用对话框:

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

相关:

Prompting overlay for extra data by managed bean

Calling a JavaScript function from managed bean

【问题讨论】:

    标签: jsf primefaces dialog requestcontext


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2015-05-08
      • 2011-06-08
      • 1970-01-01
      • 2011-11-02
      • 2011-12-23
      • 2011-06-22
      • 2015-11-19
      • 1970-01-01
      • 2013-06-29
      相关资源
      最近更新 更多