简体   繁体   中英

Displaying Records based on keyword from vf page

I have a senario where i will be dispalying input text fieldon vf page,when i enter some value and click on search button the realted accounts should be displayed depending on that keyword. I have tried the following code,but i am unable to resolve the error Unknown property 'VisualforceArrayList.Name' The below is my code: class:

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 page:

<apex:page controller="AccountswithKeywordfrompage" standardStylesheets="false">

 <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>  

Can anyone help me to solve the issue?

accountlist is a List<List<Account>> , which is the wrong type; a SOSL search returns a List<List<sObject>> . It just so happens that your SOSL search only returns Account results.

When you iterate over a List<List<sObject>> :

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

the type of the iteration variable is List<Account> , which has no Name property.

The cleanest solution is to declare your variable as a List<Account> and extract the first element of the returned List<List<sObject>> from SOSL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM