当我点击dataexporter时,它会验证输入字段而不是导出数据表

时间:2017-10-21 07:33:25

标签: primefaces datatable

我正在编写用于添加和查看供应商的代码。但问题是,我添加了一个dataexporter来以不同的格式导出表。当我单击dataexporter时,它会验证inpuut字段而不是导出数据表。见下面的代码,

  <h:panelGrid columns="6">
                            <p:outputLabel value="Vendor Name: " for="vname"/>
                            <p:inputText id="vname" required="true" value="#{bank.vendor_name}" />
                            <p:message for="vname"/>

                            <p:outputLabel value="Vendor Bank: " for="bank"/>
                            <p:selectOneMenu id="bank" value="#{bank.bankmode.bankName}" required="true" requiredMessage="Bank required">


                                <f:selectItem itemLabel="--Select Bank--" itemValue="" noSelectionOption="true"/>
                                <f:selectItems value="#{bank.bankmodel}"
                                               var="singlevalue"  
                                               itemLabel="#{singlevalue.bankName}"
                                               itemValue="#{singlevalue.bankName}"/>
                            </p:selectOneMenu>


                            <p:message for="bank"/>

                            <p:outputLabel value="Vendor Account Number: " for="anum"/>
                            <p:inputText id="anum" required="true" value="#{bank.vendor_acct}" requiredMessage="Account Number required" />
                            <p:message for="anum"/>

                            <p:outputLabel value="Vendor Contact Address: " for="adress"/>
                            <p:inputTextarea id="adress" required="true" value="#{bank.vendor_address}" requiredMessage="Contact Address required" />
                            <p:message for="adress"/>

                            <p:outputLabel value="Vendor Email Address: " for="email"/>
                            <p:inputText id="email" required="true" label="email" size="40"
                                         requiredMessage="Please enter your email address."
                                         validatorMessage="Invalid email format"
                                         value="#{bank.vendor_email}">

                                <f:validateRegex
                                    pattern="^[_A-Za-z0-9-\+]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,})$" />

                            </p:inputText>
                            <p:message for="email" />

                            <p:outputLabel value="Vendor Phone Number " for="pnum"/>
                            <p:inputText id="pnum" required="true" value="#{bank.vendor_phone}" requiredMessage="Phone number required" />
                            <p:message for="pnum"/>

                            <p:commandButton value="save" process="@this vname,bank,anum,adress,email,pnum" update=":templateForm:growl,singleTB,ven" actionListener="#{bank.insertData}" />

                        </h:panelGrid>
  <p:dataTable var="ven_tab" id="singleTB"
                                         value="#{bank.vendorList}" 
                                         rowKey="#{ven_tab.id}"
                                         selection="#{bank.selectedList}" selectionMode="single"
                                         rows="10"                                        
                                         editable="true"                                         
                                         paginatorTemplate="{CurrentPageReport}  
                                         {FirstPageLink} {PreviousPageLink} 
                                         {PageLinks} {NextPageLink} {LastPageLink} "
                                         paginator="true" style="margin-bottom:20px"
                                         rowsPerPageTemplate="5,10,15">

                                <p:ajax event="rowEdit" listener="#{bank.onRowEdit}" update=":templateForm:growl" />
                                <p:ajax event="rowEditCancel" listener="#{bank.onRowCancel}" update=":templateForm:growl" />

                                <p:column>
                                    <f:facet name="header">
                                        <h:outputText value="Vendor Id"/>
                                    </f:facet>

                                    <h:outputText value="#{ven_tab.vendorId}"/>

                                </p:column>

                                <p:column>

                                    <f:facet name="header">
                                        <h:outputText value="Vendor Name"/>
                                    </f:facet>
                                    <p:cellEditor>
                                        <f:facet name="output"><h:outputText value="#{ven_tab.vendorName}"/></f:facet>
                                        <f:facet name="input"><p:inputText value="#{ven_tab.vendorName}"  required="true"  requiredMessage="Name is required" style="width:96%"/></f:facet>
                                    </p:cellEditor>


                                </p:column>

                                <p:column>

                                    <f:facet name="header">
                                        <h:outputText value="Vendor Phone Number"/>
                                    </f:facet>
                                    <p:cellEditor>
                                        <f:facet name="output"><h:outputText value="#{ven_tab.vendorPnum}"/></f:facet>
                                        <f:facet name="input"><p:inputText value="#{ven_tab.vendorPnum}" required="true" requiredMessage="Phone is required" style="width:96%"/></f:facet>
                                    </p:cellEditor>


                                </p:column>

                                <p:column>

                                    <f:facet name="header">
                                        <h:outputText value="Vendor Email"/>
                                    </f:facet>

                                    <p:cellEditor>
                                        <f:facet name="output"><h:outputText value="#{ven_tab.vendorEmail}"/></f:facet>
                                        <f:facet name="input"><p:inputText required="true" value="#{ven_tab.vendorEmail}" requiredMessage="Email is required" style="width:96%"/></f:facet>
                                    </p:cellEditor>


                                </p:column>
                                <p:column>

                                    <f:facet name="header">
                                        <h:outputText value="Vendor Contact Address"/>
                                    </f:facet>

                                    <p:cellEditor>
                                        <f:facet name="output"> <h:outputText value="#{ven_tab.vendorContact}"/></f:facet>
                                        <f:facet name="input"><p:inputText required="true" value="#{ven_tab.vendorContact}" requiredMessage="Contact is required" style="width:96%"/></f:facet>
                                    </p:cellEditor>


                                </p:column>
                                <p:column>

                                    <f:facet name="header">
                                        <h:outputText value="Vendor Bank"/>
                                    </f:facet>

                                    <p:cellEditor>
                                        <f:facet name="output"> <h:outputText value="#{ven_tab.vendorBank}"/></f:facet>
                                        <f:facet name="input">  
                                            <p:selectOneMenu id="bank" style="width:100%" value="#{ven_tab.vendorBank}" required="true" requiredMessage="Bank required">

                                                <f:selectItem itemLabel="--Select Bank--" itemValue="" noSelectionOption="true"/>
                                                <f:selectItems value="#{bank.bankmodel}"
                                                               var="singlevalue"  
                                                               itemLabel="#{singlevalue.bankName}"
                                                               itemValue="#{singlevalue.bankName}"/>
                                            </p:selectOneMenu></f:facet>
                                    </p:cellEditor>
                                </p:column>
                                <p:column>
                                    <f:facet name="header">
                                        <h:outputText value="Vendor Account Number"/>
                                    </f:facet>
                                    <p:cellEditor>
                                        <f:facet name="output"> <h:outputText value="#{ven_tab.vendorAcct}"/></f:facet>
                                        <f:facet name="input"><p:inputText required="true" value="#{ven_tab.vendorAcct}" requiredMessage="Account is required" style="width:96%"/></f:facet>
                                    </p:cellEditor> 
                                </p:column>
                                <p:column style="width:32px">
                                    <p:rowEditor   />
                                </p:column>


                            </p:dataTable> 

                            <h3>Export Page Data Only</h3>
                            <p:contextMenu for="singleTB" rendered="#{bank.status}" >
                                <p:menuitem value="Delete" process="@this singleTB" update=":templateForm:growl,singleTB" icon="ui-icon-close" actionListener="#{bank.deleteCar}"/>
                            </p:contextMenu>
                            <h:commandLink>
                                <p:graphicImage value="/images/excel.png" />
                                <p:dataExporter type="xls" target="singleTB" fileName="report" pageOnly="true"/>
                            </h:commandLink>

                            <h:commandLink>
                                <p:graphicImage value="/images/pdf.png" />
                                <p:dataExporter type="pdf" target="singleTB" fileName="report" pageOnly="true" />
                            </h:commandLink>

                            <h:commandLink>
                                <p:graphicImage value="/images/csv.png" />
                                <p:dataExporter type="csv" target="singleTB" fileName="report" pageOnly="true" />
                            </h:commandLink>

                            <h:commandLink>
                                <p:graphicImage value="/images/xml.png" />
                                <p:dataExporter type="xml" target="singleTB" fileName="report" pageOnly="true" />
                            </h:commandLink>

请协助。我一直试图解决这个问题,并继续得到同样的结果。感谢

1 个答案:

答案 0 :(得分:1)

JSF有6个生命周期阶段。其中之一是Process Validation阶段。在该阶段,进行输入组件(例如,输入字段)的验证。在您的情况下,您不希望进行验证。所以你要做的是在命令链接组件中添加immediate属性:

<h:commandLink immediate="true">
    <p:graphicImage value="/images/excel.png" />
    <p:dataExporter type="xls" target="singleTB" fileName="report" pageOnly="true"/>
</h:commandLink>

通过此设置,将跳过Apply Request ValuesRender Response阶段之后的所有生命周期阶段。