2012-01-30 21 views
5

我有一個頁面模式對話框,在用戶單擊編輯按鈕時呈現。該對話框要求輸入用戶名和密碼,並有一個提交按鈕。如果用戶名和密碼未驗證,則顯示錯誤。當對話框中的操作失敗時,Primefaces對話框背景不透明度會加倍

問題是,如果用戶名和密碼沒有進行身份驗證,每次驗證失敗時,模式背景會越來越暗。

會導致什麼?

<p:dialog id="dialog" header="Login To Edit" widgetVar="dialog" visible="#{fundingBacker.loginVisible}" modal="true" 
    resizable="false" closable="false" draggable="true" rendered="#{!userBean.loggedIn}"> 
    <h:form> 

     <p:ajaxStatus style="width:16px;height:16px;"> 
      <f:facet name="start"> 
       <p:graphicImage value="../images/loading4.gif" /> 
      </f:facet> 
      <f:facet name="complete"> 
       <h:outputText value="" /> 
      </f:facet> 
     </p:ajaxStatus> 

     <p:messages autoUpdate="true" showDetail="true" /> 

     <h:panelGrid columns="2" cellpadding="5"> 

      <h:outputLabel for="lanId" value="LanID:" /> 
      <p:inputText value="#{currentUser.lanID}" id="lanId" required="true" label="lanId" requiredMessage="Lan ID is required" /> 

      <h:outputLabel for="password" value="Password:" /> 
      <p:password value="#{currentUser.password}" id="password" required="true" label="password" feedback="false" requiredMessage="Password is required" /> 

      <p:commandButton id="loginButton" value="Login" type="submit" styleClass="primaryButton" action="#{currentUser.performLogin}" update="dialog"/> 

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

回答

3

您正在更新對話框而沒有先關閉它。我不確定它是一個錯誤還是一個功能,但是由於visible屬性,覆蓋層會在每次對話框更新時重新初始化。您可能希望將其報告給PrimeFaces人員以及更緊湊的測試用例。

最簡單的解決方案是關閉ajax成功的對話框。它會以比最終用戶眨眼睛更快的速度重新顯示。

<p:commandButton ... onsuccess="dialog.hide()" update="dialog" /> 

你可能只需要微調的visiblerendered屬性,以確保當驗證失敗的對話框重新打開(例如,若仍不能登錄的用戶)。

另一種方法是更新對話框的形式而不是對話框本身。

<p:commandButton ... update="@form" /> 

或者只是完全刪除該屬性。它已經默認爲@form

<p:commandButton ... /> 

成功登錄後關閉對話框可以通過RequestContext#execute()完成。

RequestContext.getCurrentInstance().execute("dialog.hide()"); 
+0

刪除'update =「對話框''工作。謝謝。 – Catfish 2012-02-02 20:39:57

+0

不客氣。 – BalusC 2012-02-02 20:40:21

0

在向服務器發送每個請求之後,您的對話框將被複制。嘗試設置對話屬性,appendToBody="true"應該防止這種情況發生。

+0

我補充說,但它沒有做任何不同的事情。 – Catfish 2012-01-30 17:21:44