rich:fileupload in rich:popupPanel 第一次失败,在大页面中

rich:fileupload in rich:popupPanel fails first time, in a large page

我在 XHTML 的底部有 rich:datatable 和一堆按钮。我使用其中一个按钮显示 rich:popupPanel 来上传文件。我根据之前的建议将 rich:popupPanelrich:fileUpload 分成了不同的形式。

第一种形式:

<h:form id="form" enctype="multipart/form-data">
    <h:panelGrid columns="1" columnClasses="valign">

        <rich:messages/>

        <rich:panel style="width:1100px;">                  
            <f:facet name="header">
                <h:outputText value="MRM Segments" />
            </f:facet>

            <rich:dataTable value="#{couponController.campaignSegmentDtoList}"
                var="campaignSegment" id="sas" rowClasses="odd-row, even-row"
                styleClass="stable" sortMode="single" rowKeyVar="myrow" onrowclick="myFunction()">

                <rich:column>
                    <f:facet name="header">No</f:facet>
                    <h:outputText value="#{myrow + 1}" />
                </rich:column>

                <!-- snipped -->

            </rich:dataTable>

            <script>
                //<![CDATA[
                function updateNumbers() {
                    var a = document.getElementById('form:sas:tb');
                    for (var i=0; i < a.children.length; i++) {
                        a.children[i].children[0].innerHTML = i + 1;
                    }
                }   
                //]]>
            </script>

            <a4j:outputPanel ajaxRendered="true">
                <rich:popupPanel id="confirmPaneStatus" autosized="true" header="Confirm">
                    <table border="0" cellspacing="0" cellpadding="0">
                        <tr><td colspan="3">Are you sure you want to set all
                            segments with numeric names as Inactive ?</td></tr>
                        <tr><td colspan="3"><br/></td></tr>
                        <tr><td align="right">
                            <a4j:commandButton value="Cancel"
onclick="#{rich:component('confirmPaneStatus')}.hide(); return false;" />
                        </td><td align="left">
                            <a4j:commandButton value="Update"
onclick="#{rich:component('confirmPaneStatus')}.hide(); updateStatus(); return false;" style="margin-left:15px"/>
                        </td></tr>  
                    </table>
                </rich:popupPanel>
            </a4j:outputPanel>

            <a4j:outputPanel ajaxRendered="true">
                <rich:popupPanel id="errorPane" autosized="true" header="Error" >
                    <table border="0" cellspacing="0" cellpadding="0">
                        <tr><td colspan="3">Only .xlsx files are accepted</td></tr>
                        <tr><td colspan="3"><br/></td></tr>
                        <tr><td align="right">
                            <a4j:commandButton value="Close" onclick="#{rich:component('errorPane')}.hide();" />
                        </td></tr>  
                    </table>
                </rich:popupPanel>
            </a4j:outputPanel>                                                              

            <a4j:jsFunction name="updateStatus"
                action="#{couponController.updateCampaignSegmentDtoListWithSegmentStatus()}"
                render="sas" immediate="true"/>
            <a4j:jsFunction name="sort" oncomplete="updateNumbers()" />

        </rich:panel>
    </h:panelGrid>

    <h:panelGrid columns="7">
        <a4j:commandButton value="Apply Segment Type"  render="sas"
            action="#{couponController.updateCampaignSegmentDtoListWithSegmentType()}"
            execute="@form" style="width:140px;height:30px;"/>
        <a4j:commandButton value="Apply Segment Status" render="sas"
            execute="@form" style="width:150px;height:30px;">
            <rich:componentControl target="confirmPaneStatus" operation="show"/>
        </a4j:commandButton>
        <a4j:commandButton value="Upload Segment Names" execute="@none" 
            style="width:160px;height:30px;">
            <rich:componentControl target="uploadSegmentNames"
                operation="show" />
        </a4j:commandButton>
        <a4j:commandButton value="Save"  render="sas"
            action="#{couponController.saveCampaignSegmentsReadyToPublish()}" 
            execute="@form" style="width:78px;height:30px;"/>
        <a4j:commandButton value="Publish"  render="sas"
            action="#{couponController.publishCampaignSegmentsReadyToPublish()}"
            execute="@this" style="width:78px;height:30px;"/>
        <a4j:commandButton value="Re-Publish"  render="sas"
            action="#{couponController.rePublishCampaignSegmentsReadyToPublish()}"
            execute="@this" style="width:78px;height:30px;"/>
        <h:commandButton onclick="location.href='CampaignsVersions.jsf';return false;"
            value="Cancel" style="width:78px;height:30px;"></h:commandButton>
    </h:panelGrid>

    <rich:popupPanel id="statPane" autosized="true">
        <h:graphicImage value="/images/please_wait.gif" alt="pw" />
        Please wait...
    </rich:popupPanel>

    <script type="text/javasript">
        $(window).load(function() {
            // Animate loader off screen
            $(".statPane").fadeOut("slow");;
        });
    </script>
</h:form>

第二种形式:

<h:form id="uploadForm" enctype="multipart/form-data">
    <a4j:outputPanel ajaxRendered="true">
        <rich:popupPanel id="uploadSegmentNames" modal="true" autosized="true" 
            header="Upload Names File" domElementAttachment="parent">

            <rich:messages/>
            <rich:panel style="width:400px;height:300px;">
                <table border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td colspan="3">
                            <rich:fileUpload id="upload" acceptedTypes="xlsx"
                                fileUploadListener="#{couponController.fileUploadListener}" 
                                immediateUpload="true" maxFilesQuantity="1"
                                ontyperejected="#{rich:component('errorPane')}.show();"
                                style="width:370px" addLabel="Choose File" 
                                doneLabel="Upload Complete" execute="@none"
                                serverErrorLabel="Error, please close the upload window and try again"> 
                            </rich:fileUpload>
                        </td>
                    </tr>
                    <tr><td colspan="3"><br/></td></tr> 
                </table>
            </rich:panel>
            <h:panelGrid columns="2" style="width:400px;height:20px;" align="right">
                <h:panelGrid columns="1" border="0" style="width:260px;height:20px"/>

                <h:panelGrid columns="2" border="0">
                    <a4j:commandButton value="Process" id="process"
                        action="#{couponController.processFile}" render="sas"
                        onclick="#{rich:component('uploadSegmentNames')}.hide();"
                        execute="@form" />
                    <a4j:commandButton value="Cancel" execute="@none"
                        onclick="#{rich:component('uploadSegmentNames')}.hide();" />
                </h:panelGrid>
            </h:panelGrid>

        </rich:popupPanel>
    </a4j:outputPanel>
</h:form>

Table 可能有 10 行或 350 行或介于两者之间。问题是 table 很大时,第一次上传失败。如果我关闭上传弹出窗口并重试。有用。这只发生在 big table 上。非常感谢您的帮助。

我正在使用 Tomcat 7 和 Richfaces 4.5.1。

已解决。 table 越大,计算的 ViewState 就越大。我通过调试上传 XMLHttpRequest url 并比较两种情况(小 table 和大 table)注意到了这一点。将 maxHttpHeaderSize 增加到 65536 解决了这个问题。我的状态保存方法是'client'.