1

I have an existing vf page that edits an event. I added a method to upload an attachment to the event which works fine. I can add the attachment and the page refreshes and displays the attachment as expected.

The problem is that there are other actions on the page where it rerenders after queries. When I trigger those actions I get the error: apex:inputFile can not be used in conjunction with an action component, apex:commandButton or apex:commandLink that specifies a rerender or oncomplete attribute.

I found this article that is helpful but it doesn't seem to solve my problem. I added wrapping the command button but the error still comes up.

Is there something I am doing wrong? I tacked the attachment pieces at the bottom of the class and vf page.

Page:

<apex:page standardController="Event" extensions="SL_CallReportEditController" tabStyle="Event" title="Call Report" showHeader="true" sidebar="true" action="{!checkIsUserAssignee}" >
 <apex:sectionHeader title="Call Report" rendered="{!isAssignee}"/>
 <apex:form id="formId" enctype="multipart/form-data"> 
    <apex:pageMessages />
    <apex:pageBlock id="pageblockId" title="{!account.Name} {!if(account.Segment__c != null, '('+account.Segment__c+')','')}" mode="edit" rendered="{!IF(AND(isAssignee == true,event.IsCallReport__c == true), TRUE, FALSE)}">
        <apex:actionFunction name="fetchUsersAF" action="{!fetchUsers}" rerender="attendeeSelection" oncomplete=" return false;"  status="actStatusId"/>
        <apex:inputhidden value="{!selectedAttendeeType}" id="AttendeeId"/>
        <apex:pageBlockButtons >
            <apex:commandButton value="Generate Report" action="{!doSave}"/>
            <-- !Snip -->
        </apex:pageBlockButtons>
        <apex:pageBlockSection title="Meeting Details">
            <-- !Snip -->
        </apex:pageBlockSection>
        <apex:actionRegion renderRegionOnly ="false">
            <apex:pageBlockSection title="NPD Attendees" columns="1">
                <apex:outputPanel rendered="{!IF(account.RecordType.DeveloperName!='Practice_Account', 'true', 'false')}" >
                    <input type="radio" id="accountTeamList" name="Attendee" value="Search Account Team" checked="true" onclick="setSelectedSearch(this.value);"/>
                    <label for="accountTeamList"><b>Search Account Team</b></label><br/>
                    <input type="radio" id="allNPDList" name="Attendee" value="Search All NPD" onclick="setSelectedSearch(this.value);"/>
                    <label for="allNPDList"><b>Search All NPD</b></label>
                </apex:outputPanel>
                <apex:outputPanel rendered="{!IF(account.RecordType.DeveloperName=='Practice_Account', 'true', 'false')}">
                    <input type="radio" id="accountTeamListPr" name="Attendee" value="Search Account Team" checked="true" onclick="setSelectedSearch(this.value);"/>
                    <label for="accountTeamListPr"><b>Search Account Team</b></label><br/>
                    <input type="radio" id="practiceListPr" name="Attendee" value="Search Practice" onclick="setSelectedSearch(this.value);"/>
                    <label for="practiceListPr"><b>Search Practice Members</b></label><br/>
                    <input type="radio" id="allNPDListPr" name="Attendee" value="Search All NPD" onclick="setSelectedSearch(this.value);"/>
                    <label for="allNPDListPr"><b>Search All NPD</b></label>
                </apex:outputPanel>
                <apex:actionStatus id="actStatusId" >
                    <apex:facet name="start" >
                        <img src="/img/loading.gif"/>                    
                    </apex:facet>
                </apex:actionStatus>
                <c:SL_SelectBoxes id="attendeeSelection"    leftOption="{!possibleNPDAttendees}"
                                                            rightOption="{!NPDAttendees}"
                                                            size="14"
                                                            width="350px"
                                                            height="100px"/>
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Client Attendees">
                <c:SL_SelectBoxes   leftOption="{!possibleClientAttendees}"
                                    rightOption="{!clientAttendees}"
                                    size="14"
                                    width="350px"
                                    height="100px"/>
            </apex:pageBlockSection>
        </apex:actionRegion>    
        <-- !Snip -->
        <apex:actionRegion>
            <apex:outputpanel id="absolutesection">
                <apex:pageBlockSection id="masterSection" columns="1" title="Follow Up Actions" rendered="{!wrappersDisplayed.size>0}">
                    <apex:variable value="{!1}" var="rowNum"/>
                    <apex:repeat id="theRepeat" value="{!wrappersDisplayed}" var="task">
                        <apex:pageBlockSection id="taskSection" columns="1" title="{!FLOOR(rowNum)}." collapsible="false">
                            <apex:outputPanel> 
                                <apex:variable var="rowNum" value="{!rowNum + 1}"/>
                                <apex:pageBlockSection rendered="{!!task.toDelete}">
                                    <apex:inputField value="{!task.task.Subject}"/>
                                    <apex:inputField value="{!task.task.WhoId}"/>
                                    <apex:inputField value="{!task.task.ActivityDate}"/>
                                    <apex:inputField value="{!task.task.OwnerId}"/>
                                    <apex:inputField value="{!task.task.Priority}"/>
                                    <apex:inputField value="{!task.task.Follow_Up_Action_Items__c}"/>
                                    <apex:outputText value=" "/>
                                    <apex:outputPanel rendered="{!!task.toDelete}">
                                        <apex:commandButton action="{!task.setDelete}" status="loading" value="Cancel This Item" immediate="true" reRender="absolutesection"/>
                                    </apex:outputPanel> 
                                </apex:pageBlockSection>
                            </apex:outputPanel>
                        </apex:pageBlockSection>
                    </apex:repeat>
                </apex:pageBlockSection>
            </apex:outputpanel>
        <apex:pageBlockSection columns="1">
            <apex:pageBlockSectionItem >
                <apex:commandButton action="{!addTask}" immediate="true" status="loading" value="Assign Tasks" reRender="absolutesection" />
            </apex:pageBlockSectionItem>
        </apex:pageBlockSection>
    </apex:actionRegion>
        <apex:pageBlockSection title="Upload an Attachment" columns="1">
            <apex:pageBlockSectionItem >
                <apex:outputLabel value="File" for="file"/>
                <apex:inputFile value="{!attachment.body}" filename="{!attachment.name}" id="file"/>
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem >
                <apex:outputLabel value="Description" for="description"/>
                <apex:inputTextarea value="{!attachment.description}" id="description" cols="100" rows="7"/>
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem >
                <apex:commandButton action="{!upload}" value="Save Attachment" />
            </apex:pageBlockSectionItem>
        </apex:pageBlockSection>
    <-- !Snip -->
  </apex:form>
</apex:page>

Updated vf page:

    <apex:page standardController="Event" extensions="SL_CallReportEditController" tabStyle="Event" title="Call Report" showHeader="true" sidebar="true" action="{!checkIsUserAssignee}" >
 <apex:sectionHeader title="Call Report" rendered="{!isAssignee}"/>
 <apex:form id="formId" enctype="multipart/form-data"> 
    <apex:pageMessages />
    <apex:pageBlock id="pageblockId" title="{!account.Name} {!if(account.Segment__c != null, '('+account.Segment__c+')','')}" mode="edit" rendered="{!IF(AND(isAssignee == true,event.IsCallReport__c == true), TRUE, FALSE)}">
        <apex:pageBlockButtons >
            <apex:commandButton value="Generate Report" action="{!doSave}"/>
            <-- !Snip -->
        </apex:pageBlockButtons>
        <apex:pageBlockSection title="Meeting Details">
            <-- !Snip -->
        </apex:pageBlockSection>
        <apex:actionRegion renderRegionOnly ="false">
<!-- Move this line inside the actionRegion here --> <apex:actionFunction name="fetchUsersAF" action="{!fetchUsers}" rerender="attendeeSelection" oncomplete=" return false;"  status="actStatusId"/>
<!-- Move this line here --> <apex:inputhidden value="{!selectedAttendeeType}" id="AttendeeId"/>
            <apex:pageBlockSection title="NPD Attendees" columns="1">
                <apex:outputPanel rendered="{!IF(account.RecordType.DeveloperName!='Practice_Account', 'true', 'false')}" >
                    <input type="radio" id="accountTeamList" name="Attendee" value="Search Account Team" checked="true" onclick="setSelectedSearch(this.value);"/>
                    <label for="accountTeamList"><b>Search Account Team</b></label><br/>
                    <input type="radio" id="allNPDList" name="Attendee" value="Search All NPD" onclick="setSelectedSearch(this.value);"/>
                    <label for="allNPDList"><b>Search All NPD</b></label>
                </apex:outputPanel>
                <apex:outputPanel rendered="{!IF(account.RecordType.DeveloperName=='Practice_Account', 'true', 'false')}">
                    <input type="radio" id="accountTeamListPr" name="Attendee" value="Search Account Team" checked="true" onclick="setSelectedSearch(this.value);"/>
                    <label for="accountTeamListPr"><b>Search Account Team</b></label><br/>
                    <input type="radio" id="practiceListPr" name="Attendee" value="Search Practice" onclick="setSelectedSearch(this.value);"/>
                    <label for="practiceListPr"><b>Search Practice Members</b></label><br/>
                    <input type="radio" id="allNPDListPr" name="Attendee" value="Search All NPD" onclick="setSelectedSearch(this.value);"/>
                    <label for="allNPDListPr"><b>Search All NPD</b></label>
                </apex:outputPanel>
                <apex:actionStatus id="actStatusId" >
                    <apex:facet name="start" >
                        <img src="/img/loading.gif"/>                    
                    </apex:facet>
                </apex:actionStatus>
                <c:SL_SelectBoxes id="attendeeSelection"    leftOption="{!possibleNPDAttendees}"
                                                            rightOption="{!NPDAttendees}"
                                                            size="14"
                                                            width="350px"
                                                            height="100px"/>
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Client Attendees">
                <c:SL_SelectBoxes   leftOption="{!possibleClientAttendees}"
                                    rightOption="{!clientAttendees}"
                                    size="14"
                                    width="350px"
                                    height="100px"/>
            </apex:pageBlockSection>
<!-- Close actionRegion --> </apex:actionRegion>    
        <-- !Snip -->
        <apex:actionRegion>
            <apex:outputpanel id="absolutesection">
                <apex:pageBlockSection id="masterSection" columns="1" title="Follow Up Actions" rendered="{!wrappersDisplayed.size>0}">
                    <apex:variable value="{!1}" var="rowNum"/>
                    <apex:repeat id="theRepeat" value="{!wrappersDisplayed}" var="task">
                        <apex:pageBlockSection id="taskSection" columns="1" title="{!FLOOR(rowNum)}." collapsible="false">
                            <apex:outputPanel> 
                                <apex:variable var="rowNum" value="{!rowNum + 1}"/>
                                <apex:pageBlockSection rendered="{!!task.toDelete}">
                                    <apex:inputField value="{!task.task.Subject}"/>
                                    <apex:inputField value="{!task.task.WhoId}"/>
                                    <apex:inputField value="{!task.task.ActivityDate}"/>
                                    <apex:inputField value="{!task.task.OwnerId}"/>
                                    <apex:inputField value="{!task.task.Priority}"/>
                                    <apex:inputField value="{!task.task.Follow_Up_Action_Items__c}"/>
                                    <apex:outputText value=" "/>
                                    <apex:outputPanel rendered="{!!task.toDelete}">
                                        <apex:commandButton action="{!task.setDelete}" status="loading" value="Cancel This Item" immediate="true" reRender="absolutesection"/>
                                    </apex:outputPanel> 
                                </apex:pageBlockSection>
                            </apex:outputPanel>
                        </apex:pageBlockSection>
                    </apex:repeat>
                </apex:pageBlockSection>
            </apex:outputpanel>
        <apex:pageBlockSection columns="1">
            <apex:pageBlockSectionItem >
                <apex:commandButton action="{!addTask}" immediate="true" status="loading" value="Assign Tasks" reRender="absolutesection" />
            </apex:pageBlockSectionItem>
        </apex:pageBlockSection>
    </apex:actionRegion>
        <apex:pageBlockSection title="Upload an Attachment" columns="1">
            <apex:pageBlockSectionItem >
                <apex:outputLabel value="File" for="file"/>
                <apex:inputFile value="{!attachment.body}" filename="{!attachment.name}" id="file"/>
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem >
                <apex:outputLabel value="Description" for="description"/>
                <apex:inputTextarea value="{!attachment.description}" id="description" cols="100" rows="7"/>
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem >
                <apex:commandButton action="{!upload}" value="Save Attachment" />
            </apex:pageBlockSectionItem>
        </apex:pageBlockSection>
    <-- !Snip -->
  </apex:form>
</apex:page>
  • Hi Dan. To make your question more useful, I'd suggest that you edit out most of the code so we have a short, self contained, correct example. It's a lot easier to understand the problem when there's 50 lines of code instead of the 500+ lines of code you have in this post. – sfdcfox Jul 11 '16 at 18:31
2

The actionRegion must surround areas that you want to use reRender attributes or partial page refreshes, and must not surround the apex:inputFile element. See my answer on the question you linked to for how that's supposed to work. I believe you're looking for something like the following:

<apex:pageBlock id="pageblockId" ...>
    <apex:actionRegion renderRegionOnly="false">
        <apex:actionFunction name="fetchUsersAF" action="{!fetchUsers}" rerender="attendeeSelection" oncomplete=" return false;"  status="actStatusId"/>
        <!-- snip! -->
    </apex:actionRegion>
       <apex:pageBlockSection title="Upload an Attachment" columns="1">
            <!-- snip! -->
       </apex:pageBlockSection>
</apex:pageBlock>
  • That's where I got confused on your comment on the other answer, it seemed like it was wrap actionRegion around the line that you do not want to reRender. From what you're saying it's the opposite of that. In this specific case there are 3 lines that reRender the page after some logic. I should wrap actionRegion around them and that will isolate the reRender away from the inputFile. – Dan Wooding Jul 11 '16 at 19:08
  • I couldn't put the actionRegion under the pageBlock, I get an error that page block buttons must have the direct parent be pageBlock. What I did was put the actionRegion around the pageBlockSection that does the refresh. I still get the error though. I click the radio and it tries to refresh and then error. – Dan Wooding Jul 11 '16 at 20:49
  • @DanWooding Interesting. Let me see if I can play with it. – sfdcfox Jul 11 '16 at 21:16
  • @DanWooding Looks like you snipped a bit too much code, but try this: <apex:actionRegion renderRegionOnly="false"> <apex:actionFunction name="fetchUsersAF" action="{!fetchUsers}" rerender="attendeeSelection" oncomplete=" return false;" status="actStatusId"/></apex:actionRegion> – sfdcfox Jul 11 '16 at 21:30
  • Got it! I moved the actionFunction and the input hidden lines from the top and moved them close to where I was doing the query and the refresh. This gets around the pageBlockButtons not being under the pageBlock. Finally wrapping the whole chunk with actionRegion. – Dan Wooding Jul 12 '16 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.