弹出面板不显示错误/提交

时间:2013-12-04 16:18:23

标签: jsf jsf-2 popup richfaces

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

这是我的登录弹出窗口:

Before login attempt

        <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样式会被更改,并且该字段无法登录输入类型密码并显示我的密码。

after submit

为什么我的登录信息未提交验证/呈现错误?

注意:表单不带弹出框和a4j标记。

1 个答案:

答案 0 :(得分: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元素。

希望它有所帮助...