简体   繁体   English

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

[英]ignore validation on dialog close jsf primefaces

Iam trying to validate ap:dialog as below IAM尝试如下验证ap:dialog

                                <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>

when i submit dialog without filling inputs the validations are executing correctly after that if I close the dialog (gave up, dont want to save modal) because of executed and fail validations I cannot submit parent form due to this issue. 当我提交对话框而没有填写输入内容时,如果由于执行和失败的验证而关闭了对话框(放弃,不想保存模态),验证将正确执行,由于这个问题,我无法提交父表格。 Any help will be appreciated! 任何帮助将不胜感激!

If your parent form and your dialog are part of the same <h:form> you have to take care of the process attributes of your ajax behaviors. 如果您的父表单和对话框属于同一<h:form>一部分,则必须注意ajax行为的process属性。 If you process the whole form the input fields in your dialog are also processed even if the dialog is not shown. 如果处理整个表单,即使对话框未显示,对话框中的输入字段也会被处理。 So take care that you only process the fields outside the dialog. 因此请注意,您只能处理对话框外的字段。

You could also place your dialog in an own <h:form> (not within the other <h:form> ), eg 您还可以将对话框放置在自己的<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>

Then you can use @form within each form. 然后,您可以在每个表单中使用@form If you want to process or update the other form you can use absolute ids, eg ":form" or ":dialog-form". 如果要processupdate其他表单,则可以使用绝对ID,例如“:form”或“:dialog-form”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM