Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ajax 验证失败后JSF Primefaces表单错误_Ajax_Validation_Jsf_Primefaces - Fatal编程技术网

Ajax 验证失败后JSF Primefaces表单错误

Ajax 验证失败后JSF Primefaces表单错误,ajax,validation,jsf,primefaces,Ajax,Validation,Jsf,Primefaces,一般来说,我对JSF/Java是新手,但几天来一直在尝试解决这个问题 我有一张表格在验证时卡住了。当所有条目都有效时,一切都很好。在我中断验证的那一刻(比如不提供所需的值),表单就被卡住了。发生的一件事是,我无法更正无效条目,并重新发布。还有,我对selectOneMenu的级联ajax调用突然开始失败……尽管这不是表单的无效部分 我注意到级联下拉列表似乎在其重写的equals方法中抛出空指针异常 我不知所措 <html xmlns="http://www.w3.org/1999/xhtm

一般来说,我对JSF/Java是新手,但几天来一直在尝试解决这个问题

我有一张表格在验证时卡住了。当所有条目都有效时,一切都很好。在我中断验证的那一刻(比如不提供所需的值),表单就被卡住了。发生的一件事是,我无法更正无效条目,并重新发布。还有,我对selectOneMenu的级联ajax调用突然开始失败……尽管这不是表单的无效部分

我注意到级联下拉列表似乎在其重写的equals方法中抛出空指针异常

我不知所措

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui"
    xmlns:ui="http://java.sun.com/jsf/facelets">
<ui:composition template="/templates/layout.xhtml">
    <ui:define name="content">
        <p:ajaxStatus onstart="statusDialog.show();" onsuccess="statusDialog.hide();"/>  

        <p:dialog modal="true" widgetVar="statusDialog" header="Status"   
                draggable="false" closable="false">  
        <p:graphicImage value="/resources/images/ajaxloadingbar.gif" />  
</p:dialog>
        <h:form id="form">
            <p:panel id="panel"
                header="Please ensure your personal details are accurate"
                style="margin-bottom:10px;">
                <p:messages id="msgs" />
                <h:outputText
                    value="Please ensure your personal details are up to date and accurate within the Admin Direct system. Please note that this application only supports GMD customers, so unless you are within GMD, or are a user of the GMD Admin Direct service, please do not enter your details or attempt to use the application for administrative support." />
                <h:panelGrid columns="3" cellpadding="5" id="grid">

                    <h:outputText value="First Name:" style="font-weight:bold" />
                    <p:inputText id="firstName"
                        value="#{personalDetailsBean.user.firstName}" 
                        requiredMessage="First name is required..." style="width:250px" />
                    <p:message id="firstNameMessage" for="firstName" />

                    <h:outputText value="Last Name:" style="font-weight:bold" />
                    <p:inputText id="lastName"
                        value="#{personalDetailsBean.user.lastName}" 
                        requiredMessage="Last name is required..." style="width:250px" />
                    <p:message id="lastNameMessage" for="lastName" />

                    <h:outputText value="Select Function:" style="font-weight:bold" />
                    <p:selectOneMenu id="functions"
                        value="#{personalDetailsBean.user.function}" 
                        style="width:250px">
                        <f:selectItem itemLabel="Select Function" itemValue="" />
                        <f:selectItems value="#{personalDetailsBean.functions}" var="func"
                            itemLabel="#{func.functionName}" itemValue="#{func}" />
                        <f:converter converterId="functionConverter" />
                    </p:selectOneMenu>
                    <p:message id="functionMessage" for="functions" />

                    <h:outputText value="Select Site" style="font-weight:bold" />
                    <p:selectOneMenu id="sites"
                        value="#{personalDetailsBean.user.site}" 
                        style="width:250px">
                        <f:selectItem itemLabel="Select Site" itemValue="" />
                        <f:selectItems value="#{personalDetailsBean.sites}" var="sit"
                            itemLabel="#{sit.siteName}" itemValue="#{sit}" />
                        <f:converter converterId="siteConverter" />
                        <p:ajax update="region" event="change" process="@this"/>
                    </p:selectOneMenu>
                    <p:message id="siteMessage" for="sites" />

                    <h:outputText value="Region" style="font-weight:bold" />
                    <h:outputText id="region"
                        value="#{personalDetailsBean.user.site.region.regionName}" />
                    <p:message id="regionMessage" for="region" />

                    <h:outputText value="Email" style="font-weight:bold" />
                    <p:inputText id="email" value="#{personalDetailsBean.user.email}"
                        required="true"
                        validatorMessage="Invalid email address format"
                        style="width:250px">
                    <f:validateRegex
                       pattern="[\w\.-]*[a-zA-Z0-9_]@[\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]" />
                        <f:validateLength minimum="2" />
                    </p:inputText>
                    <p:message id="emailMessage" for="email" />
                </h:panelGrid>
                <p:separator />
                <p:commandButton value="Save" id="btnSubmit" actionListener="#{personalDetailsBean.saveUser}" process="@all" update="panel" />
            </p:panel>
        </h:form>
    </ui:define>
</ui:composition>
</html>

非常感谢您的建议

问候


SM

嗨,我好像已经修好了,不知道为什么。我的Site类覆盖了equals,但没有覆盖hashcode……我让eclipse覆盖hashcode,现在一切都正常了。最好知道为什么在验证失败之前都能工作。如果没有java代码,就很难理解为什么能工作。您使用ajax提交而不是标准表单提交有什么原因吗?尝试将ajax=“false”放在p:commandButton上,并删除进程=“@all”-这将执行表单提交操作,并重新呈现所有内容。