I am rendering <apex:inputfile> by adding a new row but I am losing file when I click add row button. I am able to add a new row but the path is lost.

Please help!

<apex:repeat value="wraperList" var="wr" id="repeatId">
    <apex:inputFile value="{!wr.Filedata}"/>
<apex:commandbutton value="Add Row" action="{!AddRow}" reRender="repeatId"/>



public List<wrapperClass> wraperList{get;set;} 
    public class wrapperClass{ 
        public hour__c hrIns{get;set;}
        Public blob fileData{get;set;} 
        public wrapperTimeCardClass(hour__c hrins)


Add row Method
public void addRow(){
    wraperList.add(new wrapperClass(new hour__c()));
  • It would be very helpful to see your controller code to understand the methods in what appears to be a wrapper class. I strongly suspect the class is being re-queried which could be at the root of your problem. It all depends on the methods used to add the row to it. – crmprogdev Jul 4 '15 at 15:56
  • I have updated my code.Did you get it now?I have not pasted all the code but some? – miku Jul 4 '15 at 16:23
  • What you've uploaded doesn't point me to anything useful. I suggest you upload the entire class. I'm confident there are many methods, any of which could be related to adding a "row". I may not be the one who'll have the solution to your question. I'm only pointing out that anyone who can help you, will need to see the methods in your controller. – crmprogdev Jul 4 '15 at 16:36
  • I have updated it again.Please see – miku Jul 4 '15 at 16:38

This method below:

Add row Method
public void addRow(){
    wraperList.add(new wrapperClass(new hour__c()));

is causing the public class wrapperClass method to totally re-calculate or refresh itself when you add the row; creating a new wrapper class when the row is added.

You're losing the old path because what was previously held in the controller no longer exists once that happens.

  • Then how should i solve this,Can you please help.? – miku Jul 4 '15 at 17:07
  • As i am adding a new row..The previous row should stay as it is.??What that is losing the path..All the variable stay as it is and dont lose the value..Just inputfile lose the path....? – miku Jul 4 '15 at 17:09
  • You didn't include the code for your entire page, so I don't know what controls the rest of the page. All I can tell you is that the entire wrapper class is recalculated when you add a row to it and the contents of the controller you've posted are lost. Post the rest of your page and it might tell me more. If there's a different controller for the page, please post the code for it too. I can only answer questions based on the information you provide. – crmprogdev Jul 4 '15 at 17:33
  • I'll add it's possible there's something wrong with the syntax in reRender="repeatId" of the <apex:commandbutton> statement that's causing the problem. The controller does cause the wrapper class to recalculate and the page needs to reRender based on that Id, but with more rows. Whether that's the proper way to call, may be worth checking in the VF Docs. I don't have time at the moment. – crmprogdev Jul 4 '15 at 17:50
  • reRender refers to the ID of one or more components that are redrawn when the result of an AJAX update request returns to the client. This value can be a single ID, a comma-separated list of IDs, or a merge field expression for a list or collection of IDs. I think you need to use a reference to the recordId for the page, not the repeatId. – crmprogdev Jul 4 '15 at 18:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.