,

Repopulating the selectList

In order to properly repopulate the Visualforce selectList, you can add AJAX functionality to your page, which is implemented automatically without having to write any Javascript code, whenever the user has changed the value in the Department list.

As you learned in Chapter 9, this interactive capability is easy to use with Visualforce.

1.
Add the highlighted code to your Visualforce page.

</apex:pageBlocksection>
     <apex:actionRegion >
         <apex:pageblocksection columns="1"
           title="Department">
            <apex:inputField
              value="{!Position__c.Department__c}"/>
            <apex:actionSupport event="onchange"
								rerender="dependentPositionType"
								status="departmentStatus"/>
								<apex:actionStatus id="departmentStatus"
								startText="Fetching position types..."/>
         </apex:pageblockSection>
          <apex:pageblockSection id="dependentPositionType"

Adding the actionSupport component to the inputField for the Department__c field enables this field to react to user actions—in this case, the onchange event that fires whenever the value for the field changes.

You have to include the actionRegion tags to insure that the only field values sent back to the controller are the Department and Position Type fields. If you send the entire page back, and the user does not enter a value for one of the required fields, the controller will return an error.

In response to this event, you want to re-render the pageBlockSection that contains the selectList for Position Type, which will cause the component to call the get method for the field again.

2.
Save the code for your Visualforce page.

3.
Change the value in the Department picklist to see the dynamic refresh of the Position Type picklist at work.

This single component brings it all together—the AJAX capability of the Visualforce page and the additional functionality implemented in your controller extension.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.163.127