JSF:Primefaces: Cannot open Dialog from Bean using RequestContext

Johnny2012 picture Johnny2012 · Feb 5, 2013 · Viewed 11.7k times · Source

I am not able to open Dialog from my Bean. I have also tried actionListener instead of action

This is how my JSF looks like:

<ui:composition template="../templates/site.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:sec="http://www.springframework.org/security/tags">
<!-- remove me just for encoding check ä -->
<ui:define name="content">
    <h:form id="form">
        <h:panelGrid columns="1" cellpadding="5">

            <p:commandButton value="Button" type="button" id="myButton"
                action="#{testBean.showDialog}" />
        </h:panelGrid>
    </h:form>



    <p:dialog id="testDialog" widgetVar="testDialog2"
        header="My Test Dialog" modal="true" appendToBody="true">
        <h:form>

            <h:outputText value="Output" />

        </h:form>
    </p:dialog>


</ui:define>

And this is my Bean

@Component
@Scope("view")
public class TestBean {

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


}

Answer

partlov picture partlov · Feb 5, 2013

Your showDialog() method is not called at all. Remove type="button" as you want to use AJAX enable submit, not push button.