function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sravusravu 

Urgent Help!!!!!!!! Custom Search Functionality not working properly

I have two different components that search for the same object. In the first search when i enter the keyword, the same value is assigned to the second search component. I am doing this by passing the first search parameter to the second search component. The code for first search is as follows:

 

<apex:component controller="ProductSearchController">
    <apex:form >
    <table border="0">
      <tr>
       <td valign="top">
        <apex:inputText value="{!searchParam}" id="search" size="21" style="border-color:#2C6892;border-style:solid;border-width:1px;height:18px;"/> </td>
       <td >
        <apex:commandButton style="background:url({!$Resource.ProductSearch}) no-repeat;width:20px;height:21px;margin:0px;margin-bottom:0px;margin-left:-4px;" action="{!SearchResults}"/>
       </td>
      </tr>
     </table>
      <p>  <apex:inputCheckbox value="{!Solutions}" title="Solutions" selected="true" style="margin-left:0px;"/>Solutions
        <apex:inputCheckbox value="{!Partners}" title="Partners" style="margin-left:20px;margin-bottom:0px;"/>Partners
      </p>
    </apex:form>
</apex:component>

 

The visualforce page for second earch is :

 

<apex:component controller="ProductSearchController">
<apex:attribute name="value" type="string" assignTo="{!SearchKeyword}" description="Search Keyword"/>
    <apex:form >
         <table border="0">
       <tr>
        <td valign="top">
        <apex:inputText value="{!SearchKeyword}" id="searchKey" size="68" style="border-color:#2C6892;border-style:solid;border-width:1px;height:18px;" /> </td>
        <td>
        <apex:commandButton style="background:url({!$Resource.ProductSearch}) no-repeat;width:20px;height:21px;margin:0px;margin-top:0px;margin-left:-4px;" action="{!SearchResultsKey}"/> </td>
        </tr>
        </table>
        <table border="0">
         <tr>
         <td valign="top">
        <apex:inputCheckbox value="{!Certified}"/>Certified&nbsp;&nbsp;&nbsp;
        <apex:inputCheckbox value="{!All}"/>All&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;
        <apex:inputCheckbox value="{!Solutions}"/>Solutions&nbsp;&nbsp;&nbsp;
        <apex:inputCheckbox value="{!Partners}"/>Partners </td></tr></table>
    </apex:form>
</apex:component>

 

My issue is when i give a parameter to the first component, i am able to display the same value in the second component's search box. But when I enter a new parameter in the second component, it is not taking the new value. It is still taking the old value. The attribute value is not overwritten.

 

Any suggestions????

 

Here is my controller

 

 

 

 

Thanks in advance.

Best Answer chosen by Admin (Salesforce Developers) 
sravusravu

Ok I could solve the problem by myself. I changed the attribute definition as follows

 

<apex:attribute name="SearchKeyword" type="string" description="Search Keyword"/>

All Answers

sravusravu

Here is the controller

public class ProductSearchController{
    
    public String SearchParam {get;set;}
    public String SearchKeyword {get;set; }
    public Boolean Certified {get;set;}
    public Boolean All {get;set;}
    public Boolean Solutions {get;set;}
    public Boolean Partners {get;set;}
    
      
    
    public String Term {
        get{
            return ApexPages.currentPage().getParameters().get('SearchParam');
        }
        set;
    }
    
    public String SearchTerm {
        get{
            return ApexPages.currentPage().getParameters().get('SearchKeyword');
        }
        set;
    }
        
    public PageReference searchResults(){
        PageReference pageRef = new PageReference('/apex/ProductSearchResultsPage?SearchParam='+SearchParam +'&Solutions='+Solutions+'&Partners='+Partners);
        pageRef.setRedirect(true);
        return pageRef;
    }
    
    public PageReference searchResultsKey(){
        //String SearchKey = this.SearchKeyword;
        PageReference searchPage = new PageReference('/apex/ProductSearchResultsFullPage?SearchKeyword='+SearchKeyword+'&Solutions='+Solutions+'&Partners='+Partners+'&Certified='+Certified+'&All='+All);
        searchPage.setRedirect(true);
        return searchPage;
    }
    
     public Id pId {get;set;}

    public Boolean  hasNext{
        get{
            return con.gethasNext();
        }
        set;
    }
    
    public Boolean hasPrevious{
        get{
            return con.gethasPrevious();
        }
        set;
    }
    
    public void next(){        
        con.next();    
    }        
    
    public void previous(){        
        con.previous();    
    }
    
    public ApexPages.StandardSetController con{
        get{
            if(con==NULL){
                 String Search = ApexPages.currentPage().getParameters().get('SearchParam');
                String Sol = ApexPages.currentPage().getParameters().get('Solutions');
                String Part =ApexPages.currentPage().getParameters().get('Partners');
        if(Search==NULL || Search==''){
            if(Sol=='true' && Part == 'true'){
                con = new ApexPages.StandardSetController(Database.getQueryLocator([Select Id, Application_Logo__c, title__c, Submitted_By__c from Product__c]));
           
            }
            if(Sol=='false' && Part=='true'){
                con = new ApexPages.StandardSetController(Database.getQueryLocator([Select Id, Application_Logo__c, title__c, Submitted_By__c from Product__c]));
          
            }
            if(Sol=='false' && Part=='false'){
                con = new ApexPages.StandardSetController(Database.getQueryLocator([Select Id, Application_Logo__c, title__c, Submitted_By__c from Product__c]));
            
            }
            if(Sol=='true'&& Part=='false'){
                con = new ApexPages.StandardSetController(Database.getQueryLocator([Select Id, Application_Logo__c, title__c, Submitted_By__c from Product__c]));
            
            }
        }
        else {
             List<List<SObject>> searchList = NULL;
             searchList = [FIND :Search IN ALL FIELDS RETURNING Product__c (Id)];                
             Product__c[] pro = ((List<Product__c>)searchList[0]);
             if(Sol=='true' && Part=='false'){
                 con= new ApexPages.StandardSetController(Database.getQueryLocator([Select Id, Application_Logo__c, Title__c, Submitted_By__c from Product__c where Id in :pro]));
             }
              if(Sol=='false' && Part=='false'){
                 con= new ApexPages.StandardSetController(Database.getQueryLocator([Select Id, Application_Logo__c, Title__c, Submitted_By__c from Product__c where Id in :pro]));
             }
             if(Sol=='false' && Part=='true'){
                 con= new ApexPages.StandardSetController(Database.getQueryLocator([Select Id, Application_Logo__c, Title__c, Submitted_By__c from Product__c where Id in :pro]));
             }
            if(Sol=='true' && Part=='true'){
                 con= new ApexPages.StandardSetController(Database.getQueryLocator([Select Id, Application_Logo__c, Title__c, Submitted_By__c from Product__c where Id in :pro]));
             }

        }
                con.setPageSize(10);

            }
            
           return con;
 
        }
        set;
           }
           
           
           public ApexPages.StandardSetController controller{
               get{
                   if(controller==NULL){
                       String SearchKey = ApexPages.currentPage().getParameters().get('SearchKeyword');
                       String Soln = ApexPages.currentPage().getParameters().get('Solutions');
                       String Partner = ApexPages.currentPage().getParameters().get('Partners');
                       String pAll = ApexPages.currentPage().getParameters().get('All');
                       String pCertified = ApexPages.currentPage().getParameters().get('Certified');
                       if(SearchKey==NULL || SearchKey==''){
                           if(Soln=='true' && pCertified=='true' && pAll=='true'){
                               controller = new ApexPages.StandardSetController(Database.getQueryLocator([Select Id, Application_Logo__c, title__c, Submitted_By__c from Product__c]));
                           }
                           else if(Soln=='true' && pCertified=='false' && pAll=='false'){
                               controller = new ApexPages.StandardSetController(Database.getQueryLocator([Select Id, Application_Logo__c, title__c, Submitted_By__c from Product__c]));
                           }
                           else if(Soln=='true' && pCertified=='false' && pAll=='true'){
                               controller = new ApexPages.StandardSetController(Database.getQueryLocator([Select Id, Application_Logo__c, title__c, Submitted_By__c from Product__c]));
                           }
                           else if(Soln=='true' && pCertified=='true' && pAll=='false'){
                               controller = new ApexPages.StandardSetController(Database.getQueryLocator([Select Id, Application_Logo__c, title__c, Submitted_By__c from Product__c where Certified__c = true]));
                           }
                           else if(Soln=='false' && pCertified=='true' && pAll=='true'){
                               controller = new ApexPages.StandardSetController(Database.getQueryLocator([Select Id, Application_Logo__c, title__c, Submitted_By__c from Product__c where Certified__c = true]));
                           }
                           else if(Soln=='false' && pCertified=='false' && pAll=='true'){
                               controller = new ApexPages.StandardSetController(Database.getQueryLocator([Select Id, Application_Logo__c, title__c, Submitted_By__c from Product__c]));
                           }
                           else if(Soln=='false' && pCertified=='true' && pAll=='false'){
                               controller = new ApexPages.StandardSetController(Database.getQueryLocator([Select Id, Application_Logo__c, title__c, Submitted_By__c from Product__c where Certified__c = true]));
                           }
                           else if(Soln=='false' && pCertified=='false' && pAll=='false'){
                               controller = new ApexPages.StandardSetController(Database.getQueryLocator([Select Id, Application_Logo__c, title__c, Submitted_By__c from Product__c]));
                           }
                           else{
                               controller = new ApexPages.StandardSetController(Database.getQueryLocator([Select Id, Application_Logo__c, title__c, Submitted_By__c from Product__c]));
                           }                           
                       }
                       else{
                       List<List<SObject>> searchList = NULL;
                       searchList = [FIND :SearchKey IN ALL FIELDS RETURNING Product__c (Id)];                
                       Product__c[] pro = ((List<Product__c>)searchList[0]);
                           if(Soln=='true' && pCertified=='true' && pAll=='true'){
                               controller = new ApexPages.StandardSetController(Database.getQueryLocator([Select Id, Application_Logo__c, title__c, Submitted_By__c from Product__c where Id in :pro]));
                           }
                           else if(Soln=='true' && pCertified=='false' && pAll=='false'){
                               controller = new ApexPages.StandardSetController(Database.getQueryLocator([Select Id, Application_Logo__c, title__c, Submitted_By__c from Product__c where Id in :pro]));
                           }
                           else if(Soln=='true' && pCertified=='false' && pAll=='true'){
                               controller = new ApexPages.StandardSetController(Database.getQueryLocator([Select Id, Application_Logo__c, title__c, Submitted_By__c from Product__c where Id in :pro]));
                           }
                           else if(Soln=='true' && pCertified=='true' && pAll=='false'){
                               controller = new ApexPages.StandardSetController(Database.getQueryLocator([Select Id, Application_Logo__c, title__c, Submitted_By__c from Product__c where Certified__c = true and Id in :pro]));
                           }
                           else if(Soln=='false' && pCertified=='true' && pAll=='true'){
                               controller = new ApexPages.StandardSetController(Database.getQueryLocator([Select Id, Application_Logo__c, title__c, Submitted_By__c from Product__c where Certified__c = true and Id in :pro]));
                           }
                           else if(Soln=='false' && pCertified=='false' && pAll=='true'){
                               controller = new ApexPages.StandardSetController(Database.getQueryLocator([Select Id, Application_Logo__c, title__c, Submitted_By__c from Product__c where Id in :pro]));
                           }
                           else if(Soln=='false' && pCertified=='true' && pAll=='false'){
                               controller = new ApexPages.StandardSetController(Database.getQueryLocator([Select Id, Application_Logo__c, title__c, Submitted_By__c from Product__c where Certified__c = true and Id in :pro]));
                           }
                           else if(Soln=='false' && pCertified=='false' && pAll=='false'){
                               controller = new ApexPages.StandardSetController(Database.getQueryLocator([Select Id, Application_Logo__c, title__c, Submitted_By__c from Product__c where Id in :pro]));
                           }
                           else{
                               controller = new ApexPages.StandardSetController(Database.getQueryLocator([Select Id, Application_Logo__c, title__c, Submitted_By__c from Product__c where Id in :pro]));
                           }
                       }
                       controller.setPageSize(10);
                       
                   }
                   return controller;
               }
               set;
          }
    
    public List<Product__c> getProducts(){
                      List<Product__c> pro;
        
        if(con!=NULL){
            pro = con.getRecords();
        }
        else{
            pro = NULL;
        }   
        return pro;
    }
    
        public List<Product__c> getProductsList(){
                      List<Product__c> pro;
        
        if(controller!=NULL){
            pro = controller.getRecords();
        }
        else{
            pro = NULL;
        }   
        return pro;
    }

    
    public PageReference Productdetail(){
        PageReference detail = new PageReference('/apex/ProductDetailPage?id='+pId);
        detail.setRedirect(true);
        return detail;
    }
    
    public Boolean getshowResultPanel(){
            if(con.getRecords().size()>0)
                return true;
                
             else
             return false;
    }
    public Boolean getNoResultPanel(){
        if(con.getRecords().size()==0)
        return true;
        else
        return false;
    }
    
       public Boolean getshowResultPanelFull(){
            if(controller.getRecords().size()>0)
                return true;
                
             else
             return false;
    }
    public Boolean getNoResultPanelFull(){
        if(controller.getRecords().size()==0)
        return true;
        else
        return false;
    }


  public Boolean  hasNextPage{
        get{
            return controller.gethasNext();
        }
        set;
    }
    
    public Boolean hasPreviousPage{
        get{
            return controller.gethasPrevious();
        }
        set;
    }
    
    public void nextpage(){        
        controller.next();    
    }        
    
    public void previouspage(){        
        controller.previous();    
    }
       
}

 

 

Damien_Damien_

This should allow you to easily change those values.  If you change the getter methods and use a contructor to set the values.

 

public String Term {get;set;}
public String SearchTerm {get;set;}

public ProductSearchController()
{
term = ApexPages.currentPage().getParameters().get('SearchParam');
searchTerm = ApexPages.currentPage().getParamters().get('SearchKeyword');
}
sravusravu

Thanks for your reply,

 

My issue is not with the Term and SearchTerm, my issue is with the inputfield in the second component. When i enter any search term in the first component that is carried to the second component but if I am entering a new seach value in the second component, that new value is not passed to the controller. Still it is taking the search parameter  from the first component. What i need is when i enter the search parameter in the second component, i want the controller to get that updated value. Not the attribute value.

sravusravu

Ok I could solve the problem by myself. I changed the attribute definition as follows

 

<apex:attribute name="SearchKeyword" type="string" description="Search Keyword"/>

This was selected as the best answer