1

一般来说,我是 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

4

0 回答 0