Search code examples
salesforceapex-codevisualforce

Automatically update Visualforce page every time an item from a drop list is picked


I have a visualforce/apex functionality that exports & emails a PDF for commission agreements to be signed. Commission agreements are types of Contracts.

The visualforce page itself is pretty simple, it has a "email to:" field as well a drop list called "Contract Project Title" (project title is a custom field). This drop list is populated via my apex controller with Contracts that have Commission Agreements as the record type.

What I want to do is that whenever a user selects a contract from the drop list, have the apex page be updated with details of the Contract, so that they would be certain that they chose the correct Contract without having to go to its page and look at the details. It would be best if that happened without having to click a button, but thats not a necessary functionality.


Solution

  • You want to use an <apex:actionSupport> tag along with your picklist:

    <apex:selectList value="{!someVar}">
      <apex:selectOptions value="{!options}"/>
      <apex:actionSupport action="{!LoadContact}" rerender="theContactInfo" event="onchange"/>
    </apex:selectList>
    
    <apex:outputPanel id="theContactInfo">
      <!-- Display your contact info here -->
    </apex:outputPanel>
    

    LoadContact is an action in your controller which loads the details for the contact selected in the drop down.