忽略对话框上的验证关闭jsf primefaces

时间:2017-03-06 08:00:33

标签: validation jsf primefaces dialog

Iam尝试验证p:对话框,如下所示

                                <p:dialog widgetVar="canPolDialog" id="canPolDialog" modal="true"
                                      appendTo="@form:canPolPanel"
                                      focus="name"
                                      resizable="false" draggable="false" minHeight="600" minWidth="250" width="700"
                                      onHide="hideModal()" styleClass="canPolDialog">
                                <f:facet name="header">
                                    <div class="dialogHeader">
                                        <h2>#{messages['pages.cancellationPolicies.dialog.title']}</h2>
                                        <span>#{messages['pages.cancellationPolicies.dialog.description']}</span>
                                    </div>
                                </f:facet>

                                <p:outputPanel id="cancellationDetail"
                                               styleClass="col-md-12 xs-mt-20 dialogSublabel">
                                    <f:validateBean>
                                        <p:outputPanel rendered="#{policyBean.renderCancelationDialog}">
                                            <p:outputPanel id="customPanel">
                                                <f:verbatim escape="false"
                                                            rendered="#{policyBean.closePopup}">
                                                    <script type="text/javascript">
                                                        PF('canPolDialog').hide();
                                                    </script>
                                                </f:verbatim>

                                                <div class="row">
                                                    <ets:inputTextWithLabel
                                                        label="pages.cancellationPolicies.name"
                                                        id="name"
                                                        formCol="6"
                                                        requiredMessage="#{readMessage.getValidationMessagesValue('cancellationPolcy.policyName.cant.be.null')}"
                                                        value="#{policyBean.cancelationPolicyPojo.name}"
                                                        required="true"
                                                    />
                                                </div>
                                                <div class="col-md-10 minsizeText">
                                                    #{messages['pages.cancellationPolicies.policyName.description']}
                                                </div>

                                                <div class="row">
                                                    <ets:selectWithLabel required="true"
                                                                         id="policyNameType"
                                                                         requiredMessage="#{readMessage.getValidationMessagesValue('cancellationPolcy.policyNameType.cant.be.null')}"
                                                                         firstItem="#{messages['global.pleaseSelect']}"
                                                                         formCol="6"
                                                                         label="pages.cancellationPolicies.policyName"
                                                                         value="#{policyBean.cancelationPolicyPojo.policyNameType}">
                                                        <f:selectItems noSelectionValue="false"
                                                                       value="#{PolicyNameType.values()}"
                                                                       var="nameType"
                                                                       itemValue="#{nameType}"
                                                                       itemLabel="#{messages[nameType.getBundleKey()]}"/>
                                                        <p:ajax event="change" resetValues="true"
                                                                update="@form:cancellationTypePanel,@form:dropdownHour,@form:penaltyRenderArea,@form:noShowPanel"
                                                                listener="#{policyBean.onNameTypeChange()}"/>
                                                    </ets:selectWithLabel>
                                                </div>

                                                <div class="col-md-10 minsizeText">
                                                    #{messages['pages.cancellationPolicies.acceptCancelation.description']}
                                                </div>
                                                <div class="row">
                                                    <p:outputPanel id="cancellationTypePanel">
                                                        <ets:selectWithLabel
                                                            id="cancellationType"
                                                            firstItem="#{messages['global.pleaseSelect']}"
                                                            formCol="6" required="true"
                                                            requiredMessage="#{readMessage.getValidationMessagesValue('cancellationPolicy.canType.cant.be.null')}"
                                                            label="pages.cancellationPolicies.acceptCancelation"
                                                            value="#{policyBean.cancelationPolicyPojo.cancellationType}">
                                                            <f:selectItems
                                                                value="#{policyBean.cancellationTypes}"
                                                                var="var" noSelectionValue="false"
                                                                itemValue="#{var}"
                                                                itemLabel="#{messages['cancelationPolicyBean.cancelationPolicyPojo.'.concat(var.friendlyName())]}"
                                                            />
                                                            <p:ajax resetValues="true" event="change"
                                                                    listener="#{policyBean.handleCancellationChange}"
                                                                    update="@form:dropdownHour,@form:penaltyRenderArea"/>
                                                        </ets:selectWithLabel>
                                                    </p:outputPanel>
                                                    <p:outputPanel id="dropdownHour">
                                                        <p:outputPanel
                                                            rendered="#{policyBean.renderSameDayCanpolOpt}">
                                                            <ets:selectWithLabel
                                                                id="cancellationValue"
                                                                value="#{policyBean.cancelationPolicyPojo.cancellationValue}"
                                                                formCol="6" required="true"
                                                                requiredMessage="#{messages['pages.cancellationPolicies.pleaseSelectHour']}"
                                                                label="pages.cancellationPolicies.sameday">
                                                                <f:selectItem itemLabel="00:00"
                                                                              itemValue="00:00"/>
                                                                <f:selectItem itemLabel="01:00"
                                                                              itemValue="01:00"/>
                                                                <f:selectItem itemLabel="02:00"
                                                                              itemValue="02:00"/>
                                                                <f:selectItem itemLabel="03:00"
                                                                              itemValue="03:00"/>
                                                                <f:selectItem itemLabel="04:00"
                                                                              itemValue="04:00"/>
                                                                <f:selectItem itemLabel="05:00"
                                                                              itemValue="05:00"/>
                                                                <f:selectItem itemLabel="06:00"
                                                                              itemValue="06:00"/>
                                                                <f:selectItem itemLabel="07:00"
                                                                              itemValue="07:00"/>
                                                                <f:selectItem itemLabel="08:00"
                                                                              itemValue="08:00"/>
                                                                <f:selectItem itemLabel="09:00"
                                                                              itemValue="09:00"/>
                                                                <f:selectItem itemLabel="10:00"
                                                                              itemValue="10:00"/>
                                                                <f:selectItem itemLabel="11:00"
                                                                              itemValue="11:00"/>
                                                                <f:selectItem itemLabel="12:00"
                                                                              itemValue="12:00"/>
                                                                <f:selectItem itemLabel="13:00"
                                                                              itemValue="13:00"/>
                                                                <f:selectItem itemLabel="14:00"
                                                                              itemValue="14:00"/>
                                                                <f:selectItem itemLabel="15:00"
                                                                              itemValue="15:00"/>
                                                                <f:selectItem itemLabel="16:00"
                                                                              itemValue="16:00"/>
                                                                <f:selectItem itemLabel="17:00"
                                                                              itemValue="17:00"/>
                                                                <f:selectItem itemLabel="18:00"
                                                                              itemValue="18:00"/>
                                                                <f:selectItem itemLabel="19:00"
                                                                              itemValue="19:00"/>
                                                                <f:selectItem itemLabel="20:00"
                                                                              itemValue="20:00"/>
                                                                <f:selectItem itemLabel="21:00"
                                                                              itemValue="21:00"/>
                                                                <f:selectItem itemLabel="22:00"
                                                                              itemValue="22:00"/>
                                                                <f:selectItem itemLabel="23:00"
                                                                              itemValue="23:00"/>
                                                            </ets:selectWithLabel>
                                                        </p:outputPanel>

                                                        <p:outputPanel
                                                            rendered="#{policyBean.renderDaysBeforeCheckinOpt}"
                                                            formCol="6">
                                                            <ets:inputNumberWithLabel decimalPlaces="0"
                                                                                      required="true"
                                                                                      requiredMessage="#{messages['pages.cancellationPolicies.pleaseAdaysbeforecheckin']}"
                                                                                      label="pages.cancellationPolicies.adaysbeforecheckin"
                                                                                      minValue="0"
                                                                                      formCol="6"
                                                                                      maxValue="30"
                                                                                      styleClass="number-form-control"
                                                                                      id="adaysbeforecheckin"
                                                                                      value="#{policyBean.cancelationPolicyPojo.daysBeforeCheckinValue}">
                                                                <p:ajax event="blur"
                                                                        update="adaysbeforecheckin"/>
                                                            </ets:inputNumberWithLabel>
                                                        </p:outputPanel>
                                                    </p:outputPanel>
                                                </div>

                                                <div
                                                    class="col-md-10 minsizeText">#{messages['pages.cancellationPolicies.penaltyCharge.description']}

                                                </div>

                                                <div class="row">
                                                    <p:outputPanel id="penaltyRenderArea">
                                                        <p:outputPanel>
                                                            <ets:selectWithLabel
                                                                id="penaltyType" required="true"
                                                                requiredMessage="#{readMessage.getValidationMessagesValue('cancellationPolcy.penType.cant.be.null')}"
                                                                label="pages.cancellationPolicies.penaltyCharge"
                                                                formCol="6"
                                                                firstItem="#{messages['global.pleaseSelect']}"
                                                                value="#{policyBean.cancelationPolicyPojo.penaltyType}"
                                                                disabled="#{policyBean.penaltyDisable}">
                                                                <f:selectItems
                                                                    value="#{policyBean.penaltyTypeList}"
                                                                    var="var"
                                                                    itemValue="#{var}"
                                                                    itemLabel="#{messages['cancelationPolicyBean.penalty.'.concat(var.friendlyName())]}"
                                                                />
                                                                <p:ajax event="change"
                                                                        listener="#{policyBean.handlePenaltyChange}"
                                                                        resetValues="true"
                                                                        update="@form:dropDownPenalty"/>
                                                            </ets:selectWithLabel>


                                                            <p:outputPanel id="dropDownPenalty">
                                                                <p:outputPanel
                                                                    rendered="#{policyBean.renderPenaltyTotalPrice}">
                                                                    <ets:inputNumberWithLabel
                                                                        formCol="6" required="true"
                                                                        requiredMessage="#{messages['pages.cancellationPolicies.penaltyValueOfTotalPrice']}"
                                                                        label="pages.cancellationPolicies.ofTotalPrice"
                                                                        value="#{policyBean.cancelationPolicyPojo.penaltyValueOfTotalPrice}"
                                                                        symbol="%"
                                                                        decimalPlaces="0"
                                                                        emptyValue="empty"
                                                                        minValue="0"
                                                                        id="penaltyValueOfTotalPrice"
                                                                        styleClass="number-form-control"
                                                                        maxValue="100">
                                                                        <p:ajax event="blur"
                                                                                update="penaltyValueOfTotalPrice"/>
                                                                    </ets:inputNumberWithLabel>
                                                                </p:outputPanel>
                                                            </p:outputPanel>
                                                        </p:outputPanel>
                                                    </p:outputPanel>
                                                </div>

                                                <div
                                                    class="col-md-10 minsizeText">#{messages['pages.cancellationPolicies.noShow.description']}
                                                </div>

                                                <div class="row">
                                                    <p:outputPanel id="noShowPanel">
                                                        <ets:selectWithLabel
                                                            id="policyNoShowType"
                                                            label="pages.cancellationPolicies.noShow"
                                                            requiredMessage="#{readMessage.getValidationMessagesValue('cancellationPolcy.noshow.cant.be.null')}"
                                                            firstItem="#{messages['global.pleaseSelect']}"
                                                            required="true"
                                                             formCol="6" event="change"
                                                            value="#{policyBean.cancelationPolicyPojo.policyNoShowType}">
                                                            <f:selectItems
                                                                value="#{policyBean.cancelationPolicyNoShowTypes}"
                                                                var="var" itemValue="#{var}"
                                                                itemLabel="#{messages['cancelationPolicyBean.noshow.'.concat(var.friendlyName())]}"/>
                                                        </ets:selectWithLabel>
                                                    </p:outputPanel>
                                                </div>
                                                <div class="row">
                                                    <div class="dialog-footer">
                                                        <div class="col-md-12">
                                                            <ets:submitButton value="#{messages['global.save']}"
                                                                              update="@form:canDatatable,@form:cancellationDetail,@form:messages,@form:content"
                                                                              ajax="true"
                                                                              process="@form:canPolPanel"
                                                                              styleClass="btn-info btn pull-right"
                                                                              action="#{policyBean.saveCancellPolicy()}">
                                                            </ets:submitButton>
                                                        </div>
                                                    </div>
                                                </div>
                                                <p:ajax event="close"
                                                        process="@this"
                                                        resetValues="true">


                                                </p:ajax>

                                            </p:outputPanel>

                                        </p:outputPanel>
                                    </f:validateBean>
                                </p:outputPanel>
                            </p:dialog>

当我提交对话框而没有填写输入时,如果我关闭对话框(放弃了,不想保存模态),由于执行和失败验证我无法提交父表单,因此验证正确执行。任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:0)

如果您的父表单和对话框属于同一个<h:form>,则必须处理ajax行为的process属性。如果处理整个表单,即使未显示对话框,也会处理对话框中的输入字段。因此,请注意您只处理对话框外的字段。

您也可以将对话框置于自己的<h:form>(不在其他<h:form>内),例如

<h:form id="form">
   parent form
</h:form>

<h:form id="dialog-form">
   <p:dialog ...>
      dialog form
   </p:dialog>
</h:form>

然后您可以在每个表单中使用@form。如果您想要processupdate另一种形式,您可以使用绝对ID,例如“:form”或“:dialog-form”。