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
cmarz77cmarz77 

reRender dynamicComponent Lookup Issue - eyeglass button not working correctly

I have a custom object with many lookups.  I am trying to create a Visualforce page that allows the user to select an object and then using the "reRender" tag dyamically change the lookup input field.  Really I am trying to mimic the "Related To" field on tasks and events.  User selects an object and using a dynamicComponent I want to reRender the Lookup feild.

Here is my relevant VF page code:
<apex:pageblockSectionItem >
                <apex:outputLabel value="Related To" />       
                <apex:outputPanel styleClass="Input" layout="block" >
                <apex:selectList size="1" value="{!relatedToAPIName}" id="relatedToAPIName"  >
                    <apex:selectOptions value="{!RelateToObjs}"/>
                    <apex:actionSupport event="onchange" reRender="relatedToLookup" />
                </apex:selectList>
                <apex:dynamicComponent componentValue="{!RelatedToLookup}" id="relatedToLookup"/> 
                </apex:outputPanel>          
</apex:pageblockSectionItem>

Here is the relevant controller apex code:
public List<SelectOption> getRelateToObjs(){
List<SelectOption> rto = new List<SelectOption> ();
// Get all fields
Map <String, Schema.SObjectField> fieldMap = Schema.getGlobalDescribe().get(‘CustomObj__c’).getDescribe().fields.getMap();

// Loop through all fields and get the lookups
for(Schema.SObjectField sfield : fieldMap.Values()) {
  if(sfield.getDescribe().getType() == Schema.DisplayType.Reference) rto.add(new SelectOption(sfield.getDescribe().getName(),sfield.getDescribe().getLabel()));
}

return rto;
}

public Component.Apex.InputField getRelatedToLookup(){
     Component.Apex.InputField dLookup = new Component.Apex.InputField();
if(relatedToAPIName == null) relatedToAPIName='Account__c';  // Set Default
system.debug('*** '+ relatedToAPIName);
dLookup.expressions.value = '{!CustomObj__c.'+relatedToAPIName+'}';
return dLookup;
}

Here is my issue - there are two parts to a lookup field, the text field and the eyeglass User-added image button.  Based on my testing it seems like when my picklist changes the action support reRender is changing the text box from one lookup field to the newly selected lookup field but the eyeglass button when click is still searching for the object previously listed in picklist.  Since I am setting the Account lookup as the defualt no matter what the user selects in the Related To piclist the eyeglass button will always open to search for accounts.  I think if I force a full page refresh the button will update but becuase there is other inputted data on the page that I don't want to loose this is a less than idea scenerio.

Has anyone every run into this?
Ashish_SFDCAshish_SFDC

Hi , 


See the below links for sample code and more information, 

https://developer.salesforce.com/forums/ForumsMain?id=906F000000094wqIAA

https://developer.salesforce.com/forums/ForumsMain?id=906F00000008lCEIAY

http://salesforce.stackexchange.com/questions/27985/save-fields-of-two-objects


Regards,

Ashish