在jsf形式的javascript中使用bean

时间:2013-06-16 12:57:13

标签: javascript jsf primefaces

我有一个包含不同输入文本的表单,我想在客户端验证我的表单,所以我编写了一个java脚本函数,并且表单的验证基于已定义bean中的属性(userManagement.update) ,这意味着如果userManagement.update为true,则不需要这些输入文本,但如果userManagement.update为false,则需要这些输入文本。 问题是userManagement.update在javascript函数中没有改变。

<h:outputLabel for="pwd1" value="* #{i18n['password']}: "
                        rendered="#{!userManagement.update}" />
                    <h:outputLabel for="pwd1" value=" #{i18n['password']}: "
                        rendered="#{userManagement.update}" />
                    <p:password id="pwd1" value="#{userManagement.user.password}"
                        match="pwd2" label="Password 1"
                        required="#{!userManagement.update}"
                        requiredMessage="#{i18n['password_required']}"
                        validatorMessage="#{i18n['password_match_repeat_password']}" />
                    <span style="color: red" id="emptyPasswordError" />
                    <h:outputLabel for="pwd2" value="* #{i18n['repeat_password']}: "
                        rendered="#{!userManagement.update}" />
                    <h:outputLabel for="pwd2" value=" #{i18n['repeat_password']}: "
                        rendered="#{userManagement.update}" />
                    <p:password id="pwd2" value="#{userManagement.user.password}"
                        required="#{!userManagement.update}"
                        requiredMessage="#{i18n['repeat_password_required']}" />
                    <span style="color: red" id="emptyRepeatPasswordError" />



<p:commandButton value="#{i18n['update']}"
                actionListener="#{userManagement.update}">
            </p:commandButton>


<script type="text/javascript">
function validateForm() {
    if ($("#addUserform:pwd1").val() === "")
    {
        if("#{!userManagement.update}"){
            $("#emptyPasswordError").text("#{i18n['password_required']}"); 
            validation = false; 
        }
    }
    else{
        $("#emptyPasswordError").text("");
    }
    if ($("#addUserform:pwd2").val() === "")
    {
        alert("#{!userManagement.update}");
        if("#{!userManagement.update}"){
            $("#emptyRepeatPasswordError").text( "#{i18n['repeat_password_required']}"); 
            validation = false; 
        }
    }
    else{
        $("#emptyRepeatPasswordError").text("");
    } 
    return validation;
}
</script>

0 个答案:

没有答案