malformedXML: During update: accessForm:passMessage not found

痞子三分冷 提交于 2020-01-02 09:53:42

问题


I'm trying to improve my web app. I read this article http://balusc.blogspot.com/2011/01/jsf-20-tutorial-with-eclipse-and.html and tried to implement some of the ajax stuff (I'm very new to JSF and Ajax).

So the first form works as expected, but when I pass to the second page the message malformedXML: During update: accessForm:passMessage not found is shown in an alert box.

Can anyone explain me why?

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

Thanks in advance.

Update

Here's the Bean code:

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

回答1:


This error indicates a race condition in handling ajax requests. The ajax request of the action method occurred before the ajax request of the blur validation. Try adding ?faces-redirect=true to the navigation outcome value of the action method. JSF should then surely block all open ajax requests in the queue.

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

Using (default) forward on POST navigation is a poor practice anyway as the enduser would otherwise end up with an unchanged URL in browser address bar and a non-bookmarkable page. See also When should I use h:outputLink instead of h:commandLink?



来源:https://stackoverflow.com/questions/8098675/malformedxml-during-update-accessformpassmessage-not-found

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!