6

私の p:dialog はロードし続けます。一度だけ表示する必要があります。誰でもそれを行う方法を知っていますか?

    <h:body style="background: url('img/background/teste/brushed_alu.png')!important" onload="dialogAtivacao.show();">
    <script type="text/javascript">
    $(document).ready(function() {
        document.getElementById("j_username").focus();
    });
    </script>

    <p:dialog id="dialogAtivar" header="Ativação de empresa"  showEffect="drop" hideEffect="drop" resizable="false"
              widgetVar="dialogAtivacao" modal="true" closable="true" rendered="#{sessionScope['SPRING_SECURITY_LAST_EXCEPTION'].message == 'ATIVACAO'}">
        <ui:include src="pages/ativacao/AtivacaoEmpresa.xhtml"/>
    </p:dialog>
    ...

ボタン:

  <p:panel  styleClass="panelBotaoLogin" >
        <h:commandButton id="saveButton" action="#{login.doLogin()}" value="  Entrar" styleClass="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only botaoEntrar"/>
  </p:panel>

LoginBean の login() :

    public String doLogin() throws IOException, ServletException {
           ExternalContext context =  FacesContext.getCurrentInstance().getExternalContext();
           RequestDispatcher dispatcher = ((ServletRequest) context.getRequest()).getRequestDispatcher("/j_spring_security_check?j_username=" + username + "&j_password=" + password);
           dispatcher.forward((ServletRequest) context.getRequest(), (ServletResponse) context.getResponse());
           FacesContext.getCurrentInstance().responseComplete();

           return null;
     }

データベースが空のときに「ATIVACAO」を返す customAuthenticationProvider が 1 つあるため、このダイアログを開いてデータを挿入する必要がありますが、再開し続けます (閉じてすぐに再開します)。

4

1 に答える 1

3
  1. <h:body onload="dialogAtivacao.show();"/>HTMLのタグが読み込まれたときに<body>変換され、 popup が表示されます<body>ビューのページ全体のリロードが行われると、タグがリロードされます

  2. <h:commandButton id="saveButton" action="#{login.doLogin()}" value=" Entrar" styleClass="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only botaoEntrar"/>ボタンがクリックされるたびに、ページ全体の更新がトリガーされます。

一緒に、このボタンをクリックするたびに、ページ全体をリロードし、結果としてダイアログを表示します

代わりに ajax コマンド コンポーネントを使用します。

 <p:commandButton id="saveButton" action="#{login.doLogin}" value="  Entrar" styleClass="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only botaoEntrar"/>

このようにして、ajax リクエストがトリガーされ、onload一度だけトリガーされます

于 2013-04-30T13:37:31.403 に答える