nrupen
nrupen

Reputation: 65

Diplay a <p:confirmDialog> from javascript

I need to display a p:confirmDialog from the JavaScript.

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

<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

Upvotes: 0

Views: 2111

Answers (1)

LaurentG
LaurentG

Reputation: 11757

You are mixing Java and JavaScript.

In your JavaScript, you simply need to do this:

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

If you want to show the dialog after a call to a backing bean, you can call this in your Java code (backing bean):

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

As soon as the request returned, the dialog will be shown.

Upvotes: 2

Related Questions