I have a VF page to create the cases and to insert the attachments to case.On Changing the picklist values i have to rerender the entire page to enter new values. But I have a inputfile tag in the VF page which doesn't support rerender. How to resolve it?
[SalesForce] How to resolve a inputfile rerender problem
Related Solutions
You need to rerender something that surrounds the item that needs to appear and disappear.
In your case, since there are two children of your page block section, I would rerender that, rather than do a whole bunch of individual items within. Like this:
<apex:pageBlock mode="edit" title="Required Fields on Account">
<!--tell VF to rerender this parent UI section
this will rerender all children as well, instead of bits and pieces here and there-->
<apex:pageBlockSection id="areaToReRender" columns="1">
<apex:pageBlockSectionItem>
<apex:outputLabel value="Buyer Segment"/>
<apex:actionRegion >
<apex:inputField value="{!Account.Buyer_Segment__c}">
<!--you already get how this works, but for clarity to others who read
this, "reRender" identifies the component ID to rebuild cascading to all children-->
<apex:actionSupport event="onchange" reRender="areaToReRender"/>
</apex:inputField>
</apex:actionRegion >
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem rendered="{!IF(Account.Buyer_Segment__c = $Label.Acct_BuySeg1,TRUE,FALSE)}">
<apex:outputLabel value="Vertical"/>
<apex:inputField value="{!Account.Industry}" />
</apex:pageBlockSectionItem>
...Other pageBlockSectionItems here...
</apex:pageBlockSection>
I've not tested this, and it has been a while since I used this, but when I did, if an item was ever conditionally rendered, I often had trouble unless I pointed the rerender on a component at least one level above the conditional component. And here, since you clearly want the label to refresh, too, might as well just do a parent and get the refresh to include both children.
Do something like this:
Visualforce Page:
<apex:pageBlockButtons >
<apex:commandButton action="{!upload}" value="Save"/>
</apex:pageBlockButtons>
<apex:pageBlockSection showHeader="false" columns="2" id="block1">
<apex:pageBlockSectionItem >
<apex:outputLabel value="File Name" for="fileName"/>
<apex:inputText value="{!attachment.name}" id="fileName"/>
</apex:pageBlockSectionItem>
<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:pageBlockSection>
</apex:pageBlock>
Controller:
public with sharing class AttachmentUploadController {
public Attachment attachment {
get {
if (attachment == null)
attachment = new Attachment();
return attachment;
}
set;
}
public PageReference upload() {
attachment.OwnerId = UserInfo.getUserId();
attachment.ParentId = '0012800000iCVLi'; // the record the file is attached to
attachment.IsPrivate = true;
try {
insert attachment;
} catch (DMLException e) {
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading attachment'));
return null;
} finally {
attachment = new Attachment();
}
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Attachment uploaded successfully'));
return null;
}
}
Best Answer
Rerendering is not supported when you have an apex:inputFile component. There's no workaround, as the platform simply will not allow it. The best you can do is to move the apex:inputFile into an apex:iframe which will leave the rest of the "page" alone.
BTW If you are looking to rerender the entire page, that sounds the same as a refresh.