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 && !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>
爲什麼不直接在你的支持bean的init方法中驗證它呢? – pablo
@pablo:假設你想以這種方式驗證所有字段,那麼你正在複製功能。 – Kukeltje
那麼,你已經把代碼隔離在一個特定的驗證器中,你可以重用,對嗎? – pablo