在 Visualforce 页面上查找后,我尝试将 ID 发送到控制器。 ID 始终为空。我必须提到的是,查找是通过自定义查找 JavaScript 函数进行的,该函数会覆盖 Salesforce 查找函数。基于该查找 ID,我想重新呈现涉及该查找的页面部分。
这是我的查找字段和操作支持,应该发送项目__c
<apex:inputField id="ProjectLookup" tabOrderHint="1" value="{!solarDisclosure.Project__c}" required="true" html-read-only="true">
<apex:actionSupport event="onchange" action="{!updateFieldsBasedOnProject}" rerender="SolarDisclosureFields" immediate="true"/>
</apex:inputField>
我必须立即设置 true,否则它似乎不会触发控制器,可能是因为我有验证。
这是我的控制器功能...
public PageReference updateFieldsBasedOnProject(){
// Use the selectedProjectId variable to update the fields in the solarDisclosure object
// selectedProjectId = solarDisclosure.Project__c;
system.debug('solarDisclosure.Project__c: ' + solarDisclosure.Project__c);
selectedProjectId = solarDisclosure.Project__c;
system.debug('selectedProjectId: ' + selectedProjectId);
// Assuming that the variable selectedProjectId contains the selected Project's ID
Project__c selectedProject = [SELECT Id, Project_Location__c, Name FROM Project__c WHERE Id = :selectedProjectId];
solarDisclosure.Project_Location__c = selectedProject.Project_Location__c;
solarDisclosure.Project_Name__c = selectedProject.Name;
return null;
}```
I am always getting null for solarDisclosure.Project__c
I have tried to do this with vanilla javascript and sforce and seemed to get somewhere but would like to get this to work server side if I can.
I am trying to update the fields based on the lookup as seen here.
在命令按钮上
immediate=true
会跳过 setter、getter 和字段级验证(例如,像 required=true
一样,它不会跳过真正的服务器端验证规则)。我怀疑 actionSupport 的 immediate
也是如此。所以对你来说问题是它没有设置 setter,值没有传递。
您可以尝试通过该actionSupport内的
apex:param
传递您想要的值,有点像我古老的答案https://salesforce.stackexchange.com/a/4950/799
但我认为对你来说更“自然”、更具视觉效果的做事方式是使用
actionRegion
只提交你的字段所在的页面部分,而不是整个表单。尝试运行来自 https://salesforce.stackexchange.com/a/22216/799 的示例