I have done exactly the same but i am getting the following error: Please suggest
apex:inputFile can not be used in conjunction with an action component, apex:commandButton or apex:commandLink that specifies a rerender or oncomplete attribute.
The error looks pretty complete to me - this won't work because you are using an inputfile component. I'd imagine this is down to the browser protection of file input - its highly inaccessible to scripting etc as that would allow a malicious page to upload files from the user's operating system.
You'd make sure the pageblock has an id, then in your actionfunction/commandbutton/commandlink, you'd specify the rerender attribute.
I have done exactly the same but i am getting the following error: Please suggest
apex:inputFile can not be used in conjunction with an action component, apex:commandButton or apex:commandLink that specifies a rerender or oncomplete attribute.
below is my visualforce code:
<apex:page standardController="opportunity_proposals__c" extensions="AttachmentUploadController">
<apex:form >
<apex:pageMessages />
<apex:pageBlock title="Upload an Attachment" id="test">
<apex:pageBlockButtons >
<apex:commandButton action="{!upload}" value="Save" rerender="test"/>
<apex:commandButton action="{!cancel}" value="Cancel"/>
</apex:pageBlockButtons>
<apex:pageBlockSection showHeader="false" columns="2" id="block1">
<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"/>
</apex:pageBlockSectionItem>
<apex:outputLabel value="Description" for="description" rendered="true"/>
<apex:inputCheckbox value="{!opportunity_proposals__c.Attachment__c}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
The error looks pretty complete to me - this won't work because you are using an inputfile component. I'd imagine this is down to the browser protection of file input - its highly inaccessible to scripting etc as that would allow a malicious page to upload files from the user's operating system.
Put the section that you want to rerender inside the apex:outputPanel like here inside content is apex:pageBlock.
You can rerender this apex:outputPanel from actionFunction, actionSupport, commandButton and from many more VF components.
Find below a Sample Code :
<apex:page standardController="Account">
<apex:form>
<apex:outputPanel>
<apex:pageBlock title="My Content">
<apex:pageBlockSection title="My Content Section" columns="2">
<apex:inputField value="{!account.name}"/>
<apex:inputField value="{!account.site}"/>
<apex:inputField value="{!account.type}"/>
<apex:inputField value="{!account.accountNumber}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:outputPanel>
<apex:commandButton value="Test" action="{!test}" rerender="out" status="status"/>
</apex:form>
</apex:page>
This won't change the fact that the form contains an inputfile so I'd expect to receive the error message again.