+ Start a Discussion
sv_159sv_159 

Dynamically adding apex:inputfile on VF page .....please suggest

Our requirement is that.

 

How to add apex:inputfile dynamically on VF page using wrapper class

 and uploaded files should save to content .

 

 

Very urgent .....

Best Answer chosen by Admin (Salesforce Developers) 
sv_159sv_159

Thanks 

All Answers

vishal@forcevishal@force

What do you mean by 'dynamically adding'? Is it showing and hiding?

sv_159sv_159

yes

vishal@forcevishal@force

I'm not sure but there's something that rerenders cannot be used with apex:inputfiles, so showing and hiding using rerenders is out of scope (as far as I know).

 

Maybe you could try using javascript.

 

Use style.display = 'none;' and style.display = 'block'; and thus show and hide the file?

Scott.MScott.M

Easiest way is to not use visualforce components. Use straight html, javascript, and remoting to send things back to the server. Visualforce components are slow and inflexible. 

Michael_TorchedloMichael_Torchedlo

Scott's reply about using standard Javascript or HTML is a good route to take.

 

If that is not a possibility for you, there is something else you can try. I don't know all the details of how your page is setup.  If your VF page uses a custom apex controller or controller extension, then you can use a PageReference method in your controller.

 

Ex:

    On your VF page, add a command button next to your apex:inputfile to "Confirm" or "Add" whatever file the user has uploaded.  Have that command button call the ReLoad() function.

 

   public pageReference ReLoad(){

        //some logic based on what you want to do with the uploaded file

        //

        return Page.Name_of_your_Visualforce_Page;

    }

 

A method like this will reload the page in the web browser, but it is not declaring a new instance of the controller, so it keeps all the original data.  It is a little like manually rerendering the page when the user clicks the button to add a file, without using the "rerender" support in your Visualforce markup.  "Rerender" will not work with an apex:inputFile component, but you can redirect the user back to the same page, which may accomplish the same thing. 

 

Also, if you have parts of your page which should be conditionally displayed, then each time the ReLoad() runs, it can reevaluate those conditions.  The resulting page will seem like it is changing in response to the user's input.

sv_159sv_159

Thanks for sharing.

sv_159sv_159

Thanks 

This was selected as the best answer