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

apex:inputFile can not be used in conjunction with an action component...

Hi all,


I have a problem about upload file using apex:InputFile control, when i add this control (apex:InputFile) to form that uses renderer attribute, there is an error occurs:

apex:inputFile can not be used in conjunction with an action component, apex:commandButton or apex:commandLink that specifies a rerender or oncomplete attribute


Pls help me to solve this problem. 


The error says it all, remove the rerender (and oncomplete if applicable) attribute or move the inputFile to another page with a form that doesn't have rerender/oncomplete on the action.


hi mtbclimber,


In my busines, customer want to use ajax and upload file in only one Visual page.


I also try to move upload file to another page, and in main page i use <apex:include> but that error still orcurs.


So, how to solve????


I didn't mean to suggest you drop to an include. I meant you can either use rerender or you can use inputfile. They can not be used together, as the error states.


If you want to maintain the appearance of partial page updates the only real solution is to use an iframe but in the end there is no solution here technically besides doing a full page refresh.


There is another way I've used in the past, but it breaks a best practice rule.  Create another apex:form, put your inputfile inside of it, change the target on the form to an invisible iframe.  Have the iframe load to another page that calls a method for refreshing the file list on the parent frame (parent.refreshAttachments), etc.


I wish there was a parameter on the inputfile to prevent full page rerender.  Then we could at least trigger something onclick to refresh the attachments.



By wrapping this in actionRegion, it seems to work. Is this officially unsupported?


I have a selectRadio with actionSupport.  If some of the options are selected, I require an attachment (inputFile) - so I want to refresh the page.


If I wrap selectRadion with actionRegion, it works...if not, I get the message in this thread.







I think it's in a gray area.  Developer support will always mention this if they see two forms.  It's not the best practice because it creates two copies of the viewstate.  I can say I've successfully run a VisualForce page like this with 220 active users using it 24x5 (around 80 using it concurrently at a time), without any issues from it.  In my new version I moved to an iframe that auto-resizes.  I had a use for a few of these iframes though so that is the reason I went that route.


I mis-read your reply.  I think that method is the preferred way to handle inputfile on a form with re-rerendering.  I've sent you an example our company uses in production over PM for attaching files on a form that has re-rendering components.




Thanks Richard. I just sent you a note back through the private message.




I'm having the same problem. Is it possible for you to post the example here or send it to me directly. Have to upload a file but not refresh the entire page.





Here is pseudocode. Essentially, if the user selects certain options in select Radio, the inputfile is shown, else it is not.

Wrapping selectRadio with action Region works, else you get the error.



<pageBlock id = "xyz">
<apex:actionRegion >
<apex:selectOptions />
   <apex:actionSupport rerender = "xyz"/>
<apex:outputPanel rendered= "condition under which to allow attachment" >
<apex:inputFile id="uploadFile">





I've tried this but it's still not working. I was looking for the hidden iframe solution. 


Hi Akki,

Any possible solution for this ? Please share


Havent been able to come up with a solution yet, after the inputFile, my entire visualforce page is refreshed.

erai yoshinagaerai yoshinaga

Maybe my way to avoid the same error  will be helpful for you.


please check following point with consideration of sample code

1.control the inputfile component to be shown

    To show them after a button click and to hide them before next page rendering

2. do not use rerender attribute on the second button.

   I am not sure about the reason. but my code work wery well


Page block :
        <!-- attachment erea   --> 
        <apex:pageBlock title="attachment" id="fileblock">
          <apex:pageBlockSection showHeader="true" title="File List" columns="4" id="Innfileblock">
                <apex:pageBlockTable value="{!erAttachInn}" var="file">
                    <apex:column >
                        <apex:commandbutton action="{!deleteAttachFile}" value="delete" reRender="Innfileblock">
                             <apex:param name="afparam1" value="{!}" assignTo="{!attachIdTodel}"/>
                             <apex:param name="afparam2" value="erinn" assignTo="{!attchdomain}"/>
                    <apex:column value="{!}"/>
                    <apex:column value="{!file.description}"/>
                    <apex:column >
                         <apex:outputLink value="/servlet/servlet.FileDownload?file={!}" id="theLink" target="_blank">⇒view this file</apex:outputLink>

          <apex:pageBlockSection showHeader="true" title="new file erea " columns="4" id="Newfileblock">
               <apex:panelGrid id="newfilepanel" columns="1">
                 <apex:commandbutton action="{!addnewfile}" styleclass="button1" value="show new file component" reRender="fileblock" rendered="{!loadstep='step1'}">
                 <apex:commandbutton action="{!decidenewfile}" styleclass="button2" value="add this file to list"  rendered="{!loadstep='step2'}" >
          <apex:pageBlockSection showHeader="false" columns="2" id="fileselect" rendered="{!loadstep='step2'}">
            <apex:pageBlockSectionItem >
                <apex:outputLabel value="domain" for="attachdomain"/>
                <apex:selectRadio value="{!newfile.attachdomain}" id="attachdomain">
                    <apex:selectOption itemValue="erInn" />
                    <apex:selectOption itemValue="erOut"/>
                    <apex:selectOption itemValue="ea" />
            <apex:pageBlockSectionItem >
              <apex:outputLabel value="file name" for="fileName"/>
              <apex:inputText value="{!}" id="fileName"/>
            <apex:pageBlockSectionItem >
              <apex:outputLabel value="file" for="file"/>
              <apex:inputFile value="{!newfile.attachment.body}" filename="{!}" id="file"/>
            <apex:pageBlockSectionItem >
              <apex:outputLabel value="description " for="description"/>
              <apex:inputTextarea value="{!newfile.attachment.description}" id="description"/>

Part of controller
    // to show the inputfile component
    public void addnewfile() 
        newfile=new AttachmentController();

    // to add the new file to list
    public void decidenewfile() 



Hey  ,



Can you please post the Complete Controller code. 


Thanks In Advance.



Ragava reddyRagava reddy

You have to use form tag before input file section <apex:form>, please try it once,

put remaining code
     <apex:form >
        <apex:outputpanel id="selobjren">
        <apex:outputpanel rendered="{!secondsecren == true}">
                <apex:inputFile value="{!BlobFile}" filename="{!RecordsInTheFile}" accept=".csv" />
                <apex:commandButton value="Map Values" action="{!objrelatedfields}" reRender="selfieldren"/>

Raghavendra Reddy.D

Luke J FreelandLuke J Freeland
My workaround is to have a second form on the page that contains the upload UI and then use Javascript to move it to the desired location on the page. This worked for me with the existing AJAX and was simpler than creating a separate visualforce page and using iFrames.

Note: Unfortunately, nesting an apex:form inside another apex:form doesn't compile.
Jakub SchonJakub Schon

Why you don't use apex:actionRegion? 

I had similar problem. Then I wrapped everything that I need to have an rerender attribute on with apex:actionRegion and I'm fine. 

The apex:actionRegion solution worked perfectly for me; thank you Go Force Go