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
Anto HotelbedsAnto Hotelbeds 

Pass parameter from visualforce to apex with javascript

Hi,

I have got a visualforce page, where I am showing in a table a list of cases I get from my Apex Class.

This is my visualforce:

<apex:page controller="XMLCasePopupController" title="Search" showHeader="false" sideBar="false" tabStyle="Case" id="page" >
  <!-- messages -->
  <apex:outputPanel id="top" layout="block">
    <apex:outputLabel value="Possible duplicates" style="margin:20px; padding:10px; margin-top:10px; font-weight:bold; font-size: 1.5em;"/>
  </apex:outputPanel>

  <apex:form >
  <apex:pageBlock title="XML Case Edit" id="XML_Case_Edit" mode="Edit">
      <!-- Buttons toolbar -->   
        <apex:pageBlockButtons >
            <apex:commandButton value="Finish" action="{!endCaseCreation}"/>
        <!--    <apex:commandButton value="Back" action="{!backStep}"/> -->
        </apex:PageBlockButtons>
      
        <apex:outputPanel id="page" layout="block" style="margin:5px;padding:10px;padding-top:2px;">
  <apex:actionRegion >
      <!-- results panel -->
      <apex:outputPanel id="pnlSearchResults" style="margin:10px;height:350px;overflow-Y:auto;" layout="block">
          <apex:pageBlock id="searchResults">
             <apex:pageBlockTable value="{!results}" var="c" id="tblResults">
                    <apex:column >
                    <apex:facet name="header">
                        <apex:outputPanel >Release</apex:outputPanel>
                    </apex:facet>
                    <apex:outputLink onClick="test('{!c.Id}');return false;">{!c.Module_Release__c}</apex:outputLink>
                    </apex:column>
</apex:column>
             </apex:pageBlockTable>
         </apex:pageBlock>
      </apex:outputPanel>
  </apex:actionRegion>
  </apex:outputPanel>
    </apex:pageBlock>
    <apex:actionFunction name="test" action="{!ShowCaseToTrue}">
        <apex:param name="param1" assignto="{!IdChosen}" value=""/>
    </apex:actionFunction>
  </apex:form>

So I am calling the actionFunction ShowCaseToTrue and I want to pass the Id of the case that the user has clicked in the table. This is my apex class:

public with sharing class XMLCasePopupController {


  public List<Case> results{get;set;} // search results
  public string searchString{get;set;} // search keyword
  public string caseId{get;set;}
  public Boolean ShowCase{get;set;}
  public Case ChosenCase{get;set;}
  public Id IdChosen{get;set;}

  public XMLCasePopupController() {
    // get the current search string
    searchString = System.currentPageReference().getParameters().get('lksrch');
    caseId = System.currentPageReference().getParameters().get('id');
    //ShowCase=False;
    System.debug('==> searchString = ' + searchString + ' -- caseid ' + caseId);
    runSearch();
  }

  // performs the keyword search
  public PageReference search() {
    runSearch();

    return null;
  }

  // performs the keyword search
  public void ShowCaseToTrue() {
    this.ShowCase=True;
    system.debug('El id que tengo que buscar es: '+ IdChosen);
    ChosenCase=[SELECT Id,CaseNumber FROM Case WHERE Id=:IdChosen];
  }
}

I am always getting a null value in IdChosen. Can anybody help me on what I am missing here?

Thanks a lot!

Antonio
vbsvbs
The parameter will be available as a query parameter with the viewstate and accessible using ApexPages.currentPage().getParameters().get('param1') in your ShowCaseToTrue function.