1

I am trying to display a lookup field based on the value of a picklist.

If the value 'Other' is chosen on the picklist, the showOtherAddress is set to true and then the rerender triggered by the Address picklist should display the field.

I cannot see anything wrong with the code but the field is not showing. This is the respective portion of the visual force page:

<apex:outputPanel id="addressList">
                        <apex:outputText styleClass="availableText" rendered="{!addressOptions.size != null}" value="({!addressOptions.size - 1} available)"/>
                        <apex:actionRegion >
                            <apex:selectList styleClass="form-control" value="{!order.DeliveryAddress__c}" size="1">
                                <apex:selectOptions value="{!addressOptions}"></apex:selectOptions>
                                  <apex:actionSupport event="onclick" action="{!updateAddressDetails}" rerender="selectedAddressDescription,otherAddress">
                                  </apex:actionSupport>
                            </apex:selectList> 
                        </apex:actionRegion>                                                       
                    </apex:outputPanel>
                    <label for="selectedAddressDescription">Address Description</label>
                    <apex:outputPanel id="selectedAddressDescription" styleClass="form-control">
                        <span >{!selectedAddressDescription}</span>
                    </apex:outputPanel>
                    <apex:outputPanel id="otherAddress" rendered="{!showOtherAddress == true}">
                    <label for="other">Other Address</label><apex:inputField id="other" value="{!order.DeliveryAddress__c}"/>
                    </apex:outputPanel>

And here's the part where my Apex class is being used:

public PageReference updateAddressDetails(){
    setAddressDetails();
    return null;
}

public void setAddressDetails(){
    if (order.Account__c != null){
        System.debug(order.DeliveryAddress__c);
        Account acc = [SELECT Address__c, Address_Description__c, Secondary_Address__c, Secondary_Address_Description__c FROM Account WHERE Id= :order.Account__c];
        if (order.DeliveryAddress__c == acc.Address__c){
            System.debug('Primary add');
            this.selectedAddressDescription = acc.Address_Description__c;
            this.showOtherAddress = true;
            //return this.selectedAddressDescription;
        } else if (order.DeliveryAddress__c == acc.Secondary_Address__c){
            System.debug('Secondary add');
            this.selectedAddressDescription = acc.Secondary_Address_Description__c;
            this.showOtherAddress = false;
            //return this.selectedAddressDescription;
        } else {// if (order.DeliveryAddress__c == 'Other'){
            System.debug('OTHER');
            this.showOtherAddress = true;
            this.selectedAddressDescription = '';
        }
        System.debug(this.showOtherAddress);
    } else {
        System.debug('Foo');
    }
}
  • You've commented out the line -- // if (order.DeliveryAddress__c == 'Other'){ – David Cheng Jul 27 at 4:41
  • It should still work though shouldn't it? – edgaralienfoe Jul 29 at 8:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.