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
sfdc franklinsfdc franklin 

How to handle the Rerender attribute in the Apex:input file got stucked

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



Source code:


 
<apex:page controller="Testcntrl" id="pg">
   <apex:form id="fm"><br/>
     <script>
     
     function ValidationJs(){
     var val= document.getElementById("pg:fm:filename").value
     
      if(val == ''){
      
          alert('Please enter filename');
       }else{
       
         SavefileActfunc();
        }
     
     }
     
     </script>

 <apex:actionFunction name="SavefileActfunc"  action="{!savefile}"  rerender="t" />
   

   
    Name:<apex:inputText id="filename" />  <br/><br/>
     <apex:inputFile value="{!csvfile}"   accept=".txt"/>
     <br/><br/>
      <apex:commandButton value="Save"  onclick="ValidationJs(); return false;"   />
   </apex:form>
</apex:page>

Controller:

 
public class Testcntrl {

  public blob csvfile{get;set;}
  public string Filename{get;set;}
  
  
  
  public void savefile(){
  
  system.debug(csvfile);
  
   }
  
}




If i remove the ReRender attribute in Actionfuction iam not getting the value as null.


If i keep the Rerender attribute in Actionfunction iam getting , rerender cannot be used in the  while using the apex:inputfile


Please suggest Your Valuables suggestions to handle it..


Thanks  and Regards
Franklin.


 

Vishwajeet kumarVishwajeet kumar
Hello,
One way to solve is move filename vailidation inside apex controller and remove the need for actionFunction.

soemthing like this : 

public class Testcntrl { public blob csvfile{get;set;}
public string Filename{get;set;}

public void savefile(){
       if(String.isBlank(Filename)){
          //Add error message to page
          return;
        }else{

         system.debug(csvfile);
    }
}

}


Page : 
<apex:page controller="Testcntrl" id="pg">
<apex:form id="fm">
<apex:pageMessages />    <!--Message display component-->
<br/> 
Name:<apex:inputText id="filename" /> <br/><br/>
<apex:inputFile value="{!csvfile}" accept=".txt"/> <br/><br/>
<apex:commandButton value="Save" action="{!savefile}" />     <!-- Call saveFile -->
</apex:form>
</apex:page>


Thanks.

 
sfdc franklinsfdc franklin
hi Vishwajeet kumar, 

 Thank you, bt i have lot mre filed level validations to handle using the javascript,  can u please provide me the solution, some told to use , action region , but i am gettng value as null when i have used the action region
any solution will be helpfull.


Thanks and regards
franklin.
Vishwajeet kumarVishwajeet kumar
Hello,
Removing reRender attribute from actionFunction should work and fix the issue, it will just reload the whole page after save action.

Below is Test code :
 
<apex:page controller="Testcntrl " id="pg">
   <apex:form id="fm"><br/>
     <script>
     
     function ValidationJs(){
     var val= document.getElementById("pg:fm:filename").value
     
      if(val == ''){      
          alert('Please enter filename');
       }else{
       
         SavefileActfunc();
        }
     
     }
     
     </script>

 <apex:actionFunction name="SavefileActfunc"  action="{!savefile}"/>   
    Name:<apex:inputText id="filename" />  <br/><br/>
     <apex:inputFile value="{!csvfile}"   accept=".txt"/>
     <br/><br/>
      <apex:commandButton value="Save"  onclick="ValidationJs(); return false;"   />
   </apex:form>
</apex:page>



Controller : 

public with sharing class Testcntrl {
    public blob csvfile{get;set;}
      public string Filename{get;set;}
  
  
  
  public void savefile(){
      Account v_Account = [select id from Account LIMIT 1];
  
      if(csvfile != Null)  {
          system.debug(LoggingLevel.ERROR, 'got the file data');
          
          Attachment v_Att = new Attachment(Name = 'Test Att.txt');
          v_Att.ParentId = v_Account.Id;
          v_Att.Body = csvfile;
          
          insert v_Att;
          
         this.csvfile = Null; 
          this.Filename = Null;
          
      }
          
     else
         system.debug(LoggingLevel.ERROR, 'Null Value');     
  
  }
}

Thanks.