【问题标题】:Popup panel not displaying errors / submitting弹出面板不显示错误/提交
【发布时间】:2013-12-21 05:45:03
【问题描述】:

我正在使用 JSF 2,以及 Richfaces 4.x。我创建了一个在弹出窗口中的登录表单。弹出窗口没有正确提交和返回错误,也不允许我登录。

这是我的登录弹出窗口:

        <rich:popupPanel id="loginPopup">
            <h:form id="login" class="compact-form clearfix">
                <h1>Access your Account</h1>
                <fieldset id="inputs">
                    <h:outputLabel value="Username:" for="username"/><br/>
                    <h:inputText id="username" value="#{viewLogin.loginName}" required="true" requiredMessage="Please enter your username">
                        <f:validateLength maximum="20" minimum="3" />
                    </h:inputText>
                    <a4j:outputPanel ajaxRendered="true">
                        <h:message for="username" />
                    </a4j:outputPanel>

                    <h:outputLabel value="Password:" for="password"/><br/>
                    <h:inputSecret id="password" value="#{viewLogin.password}" required="true" requiredMessage="Enter your password">
                        <f:validator validatorId="LoginValidator" />
                        <f:validateLength maximum="20" minimum="5" />
                    </h:inputSecret>
                    <a4j:outputPanel ajaxRendered="true">
                        <h:message for="password" />
                    </a4j:outputPanel>
                </fieldset>
                <fieldset id="actions">
                    <a4j:commandButton value="Submit" id="submit" action="#{viewLogin.login()}" immediate="false" 
                           execute="username password @this"
                           render="username password"  oncomplete="if (#{facesContext.maximumSeverity == null}) {#{rich:component('loginPopup')}.hide();}"/>
                    <h:commandButton value="Cancel">
                        <rich:componentControl operation="hide" target="loginPopup"/>
                    </h:commandButton>
                    <h:link value="Forgot password?" outcome="forgotpassword"/>
                    <h:link value="Forgot username?" outcome="forgotusername"/>
                    <h:link value="Create account" outcome="createuser"/>
                </fieldset>
            </h:form> 
        </rich:popupPanel>

现在,当我按下提交按钮时,h:inputSecret 样式会发生变化,并且该字段没有登录输入类型密码并将显示我的密码。

为什么我的登录没有提交验证/呈现错误?

注意:该表单无需 popup 和 a4j 标签即可工作。

【问题讨论】:

  • 另外,为了测试目的,添加一个通用的 rich:messages/h:messages 来检查它是否有其他抱怨 - 不要忘记让它重新渲染..

标签: jsf jsf-2 popup richfaces


【解决方案1】:

我刚刚在 RF 4.3.3.Final 中仔细检查了您的源代码,只是删除了您正在使用的 LoginValidator,但未提供:

<rich:popupPanel id="loginPopup" show="true">
    <h:form id="login" class="compact-form clearfix">
        <h1>Access your Account</h1>
        <fieldset id="inputs">
            <h:outputLabel value="Username:" for="username"/><br/>
            <h:inputText id="username" value="#{viewLogin.loginName}" required="true" requiredMessage="Please enter your username">
                <f:validateLength maximum="20" minimum="3" />
            </h:inputText>
            <a4j:outputPanel ajaxRendered="true">
                <h:message for="username" />
            </a4j:outputPanel>
             <h:outputLabel value="Password:" for="password"/><br/>
             <h:inputSecret id="password" value="#{viewLogin.password}" required="true" requiredMessage="Enter your password">
                <f:validateLength maximum="20" minimum="5" />
             </h:inputSecret>
             <a4j:outputPanel ajaxRendered="true">
                <h:message for="password" />
             </a4j:outputPanel>
        </fieldset>
        <fieldset id="actions">
            <a4j:commandButton value="Submit" id="submit" action="#{viewLogin.login()}" immediate="false"
                   execute="username password @this"
                   render="username password"  oncomplete="if (#{facesContext.maximumSeverity == null}) {#{rich:component('loginPopup')}.hide();}"/>
            <h:commandButton value="Cancel">
                <rich:componentControl operation="hide" target="loginPopup"/>
            </h:commandButton>
        </fieldset>
    </h:form>
</rich:popupPanel>

使用最小化的 Seam 2.1.3.CR1 注入 Bean

import org.jboss.seam.annotations.Name;

@Name("viewLogin")
public class TestBean {

private String loginName;
private String password;

public String getPassword() {
    return password;
}
public void setPassword(String password) {
    this.password = password;
}
public String getLoginName() {
    return loginName;
}
public void setLoginName(String loginName) {
    this.loginName = loginName;
}

public String login() {
    System.out.println("Login called");
    return "";
}
}

并且inputSecret 字段是保密的。我的建议是

  • 添加全局h:messages(必须通过单击按钮重新呈现)或全局rich:messages 以检查其他可能的原因。
  • 还要仔细检查 LoginValidator-Bean 是否存在任何可能的问题
  • 确保没有其他 PhaseListener/JavaScript 主动更改 DOM

有时,popupPanel 结合表单(作为嵌套表单)会显示奇怪的行为。您可以修改通过属性 domElementAttachment 附加的 DOM 元素。

希望对你有帮助...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-10-24
    • 2011-10-27
    • 1970-01-01
    • 1970-01-01
    • 2014-12-23
    • 1970-01-01
    • 2015-06-02
    • 1970-01-01
    相关资源
    最近更新 更多