如何在加载时调用默认值上的日历验证程序

时间:2017-01-27 10:38:00

标签: validation jsf primefaces jsf-2

我有这段代码。目前,按钮调用验证。但是,如果页面加载时已存在默认值,我也想调用验证。我怎样才能做到这一点?感谢。

// ... the calendar
<div class="formBlock">
    <p class="formGroupTitle">#{msg['startEmploymentDate']}</p>
    <p:message id="startDateMessage" for="startDate" />
    <p:calendar id="startDate" required="true" pattern="dd.MM.yyyy"
            locale="de" requiredMessage="#{nts['pleaseEnterAFutureDate']}"
            mindate="#{companyJobProfileCreateStep2Bean.currentDate}"
            value="#{companyJobProfileCreateStep2Bean.jobProfile.startDate}"
            converterMessage="#{nts['pleaseEnterAFutureDate']}"
            validator="futureDateValidator" showOn="button" navigator="true">
            <p:ajax event="dateSelect" update="@(.roundedNumberRefreshable)"
                    listener="#{companyJobProfileCreateStep2Bean.updateSearchParameters()}" />
    </p:calendar>
</div>

// ... and the button
<p:commandButton
    value="#{companyJobProfileCreateStep2Bean.getJobProfile().ams ? msg['sendProposal'] : msg['accept']}"
    oncomplete="if (args &amp;&amp; !args.validationFailed) {PF('generalDetailsSlider').unselect(0);PF('paymentDetailsSlider').select(0);}"
    update="@(.adtextUpdateable) @(.hasAddressAndMessageUpdateable) startDate vacancies startDateMessage vacanciesMessage @(.generalDetailsSliderHeaderUpdateable) @(.progressBarCompany)"
    actionListener="#{companyJobProfileCreateStep2Bean.verifyHasAddresses()}"
    process="startDate vacancies" partialSubmit="true"></p:commandButton>

1 个答案:

答案 0 :(得分:0)

我有一个想法可能会使用remoteCommand(一点点黑客)。基本上,您将模拟单击提交按钮时将发生的情况。您可以决定何时调用您的函数。

希望这有帮助。

<p:remoteCommand name="errorSubmitButton" autoRun="false/true" global="false"
                oncomplete="if (args &amp;&amp; !args.validationFailed) {PF('generalDetailsSlider').unselect(0);PF('paymentDetailsSlider').select(0);}"
                update="@(.adtextUpdateable) @(.hasAddressAndMessageUpdateable) startDate vacancies startDateMessage vacanciesMessage @(.generalDetailsSliderHeaderUpdateable) @(.progressBarCompany)"
                actionListener="#{companyJobProfileCreateStep2Bean.verifyHasAddresses()}"
                process="startDate vacancies" partialSubmit="true" />

<h:outputScript rendered="yourConditionWhenToExecuteScriptIfYouHaveOne">
        $(document).ready(function () {
            errorSubmitButton();
        });
</h:outputScript>