javascript - 将参数从 Visualforce 传递到 apex 错误

标签 javascript arguments salesforce visualforce apex

我有一个 Visualforce 页面,我在其中以表格显示从 Apex 类(class)获得的案例列表。

这是我的视觉力量:

<apex:page controller="XMLCasePopupController" title="Search" showHeader="false" sideBar="false" tabStyle="Case" id="page" >
<!-- messages -->
<apex:outputPanel id="top" layout="block">
<apex:outputLabel value="Possible duplicates" style="margin:20px; padding:10px; margin-top:10px; font-weight:bold; font-size: 1.5em;"/>
</apex:outputPanel>

<apex:form >
<apex:pageBlock title="XML Case Edit" id="XML_Case_Edit" mode="Edit">
  <!-- Buttons toolbar -->    
    <apex:pageBlockButtons >
        <apex:commandButton value="Finish" action="{!endCaseCreation}"/>
    <!--    <apex:commandButton value="Back" action="{!backStep}"/> -->
    </apex:PageBlockButtons>

    <apex:outputPanel id="page" layout="block" style="margin:5px;padding:10px;padding-top:2px;">
<apex:actionRegion >
  <!-- results panel -->
  <apex:outputPanel id="pnlSearchResults" style="margin:10px;height:350px;overflow-Y:auto;" layout="block">
      <apex:pageBlock id="searchResults">
         <apex:pageBlockTable value="{!results}" var="c" id="tblResults">
                <apex:column >
                <apex:facet name="header">
                    <apex:outputPanel >Release</apex:outputPanel>
                </apex:facet>
                <apex:outputLink onClick="test('{!c.Id}');return false;">{!c.Module_Release__c}</apex:outputLink>
                </apex:column>
</apex:column>
         </apex:pageBlockTable>
     </apex:pageBlock>
  </apex:outputPanel>
</apex:actionRegion>
</apex:outputPanel>
</apex:pageBlock>
<apex:actionFunction name="test" action="{!ShowCaseToTrue}">
    <apex:param name="param1" assignto="{!IdChosen}" value=""/>
</apex:actionFunction>
</apex:form>

因此,我正在调用 actionFunction ShowCaseToTrue,并且想传递用户在表中单击的案例的 Id。这是我的顶点类(class):

public with sharing class XMLCasePopupController {

    public List<Case> results{get;set;} // search results
    public string searchString{get;set;} // search keyword
    public string caseId{get;set;}
    public Boolean ShowCase{get;set;}
    public Case ChosenCase{get;set;}
    public Id IdChosen{get;set;}

    public XMLCasePopupController() {
        // get the current search string
        searchString = System.currentPageReference().getParameters().get('lksrch');
        caseId = System.currentPageReference().getParameters().get('id');
        //ShowCase=False;
        System.debug('==> searchString = ' + searchString + ' -- caseid ' + caseId);
        runSearch(); 
    }

    // performs the keyword search
    public PageReference search() {
        runSearch();

        return null;
    }

    // performs the keyword search
    public void ShowCaseToTrue() {
        this.ShowCase=True;
        system.debug('El id que tengo que buscar es: '+ IdChosen);
        ChosenCase=[SELECT Id,CaseNumber FROM Case WHERE Id=:IdChosen];
    }
}

我总是在 IdChosen 中得到空值。有人可以帮我解决我在这里缺少的东西吗?

非常感谢!

安东尼奥

最佳答案

Couple of things

1)将IdChosen更改为String数据类型

public String  IdChosen{get;set;}

2)更改action功能测试

<apex:actionFunction name="test" action="{!ShowCaseToTrue}">
   <apex:param name="param1" assignto="{!IdChosen}" value="{!c.Id}"/>
</apex:actionFunction>

关于javascript - 将参数从 Visualforce 传递到 apex 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21672142/

相关文章:

vba - 多参数子 vba

function - 在 Haxe 中传递任意函数参数列表

salesforce - Visualforce:如何打印当前日期?

javascript - 如何从顺序键盘导航中删除 Vuetify 附加图标

javascript - 使用 JavaScript 隐藏打印 View 中的空字段

javascript - 页面滚动和 JQuery

triggers - Salesforce Apex 触发器 "isAPI"上下文变量

javascript - 在同一网页中动态更改 p5.js Canvas 的最佳方法是什么?

c - 段错误 - 原因是什么

Salesforce:任何可用于访问 Salesforce 日历的 Rest API?