+ Start a Discussion
Sure@DreamSure@Dream 

required="true" for apex:inputFile

Hi All,

I have used required="true" for apex:inputFile.
On click of a custom button, I am trying to upload that file.

But even if its required="true", the controller method is getting called and null pointer exception is being thrown.

We cannot keep rerender in conjuction with rerender attribute. So I am not keeping rerender for this button.

How can check whether a file is selected or not?
Vinit_KumarVinit_Kumar
Can you post your code,it's still not clear to me ??
kevin Carotherskevin Carothers
Hi Sure@dream,

I tried setting up a simple doc upload and when the doc was blank, the controller threw an error onto my VF page.
The code I used to try to duplicates your problem (although there is no code to duolicate agains) was as follows;

VF page;
<apex:page standardController="Document" extensions="UploaddocumentExt">
    <apex:messages />
    <apex:form id="theForm">
      <apex:pageBlock >
          <apex:pageBlockSection >
            <apex:inputFile required="true"  value="{!document.body}" filename="{!document.name}"/>
            <apex:commandButton value="Save" action="{!save}"/>
          </apex:pageBlockSection>
       </apex:pageBlock>
    </apex:form>
</apex:page>

Controller;

public class UploaddocumentExt {
    public UploaddocumentExt(ApexPages.StandardController controller) {
        Document d = (Document) controller.getRecord();
        d.folderid = UserInfo.getUserId(); //this puts it in My Personal Documents
    }                 
}

This code shows the following errors when you don't specify a file;
User-added image
With "Required="true"  the message in the red rectangle appears.  Without the "required" tag just the message below the rectangle is showing.
Can you give some more detail?