简体   繁体   English

Diplay a <p:confirmDialog> 来自javascript

[英]Diplay a <p:confirmDialog> from javascript

I need to display a p:confirmDialog from the JavaScript. 我需要从JavaScript中显示一个p:confirmDialog

I've tried: 我试过了:

<p:confirmDialog id="users"  widgetVar="UsersWidget" severity="alert" closable="false">

    <h:outputText value="Please specify the UserID of the contractor to whom a mail need to be sent"></h:outputText>
    <h:inputText></h:inputText>
    <p:commandButton id="OK" value="add"></p:commandButton>
    <p:commandButton style="font-size:1.1em;" id="Cancel" 
        value="cancel" action="#{Bean.Report}"   >
    </p:commandButton>

</p:confirmDialog>

<f:selectItem itemLabel="Select One" itemValue="" />
<f:selectItems value="#{Bean.usersList}"/>
<f:selectItem itemLabel="Other" itemValue="Other" />
<p:ajax listener="check()" />

My Javascript 我的Javascript

<h:head>
<script language="javascript">
    function check() {
        alert("Entered");
        RequestContext.getCurrentInstance().execute("UsersWidget.show()");
        alert("Working!!");
    }
</script>
</h:head>

i can see the alert entered byt i cannot see the conform dialog and the working alert 我可以看到由我输入的警报我看不到符合对话框和工作警报

You are mixing Java and JavaScript. 您正在混合使用Java和JavaScript。

In your JavaScript, you simply need to do this: 在您的JavaScript中,您只需要这样做:

<script language="javascript">
    function check() {
        alert("Entered");
        UsersWidget.show();
        alert("Working!!");
    }
</script>

UsersWidget corresponds to the name you set in the attribute widgetVar of the p:confirmDialog . UsersWidget对应于您在p:confirmDialog的属性widgetVar中设置的名称。

If you want to show the dialog after a call to a backing bean, you can call this in your Java code (backing bean): 如果要在调用支持bean之后显示对话框,可以在Java代码(支持bean)中调用它:

public void myJavaMethod() {
    RequestContext.getCurrentInstance().execute("UsersWidget.show()");
}

As soon as the request returned, the dialog will be shown. 一旦请求返回,将显示该对话框。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM