2013-04-30 24 views
5

我的p:對話框不斷加載,我只需要它出現一次。任何人都知道如何做到這一點?Primefaces p:對話框不斷重新打開

<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:

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; 
    } 

我已經一個customAuthenticationProvider返回 'ATIVACAO' 時,數據庫是空的,所以我需要打開這個對話框插入數據,但它不斷重新打開(關閉立即重新打開)。

+0

「on&on」是什麼意思?對話框加載頁面加載?它拒絕關閉?或者它關閉並立即重新打開?通常應該觸發對話的是什麼? – kolossus 2013-04-30 13:03:28

+0

嗨kolossus,它關閉立即重新打開。謝謝。 – Kyne 2013-04-30 13:06:04

+0

您需要在此處包含對話框的觸發器組件以用於上下文 – kolossus 2013-04-30 13:07:54

回答

3
  1. <h:body onload="dialogAtivacao.show();"/>轉化成當HTML的標籤<body>被加載時,顯示彈出<body>標記將在整個頁面重新加載視圖時重新加載

  2. 每次單擊該按鈕時都會觸發整頁刷新。

在一起,就成了,每次我點擊這個按鈕,重新加載整個頁面,並顯示對話框,結果

使用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僅被觸發一次

+1

非常感謝。問題解決了! – Kyne 2013-04-30 13:45:55

+0

與其使用'onLoad'函數並執行ajax解決方法,對話框的'visible'屬性應該具有與'rendered'屬性相同的表達式。然後,一旦「數據庫不再空」,他就可以完成整頁刷新而不必擔心彈出的對話框。 – Manuel 2013-04-30 13:47:07

+1

@Manuel,也可以工作,但它似乎是一個登錄頁面,我認爲OP希望在打開頁面時顯示對話框。使用'visible' attr將導致額外的驗證參數來檢查頁面加載是否是新鮮請求。無論哪一個工作。您可以發佈該實施 – kolossus 2013-04-30 13:49:46