1
votes

I have this form with a panel grid and a dialog:

<h:form id="regiForm">
    <p:panelGrid>
        <p:row style="height:30%">           
            <p:column>
                <h:outputText/> 
            </p:column>     
            <p:column>
                <p:commandButton style="width:350px" type="submit" actionListener="#
                {regiBean.showDialog}" id="ajax" value="#{msg['regi_button']}" update="regiForm"   process="@this"/>
            </p:column>  
            <p:column>
            </p:column>  
        </p:row>  
    </p:panelGrid>
    <p:dialog id="dialog" header="#{msg['regi_dialog_header']}" widgetVar="myDialog"  position="center center" >  
        <h:outputText value="#{msg['regi_dialog']}" />  
    </p:dialog>
</h:form>

I would like to open the dialog from inside the action listener:

public void showDialog() {
    RequestContext.getCurrentInstance().execute("dialog.show()");
    RequestContext.getCurrentInstance().execute("myDialog.show()");
}

However, the dialog is not shown. How is this caused and how can I solve it?

I'm using JSF 2.1 and PrimeFaces 3.5.

1
are you sure your method is correctly call ? cause this is the correct way to display dialog from bean. RequestContext.getCurrentInstance().execute("widgetVar.show()"); You got js or ajax error ?Joffrey Hernandez

1 Answers

3
votes

The first statement with the command

RequestContext.getCurrentInstance().execute("dialog.show()");

won't work because dialog refers to the XHTML ID of the p:dialog component. This will cause an javascript error. And that could be the reason why the second command

RequestContext.getCurrentInstance().execute("myDialog.show()");

won't get executed. Also I would add ; to the end of each Javascript command (but this is just my personal style)