2011-11-11 24 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?