【问题标题】:Displaying Records based on keyword from vf page根据 vf 页面中的关键字显示记录
【发布时间】:2021-02-16 13:38:22
【问题描述】:

我有一个场景,我将在 vf 页面上显示输入文本字段,当我输入一些值并单击搜索按钮时,应根据该关键字显示真实帐户。 我已尝试以下代码,但无法解决错误 Unknown property 'VisualforceArrayList.Name' 以下是我的代码: 类:

public class AccountswithKeywordfrompage {
    public string keyword{get;set;}
    public List<List<Account>> accountlist{get;set;}
    public void Accounts(){
        keyword = System.currentPageReference().getParameters().get('search');
        accountlist=[FIND '+keyword' IN ALL FIELDS 
                     RETURNING Account(Name)];
    }
}

vf 页面:

 <apex:form>
        <apex:inputText label="SearchAccounts" id="search">
            <apex:commandButton value="search" action="{!Accounts}"/>
        </apex:inputText> 
        <apex:pageblock>
            <apex:pageblockTable value="{!accountlist}" var="accountobj">
                <apex:outputlink value="{!accountobj.Name}"/>
            </apex:pageblockTable>   
        </apex:pageblock>
    </apex:form>  
</apex:page>  

谁能帮我解决这个问题?

【问题讨论】:

    标签: salesforce apex visualforce


    【解决方案1】:

    accountlistList&lt;List&lt;Account&gt;&gt;,这是错误的类型; SOSL 搜索返回List&lt;List&lt;sObject&gt;&gt;。碰巧您的 SOSL 搜索只返回 Account 结果。

    当你迭代 List&lt;List&lt;sObject&gt;&gt;:

    <apex:pageblockTable value="{!accountlist}" var="accountobj">
    

    迭代变量的类型是List&lt;Account&gt;,它没有Name属性。

    最干净的解决方案是将变量声明为List&lt;Account&gt;,并从 SOSL 中提取返回的List&lt;List&lt;sObject&gt;&gt; 的第一个元素。

    【讨论】:

    • 当我替换您所说的内容时,我仍然遇到一些错误,例如 Unknown property 'AccountswithKeywordfrompage.list' 您能否解释一下如何获取从控制器类返回到 vf 的列表值页面
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-13
    • 2019-04-23
    • 1970-01-01
    相关资源
    最近更新 更多