首页 > 解决方案 > Can't redirect to other page when clicking a commandButton in dialog

问题描述

Hi guys I try to make a dialog, it's like when click submit the dialog will show up and if you click Ok it will redirect to other page but when I try click it its's doesnt work how to fixed it ??

this the code

<p:dialog modal="true" widgetVar="successDialog" header="Info"
                    closable="false" appendTo="@(body)">
                    <h:panelGrid columns="1" cellpadding="2">
                        <h:outputText value="Save data berhasil" />
                        <center>
                            <p:commandButton value="Ok"
                                action="/prpk_paperless/master_prpk.xhtml?faces-redirect=true"
                                onclick="PF('successDialog').hide()" immediate="true"/>
                        </center>
                    </h:panelGrid>
                </p:dialog> 



                <p:dialog modal="false" widgetVar="failedDialog" header="Info"
                    closable="false">
                    <h:panelGrid columns="1" cellpadding="2">
                        <h:outputText value="Save data failed" />
                        <center>
                            <p:commandButton value="Ok" action="#"
                                onclick="PF('failedDialog').hide()" />
                        </center>
                    </h:panelGrid>
                </p:dialog>

thank you..

标签: primefacesxhtml

解决方案


你可以试试:

实用程序.java:

public static void RedirectToURL( final String url ) {
  FacesContext FC = FacesContext.getCurrentInstance();
  try {
    FC.getExternalContext().redirect( url );
  } catch ( Exception e ) { /* do some useful */ }
  FC.responseComplete();
}

bean.java

public void function buttonOk() {
  RedirectToURL("/prpk_paperless/master_prpk.xhtml");
}

在 xhtml 中:

<p:commandButton value="Ok" actionListener="#{bean.buttonOk()}" onclick="PF('successDialog').hide()"/>

推荐阅读