2011-11-11 25 views
2

我正在嘗試改進我的web應用程序。我閱讀這篇文章http://balusc.blogspot.com/2011/01/jsf-20-tutorial-with-eclipse-and.html並試圖實現一些ajax的東西(我對JSF和Ajax非常陌生)。malformedXML:更新期間:accessForm:passMessage未找到

因此,第一種形式按預期工作,但是當我傳遞到第二頁時,消息malformedXML:更新期間:accessForm:passMessage未找到顯示在警告框中。

任何人都可以解釋我爲什麼嗎?

<h:form id="accessForm"> 
     <h:panelGrid columns="3"> 
      <h:outputLabel for="user" value="Usuario:" 
          style="float: right" /> 
      <h:inputText id="user" value="#{userVerifier.username}" 
         required="true" 
         requiredMessage="Introduzca su nombre de usuario."> 
       <f:ajax event="blur" render="userMessage" /> 
      </h:inputText> 
      <h:message id="userMessage" for="user" style="color: #FF0000;" /> 

      <h:outputLabel for="pass" value="Contraseña:" 
          style="float: right" /> 
      <h:inputSecret id="pass" value="#{userVerifier.password}" 
          required="true" 
          requiredMessage="Introduzca su contraseña." redisplay="true"> 
       <f:ajax event="blur" render="passMessage" /> 
      </h:inputSecret> 
      <h:message id="passMessage" for="pass" style="color: #FF0000;" /> 

      <h:panelGroup /> 
      <h:commandButton value=" Entrar " action="#{userVerifier.check}" 
          style="float: right" > 
       <f:ajax execute="@form" render="@form" /> 
      </h:commandButton> 
      <h:messages globalOnly="true" layout="table" /> 
     </h:panelGrid> 
    </h:form> 

在此先感謝。

更新

這裏的豆代碼:

@ManagedBean 
@SessionScoped 
public class UserVerifier{ 

    private String username; 
    private String password; 
    private String dependencia; 
    private String tipoUsuario; 
    private final Database db = new Database(); 

    public String getUsername() { 
     return username; 
    } 

    public void setUsername(String username) { 
     this.username = username; 
    } 

    public String getPassword() { 
     return password; 
    } 

    public void setPassword(String password) { 
     this.password = password; 
    } 

    public String getDependencia() { 
     return dependencia; 
    } 

    public void setDependencia(String dependencia) { 
     this.dependencia = dependencia; 
    } 

    public String getTipoUsuario() { 
     return tipoUsuario; 
    } 

    public void setTipoUsuario(String tipoUsuario) { 
     this.tipoUsuario = tipoUsuario; 
    } 

    public String check() { 
     String isValidUser = db.checkUser(username, password); 
     if (isValidUser.equals("T")) { 
      dependencia = db.getDependencia(username, password); 
      tipoUsuario = db.getTipoUsuario(username); 
      System.out.println("tipoDepe: " + dependencia); 
      System.out.println("tipoUser: " + tipoUsuario); 
      if (dependencia != null && tipoUsuario != null) { 
       return "upload-file"; 
      } else { 
       setUsername(""); 
       setPassword(""); 
       return "index"; 
      } 
     } else if (isValidUser.equals("F")) { 
      setUsername(""); 
      setPassword(""); 
      return "index"; 
     } else { 
      return "error-pnf"; 
     } 
    } 
} 
+0

什麼是JSF impl/version? (或者你是否使用Glassfish的默認版本?如果是,哪個Glassfish版本?)你是否在任何地方使用渲染屬性?這個錯誤表明一個組件在被更新時沒有被渲染,但是我沒有在代碼中看到它。 – BalusC

+0

不,我沒有在任何地方使用「渲染」屬性。我正在使用Mojarra 2.1.4和Tomcat 7. – BRabbit27

+0

在bean的函數中的''的'action =「#{userVerifier.check}」'中,我返回一個String,所以我可以去到下一頁。 – BRabbit27

回答

2

這個錯誤表示在處理Ajax請求的競爭條件。操作方法的ajax請求發生在模糊驗證的ajax請求之前。嘗試將?faces-redirect=true添加到操作方法的導航結果值。那麼JSF應該可以阻止隊列中所有打開的Ajax請求。

public String check() { 
    // ... 
    return "nextpage?faces-redirect=true"; 
} 

使用(默認)向前POST導航是一個貧窮的做法反正作爲終端用戶否則將在瀏覽器地址欄中的URL不變和非可收藏的頁面結束。另請參見When should I use h:outputLink instead of h:commandLink?