JSF验证错误消息未显示

时间:2012-12-10 20:51:32

标签: validation jsf-2 primefaces spinner

以下是代码:

    <p:tabView id="tabId" effect="fade" effectDuration="normal"
        style="font-size:105%;font-family:Times New Roman, Times, serif;"
        orientation="left">

        <p:tab title="Yard Parameters">
            <h:form id="yardParameters"
                style="color:white; font-weight:bold; font-size:100%;">
                <p:messages id="messages" showDetail="true" autoUpdate="true"
                    closable="true" />
                <div style="position: relative; left: 39px;">
                    <h:panelGrid columns="5" cellpadding="8">
                        <h:outputLabel for="humpSpeed" value="Hump Speed:" />
                        <p:spinner id="humpSpeed" value="#{yardMaster.humpSpeed.number}"
                            stepFactor="#{yardMaster.humpSpeed.step}"
                            min="#{yardMaster.humpSpeed.min}"
                            max="#{yardMaster.humpSpeed.max}"
                            suffix="#{yardMaster.humpSpeed.suffix}"
                            style="width: 200px;font-size:86%;">
                            <f:validateLongRange minimum="#{yardMaster.humpSpeed.min}"
                                maximum="#{yardMaster.humpSpeed.max}" for="humpSpeed" />
                        </p:spinner>    
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <h:outputLabel for="pullbackTime" value="Pullback Time:" />
                        <p:spinner id="pullbackTime"
                            value="#{yardMaster.pullbackTime.number}"
                            stepFactor="#{yardMaster.pullbackTime.step}"
                            min="#{yardMaster.pullbackTime.min}"
                            max="#{yardMaster.pullbackTime.max}"
                            suffix="#{yardMaster.pullbackTime.suffix}"
                            style="width: 200px;font-size:86%;">
                            <f:validateLongRange minimum="#{yardMaster.pullbackTime.min}"
                                maximum="#{yardMaster.pullbackTime.max}" for="pullbackTime" />
                        </p:spinner>
                    </h:panelGrid>
                </div>
                <br></br>
                <div style="position: relative; left: 25px;">
                    <h:panelGrid columns="5" cellpadding="8">

                        <h:outputLabel for="inspectionTime" value="Inspection Time:" />
                        <p:spinner id="inspectionTime"
                            value="#{yardMaster.inspectionTime.number}"
                            stepFactor="#{yardMaster.inspectionTime.step}"
                            min="#{yardMaster.inspectionTime.min}"
                            max="#{yardMaster.inspectionTime.max}"
                            suffix="#{yardMaster.inspectionTime.suffix}"
                            validatorMessage="Please enter from 30 to 120"
                            style="width: 200px;font-size:86%;">
                            <f:validateLongRange minimum="#{yardMaster.inspectionTime.min}"
                                maximum="#{yardMaster.inspectionTime.max}" for="inspectionTime" />
                        </p:spinner>
                        <h:outputLabel for="extraTrainThreshold"
                            value="Extra Train Threshold:" />
                        <p:spinner id="extraTrainThreshold"
                            value="#{yardMaster.extraTrainThreshold.number}"
                            stepFactor="#{yardMaster.extraTrainThreshold.step}"
                            min="#{yardMaster.extraTrainThreshold.min}"
                            max="#{yardMaster.extraTrainThreshold.max}"
                            suffix="#{yardMaster.extraTrainThreshold.suffix}"
                            style="width: 200px;font-size:86%;">
                            <f:validateLongRange
                                minimum="#{yardMaster.extraTrainThreshold.min}"
                                maximum="#{yardMaster.extraTrainThreshold.max}"
                                for="extraTrainThreshold" />
                        </p:spinner>
                    </h:panelGrid>
                </div>
                <br></br>
                <div style="position: relative; left: 16px;">
                    <h:panelGrid columns="5" cellpadding="8">
                        <h:outputLabel for="airBleedingTime" value="Air Bleeding Time:" />
                        <p:spinner id="airBleedingTime"
                            value="#{yardMaster.airBleedingTime.number}"
                            stepFactor="#{yardMaster.airBleedingTime.step}"
                            min="#{yardMaster.airBleedingTime.min}"
                            max="#{yardMaster.airBleedingTime.max}"
                            suffix="#{yardMaster.airBleedingTime.suffix}"
                            style="width: 200px;font-size:86%;">
                            <f:validateLongRange minimum="#{yardMaster.airBleedingTime.min}"
                                maximum="#{yardMaster.airBleedingTime.max}"
                                for="airBleedingTime" />
                        </p:spinner>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <h:outputLabel for="xxxxxxTime" value="xxxxxxxx Time:" />
                        <p:spinner id="xxxxxxTime"
                            value="#{yardMaster.xxxxxxTime.number}"
                            stepFactor="#{yardMaster.xxxxxxTime.step}"
                            min="#{yardMaster.xxxxxxTime.min}"
                            max="#{yardMaster.xxxxxxTime.max}"
                            suffix="#{yardMaster.xxxxxxTime.suffix}"
                            style="width: 200px;font-size:86%;">
                            <f:validateLongRange minimum="#{yardMaster.xxxxxxTime.min}"
                                maximum="#{yardMaster.xxxxxxTime.max}" for="xxxxxxTime" />
                        </p:spinner>
                    </h:panelGrid>
                </div>
                <br></br>
                <div style="position: relative; left: 30px;">
                    <h:panelGrid columns="5" cellpadding="8">
                        <h:outputLabel for="couplingTime" value="Coupling Time:" />
                        <p:spinner id="couplingTime"
                            value="#{yardMaster.couplingTime.number}"
                            stepFactor="#{yardMaster.couplingTime.step}"
                            min="#{yardMaster.couplingTime.min}"
                            max="#{yardMaster.couplingTime.max}"
                            suffix="#{yardMaster.couplingTime.suffix}"
                            style="width: 200px;font-size:86%;">
                            <f:validateLongRange minimum="#{yardMaster.couplingTime.min}"
                                maximum="#{yardMaster.couplingTime.max}" for="couplingTime" />
                        </p:spinner>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <h:outputLabel for="xxxxxxTime2" value="xxxxxxxx Time:" />
                        <p:spinner id="xxxxxxTime2"
                            value="#{yardMaster.xxxxxxTime2.number}"
                            stepFactor="#{yardMaster.xxxxxxTime2.step}"
                            min="#{yardMaster.xxxxxxTime2.min}"
                            max="#{yardMaster.xxxxxxTime2.max}"
                            suffix="#{yardMaster.xxxxxxTime2.suffix}"
                            style="width: 200px;font-size:86%;">
                            <f:validateLongRange minimum="#{yardMaster.xxxxxxTime2.min}"
                                maximum="#{yardMaster.xxxxxxTime2.max}" for="xxxxxxTime2" />
                        </p:spinner>
                    </h:panelGrid>
                </div>
                <br></br>
                <br></br>
            </h:form>
        </p:tab>
        <p:tab title="Air Bleeding Time" />
        <p:tab title="Inbounded Time" />
        <p:tab title="Outbound Time" />
    </p:tabView>

这就是我做错了什么,验证发生了,即只有当它们处于可接受的范围内时才接受这些值,但是当我输入的值不在范围内时,则不显示错误消息。 以下是命令按钮的代码,如果数据验证正确,则导航到不同的页面:

    <p:commandButton
        style="color:white; background-color:#292929; font-weight:bold; font-size:120%; font-family:Times New Roman, Times, serif;"
        value="Generate Plan" action="Generated Plan?faces-redirect=true" />

1 个答案:

答案 0 :(得分:0)

我发现了问题,它在我面前的config.xml中。 我不小心把下面的东西放在里面,

<application>
    <message-bundle>ValidationMessages</message-bundle>
</application>

这基本上意味着我应该定义我自己没有做过的消息,所以我没有收到消息,一旦我删除它,我开始收到消息。