1

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.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
bvb1909
  • 191
  • 2
  • 6
  • 19
  • 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 Nov 20 '13 at 13:11

1 Answers1

3

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)

Manuel
  • 3,828
  • 6
  • 33
  • 48
  • You're welcome. Accept it if the answer helpd you. So other people with the same problem can find the solution easier. – Manuel Nov 23 '13 at 06:07