malformedXML:更新期间:accessForm:passMessage 未找到

发布于 2024-12-15 05:06:12 字数 3645 浏览 2 评论 0原文

我正在尝试改进我的网络应用程序。我读了这篇文章 http://balusc.blogspot .com/2011/01/jsf-20-tutorial-with-eclipse-and.html 并尝试实现一些 ajax 的东西(我对 JSF 很陌生,阿贾克斯)。

因此,第一个表单按预期工作,但是当我传递到第二个页面时,消息ma​​lformedXML:在更新期间:accessForm:passMessage not found显示在警报框中。

谁能解释一下为什么?

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

提前致谢。

更新

这是 Bean 代码:

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雨落星ぅ辰 2024-12-22 05:06:12

此错误表明处理 ajax 请求时存在竞争条件。动作方法的ajax请求发生在模糊验证的ajax请求之前。尝试将 ?faces-redirect=true 添加到操作方法的导航结果值中。然后,JSF 肯定会阻止队列中所有打开的 ajax 请求。

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

无论如何,在 POST 导航上使用(默认)转发都是一种不好的做法,否则最终用户最终会在浏览器地址栏中看到未更改的 URL 和不可添加书签的页面。另请参阅 何时应使用 h:outputLink 而不是 h:commandLink?< /a>

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文