I have a page with uploading document form, I followed this example but I got a problem when I try to upload the file with the following error message Required fields are missing: [Document Name]
And here is my VF code
<apex:pageBlock title="Scan Document" >
<apex:form id="scanDocumentTabForm" enctype="multipart/form-data">
<apex:pageBlockSection columns="1" >
<apex:inputText value="{!document.name}"
id="fileName"/>
<apex:inputFile value="{!document.body}"
filename="{!document.name}"
id="file"/>
<apex:inputField label="Description" value="{!document.description}"/>
<apex:actionRegion >
<apex:commandButton value="Upload File"
action="{!saveDocument}"
reRender="documentsTableForm"
status="getDoc"/>
</apex:actionRegion>
</apex:PageBlockSection>
<apex:actionStatus startStyleClass="loading"
stopStyleClass="unload"
id="getDoc"/>
<apex:pageMessages />
<apex:pageBlockSection >
<apex:panelGroup id="documentsTable">
<apex:pageBlockTable value="{!documents}" var="doc" >
// table content ..
<!-- This is the dynamic reference part -->
</apex:pageBlockTable>
</apex:panelGroup>
</apex:pageBlockSection>
</apex:form>
</apex:pageBlock>
And this is the Controller Code
public Document document {get; set;}
public MyController (){
document = new Document();
}
public pageReference saveDocument() {
document.AuthorId = UserInfo.getUserId();
document.FolderId = UserInfo.getUserId();
try {
insert document;
} catch (DMLException e) {
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading file'));
return null;
} finally {
document.body = null; // clears the viewstate
document = new Document();
}
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'File uploaded successfully'));
return null;
}
Best Answer
Re-render don't work with
<apex:input>
but there is is no problem in page reload. On page refresh no information lost and data changes during action method call these details can be used on pageHere is an example using above sample code:
Page: