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
Alex Li 26Alex Li 26 

Passing param to controller with actionsupport and inputfile tag

<apex:actionFunction name="saveJS" action="{!save}">
  <apex:param value="test" name="test"/>
</apex:actionFunction>

<apex:dataTable value="{!list}" var="value">
  <apex:column>
    <apex:inputfile value="{!body}" fileName="{!name}" onchange="saveJS()"/>
  </apex:column>
</apex:dataTable>
In my controller, I have a save() method that is debugging the param "test" that I'm getting with ApexPages.currentPage().getParameters().get('test') but I'm getting null.

I not sure if that the right approach, but what I trying to do is to pass an identifier along with the body of the file that the user can upload so that I can get it back later (since I have several rows and one file can be uploaded for each row).
I'm guessing that apex:param does not work in this case because inputFile is refreshing the whole page

Any idea on what's happening exactly or how I can approach this task differently ?

PS : That's not the finish code since I'm not changing the param value yet (to have a unique identifier for each file)
Ajay K DubediAjay K Dubedi
Hi Alex,

Use this line of code for Action Function:

<apex:actionFunction name="saveJS" action="{!save}" reRender="none">
  <apex:param value="test" name="test"/>
</apex:actionFunction>

If this code does'nt work try to implement it using java script.
<script type="text/javascript">
  function funJS()
   {
    var text=document.getElementById("{!$Component.dt.if}").value;
    saveJS(text);
   }
</script>

<apex:actionFunction name="saveJS" action="{!save}" reRender="none">
  <apex:param value="test" name="test"/>
</apex:actionFunction>


<apex:dataTable value="{!list}" var="value" id="dt">
  <apex:column>
    <apex:inputfile value="{!body}" fileName="{!name}" onchange="funJS()" id="if"/>
  </apex:column>
</apex:dataTable>


Hope this will help you. Please mark it as Best Answer if you find it helpful.

Thanks.
Ajay Dubedi
CA SFDCCA SFDC
@Ajay - We can't use reRender in Action function saveJS for inputFile onchange. And unless we rerender something we can't get Param value of Action Function in Controller. I know It tricky. 

@Alex - Can you give us the controller code. I would like to see how you defined getter/setter scope of the variable test. And as mentioed limitations and bugs around Inputfile, reRender  and param, it is hard to tell without your controller code.