function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
B2000B2000 

Inputfile Popup Window Causing Parent Window to Not Display Entire Page

My goal is to have a section on my page to collect and save an attachment to a custom object and also list all the attachments.  

 

The main page has many reRenders which resulted in an error message stating: apex:inputFile can not be used in conjunction with an action component, apex:commandButton or apex:commandLink that specifies a rerender or oncomplete.  I've read all the current posts on this board and saw two options: 1) create a hidden iframe (was not sure how to do this) 2. Create a popup window.  I used some code posted on the board to create a popup window that uses the inputfile and two buttons, one to save the file and the second to refresh the parent window and close the popup.  The code appears to work fine, but, on the main page when I click on any button (SAVE that does a reRender) below the pageblock section that opens the popup window, the entire page below the popup window pageblock disappears.  I moved the attachment pageblock to the bottom of the page and everything displays correctly.  Any ideas on why the pageblock sections below the popup window section disappear?  Thanks.

 

MAIN PAGE

        <apex:actionFunction name="refreshAttList" reRender="attList"/>

        <!-- SEVERAL pageBlocks here -->

        <apex:pageblock rendered="{!AND(terFlag,NOT(hideTerPlanFlag),displaySection=null,
            territoryPlan!='new',territoryPlan!='none',territoryPlan!=null)}" id="TPAttch" >
            <table>
                <tr>
                    <td>
                        <apex:outputText value="Attachments" />
                    </td>
                    <td>
                        <apex:commandButton value="Save" action="{!saveTPButton}"  
                            rendered="{!AND(isOwner,newTerPlan.Status__c!='Submitted')}"
                            reRender="TPAttch"  style="color:#1797C0;" status="TPAttchStatus"/>

                       <apex:commandButton onclick="window.open('/apex/ATPAddAttachmentPage?id={!territoryPlan}','Add Attachment', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,width=500,height=100,left = 480,top = 300');"  
                            value="Add Attachment"   
                            rendered="{!IF(AND(isOwner,newTerPlan.Status__c!='Submitted', territoryPlan!='new'),true,false)}"
                            style="color:#1797C0;" />
                    </td> 
                    <td>
                        <apex:actionStatus startText=" (Saving......)" startStyle="color:{!secHdrColor};font-weight:bold;" 
                            id="TPAttchStatus"/>
                        <apex:actionStatus startText=" (Updating……)" startStyle="color:{!secHdrColor};font-weight:bold;" 
                            id="TPAttchUpdateStatus"/>
                    </td>
                </tr>
            </table>

            <apex:pageBlockSection title="Attachment List" id="attList">
            <!-- TABLE OF ATTACHMENTS HERE -->
            </apex:pageBlockSection >
        </apex:pageblock>

        <!-- MANY pageBlocks here that disappear-->

POPUP PAGE
<apex:page controller="ATPAddAttachment" title="Add Attachment" showHeader="false">

<apex:form title="Add Attachment" >
    <h1>Add Attachment</h1>
    <apex:pageBlock >
        <apex:inputFile value="{!attch.Body}" fileName="{!attch.Name}" />
        <br/>
        <apex:commandButton action="{!saveAttachmentButton}" value="Save" rendered="{!!attchFlag}"/>
        <apex:commandButton value="Return" onclick="window.opener.refreshAttList();window.close();" rendered="{!attchFlag}"/>
    </apex:pageBlock>          
</apex:form>
</apex:page>

POPUP CLASS
public with sharing class ATPAddAttachment 
{
  Public Attachment attch          {get;set;}
  public Boolean attchFlag        {get;set;}  
  public ATPAddAttachment()
  {
    attch   = new Attachment(ParentId  = ApexPages.currentPage().getParameters().get('id'));
    attchFlag  = false;
  }    
  public void saveAttachmentButton()
  {
    try
    {insert attch;}
    catch (system.Dmlexception e){}
    finally{attch.Body=null;}    
    attchFlag = true;
  }
}

 

joshbirkjoshbirk

So to be clear, it's not:

 

<apex:commandButton value="Save" action="{!saveTPButton}"  
                            rendered="{!AND(isOwner,newTerPlan.Status__c!='Submitted')}"
                            reRender="TPAttch"  style="color:#1797C0;" status="TPAttchStatus"/>

 

That you click and makes thing disappear below the shown pageblock, but commandButtons below this section?  Are they rerendering the whole page or just sections?

 

If it is specifically things below this pageblock, and hence putting it to the bottom of the page - it kinda seems like something with how that pageBlock is getting re/rendered is breaking the HTML somehow ... but that is somewhat difficult to do in VF.

B2000B2000

Correct. It is not this commandButton, but an identical commandButton in every pageBlock section below the Popup Window pageBlock section that results in the partial page disappearing.  Each pageBlock section has a SAVE commandButton that does a mass save of all the fields and objects, then reRenders that specific pageBlock section.  When the Popup's RETURN button is clicked, the main page attachment list table is updated and the popup window closes.  The whole main page is displayed correctly.  If I select any SAVE button from a  pageBlock below the Popup Window pageblock section, the entire page below the Popup Window's pageBlock section disappears.  However, moving the Popup Window pageBlock as the last pageBlock in the form has no ill effect as there are no pageBlocks below.

joshbirkjoshbirk

It sounds like something in the dynamic text the popup window rerenders on the main page is breaking the remaining page structure.  I'd try going through the flow you describe in a browser with a good web inspector like Chrome and trying to determine the structure of the HTML in that state.