1

I currently have a wrapper list containing custom sObjects and checkboxes. I also have a inputText field on a Visualforce page and would like to filter the wrapper list by License_Voucher__c which is a field in my custom SObject contained within my wrapper.

I would like for the search to contain all variances of the string such as if the user typed in 'john' , the search would return 'john', 'johnson', 'johnny'. Basically john* or a sql equivalent of 'LIKE'.

To make life simpler I added a string voucherNumber to my wrapper and tried to iterate through the list with the .contains() to see if each element met the inputText requirements.

Unfortunately whether I try searching with the entire correct string or part of the correct string I seem to get no results. Would there be a better approach to this? thanks!

Wrapper Class

public class wrapper_OlympusLR{ 
public License_Request__c lrObj {get;set;}
public String macAddress {get;set;}
public String serverName {get;set;}
public String serialNumber {get;set;}
public String serverModel {get;set;}
public Boolean selected {get;set;}
public String voucherNumber {get;set;}

public wrapper_OlympusLR(License_Request__c lrq)
{              
        this.lrObj      = lrq;
        this.selected   = false;               
        this.macAddress = null;
        this.serverName = null;
        this.serialNumber   = null;
        this.serverModel    = null;
        this.voucherNumber = lrq.License_Voucher__c;

}

Controller Search Method

    public PageReference runSearch()
{
    String voucherNumber = inputVoucherNumber+'.*';
    if(voucherNumber.equals(''))
    {
        //DO NOTHING OR USE ORIGINAL LIST 
        wrapDynLRList = wrapLRListOriginal;

    }
    else
    {
        wrapDynLRList.clear();
        for(wrapper_OlympusLR lrList : wrapLRListOriginal)
        {
            if(lrList.voucherNumber.contains(voucherNumber))
            {
                wrapDynLRList.add(lrList);
            }
        }

    }
    return null;
} 
2
  • The code you posted appears to have 3 different lists: wrapDynLRList, wrapLRListOriginal and wrapLRList. It would make more sense if wrapLRListOriginal was used in place of wrapLRList.
    – Keith C
    Commented Aug 11, 2014 at 20:11
  • small typo mistake on my part. There's only supposed to be two lists and not three. Fixed it for a better understanding. Thanks for spotting that out!
    – enph
    Commented Aug 11, 2014 at 21:44

1 Answer 1

2

You do not need to append the '.*' on the voucher number

Using the .contains(voucherNumber) will return any result that has the voucherNumber in the field the contains is applied on.

1
  • bah, guess I overlooked how the .contains() works. Removing the .* fixed it, thanks for the insight.
    – enph
    Commented Aug 11, 2014 at 20:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .