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
Mary Pamishetty 3Mary Pamishetty 3 

pass values to component from vf page

Hi,
I have inputtext field(<apex:inputText id="idSearchGlobal" />) in  vf page (not using any custom controller and extender in vf page)and  want to pass that inputtext  value to the component .
So my question is how to assign this inputtextfield value to component attribute.
     <c:GlobalSearch_Component attributevalue='..how i need to pass inputtextfield value here............'></c:GlobalSearch_Component>
 
LBKLBK
Hi Mary,

You need APEX to do that. It could be either a custom controller or an extension.

You can define a variable in the controller and use it on your text field as well as the component.

Your APEX class will look like this.
public class YourClassName{
	public String sTextValue {get; set;}
	public YourClassName(){
		
	}
}
And your VF code will look like this.
<apex:inputText id="idSearchGlobal" value="{!sSearchGlobal}" />

<c:GlobalSearch_Component attributevalue="{!sSearchGlobal}"></c:GlobalSearch_Component>
Hope this helps.

 
LBKLBK
Can you post your class file and VF pages (and components), so that we can take a better look at your code?
Mary Pamishetty 3Mary Pamishetty 3
following is the vf page
<apex:page docType="html-5.0" applyBodyTag="false" applyHtmlTag="false" showHeader="false" standardStylesheets="false"  standardController="Lead" extensions="GlobalSearch_Extender">

   <apex:inputText id="idSearchGlobal" style="border-radius:10px;" value="{!searchStr}" /> 
                 <!--      <button type='button'  class="rounded" id="searchText" data-toggle="modal" href="#globaSearch" >Search</button> -->
       
                 <apex:commandButton value="Search"  html-data-toggle="modal" html-data-target="#globaSearch" rerender="true" immediate="true"/>
                    
                         <div id="globaSearch" class="modal fade" role="dialog" width="100%">
                                    <div class="modal-dialog">
                                        {!searchStr}
                                        <!-- Modal content-->
                                        <div class="modal-content">
                                            <div class="modal-header">
                                                <button type="button" class="close" data-dismiss="modal">&times;</button>
                                                <h4 class="modal-title">Search Results</h4>
                                            </div>
                                            <div class="modal-body">      
                                           <c:GlobalSearch_Component searchGlobal="{!searchStr}" rerender="idSearchGlobal"></c:GlobalSearch_Component> 
                                                
                                            </div>
                                            
                                        </div>
                                        
                                    </div>
                                </div>


and the extender is 

public class GlobalSearch_Extender{
    public string searchStr{get; set;}
    
    public GlobalSearch_Extender(){}
    public GlobalSearch_Extender(ApexPages.StandardController controller)
    {}
}


and component is 

<apex:component controller="GlobalSearch" allowDML="true">  
     <apex:attribute name="searchGlobal" type="string" description="TODO: Describe me" assignTo="{!searchStr}" />
    <apex:attribute name="rerender" type="String" description="TODO: Describe me" required="true"/>

   
    <script type="text/javascript">
    function closeMe(lid){
        //   window.location.href ='/apex/Lead_Layout_Template?id='+lid;  
        //  window.close(); 
        setTimeout(function(){document.location.href = '/apex/Lead_Layout_Template?id='+lid},50);
    }
    </script>        
    <div class = "bs" style="padding:3px;">  
        
        <!-- <apex:inputText value="{!searchStr}" style="border-radius:10px;"/>
<apex:commandButton value="Search" action="{!searchText}"  style="border-radius:10px;"/>-->
                
        <apex:outputPanel title="" id="error">
            <apex:pageMessages ></apex:pageMessages>
        </apex:outputPanel>
        <div class="row">
            <apex:pageBlock title="Leads" id="leads">
                <table class="table table-striped text-centered" cellspacing="40" style="white-space:nowrap; width:100%;" id="GlobalSearchLeadsTable" >                
                    <thead>                
                        <tr>
                            <td></td>
                            <td>Name</td>
                            <td>Email</td> 
                            
                            
                        </tr>
                    </thead>
                    <tbody>
                        <apex:repeat value="{!leadList}" var="lead" >
                            <tr class="repeater">
                                <td></td>
                                <td> 
                                    
                                    <apex:commandLink value="{!lead.Name}" onclick="closeMe('{!URLENCODE(LEFT(lead.id,15))}');return true;"> </apex:commandLink>
                                </td> 
                                <td >
                                    <apex:commandLink value="{!lead.email}" onclick="closeMe('{!URLENCODE(LEFT(lead.id,15))}');return true;"></apex:commandLink>
                                </td>
                                
                                
                            </tr>
                        </apex:repeat> 
                    </tbody>
                </table>
            </apex:pageBlock>
        </div>
        <div class="row">
             <apex:pageBlock title="Contacts" id="conts">
            <table class="table table-striped text-centered" cellspacing="40" style="white-space:nowrap; width:100%;" id="GlobalSearchContactsTable" >                
                <thead>                
                    <tr>
                        <td></td>
                        <td>Name</td>
                        <td>Email</td> 
                        
                        
                    </tr>
                </thead>
                <tbody>
                    <apex:repeat value="{!conList}" var="cont" >
                        <tr class="repeater">
                            <td></td>
                            <td> 
                                
                                <apex:commandLink value="{!cont.Name}" onclick="closeMe('{!URLENCODE(LEFT(cont.id,15))}');return true;"> </apex:commandLink>
                            </td> 
                            <td >
                                <apex:commandLink value="{!cont.email}" onclick="closeMe('{!URLENCODE(LEFT(cont.id,15))}');return true;" ></apex:commandLink>
                            </td>
                            
                            
                        </tr>
                    </apex:repeat> 
                </tbody>
            </table>
            </apex:pageBlock>
        </div>
    </div>
</apex:component>

and controller for component is 


Public with sharing class GlobalSearch{
 Public List<Lead> leadList {get;set;}
 Public List<contact> conList{get;set;}
 
   Public String searchStr1;
 Public String getsearchStr(){
     return searchStr1;
 }
     Public void setsearchStr(string s)
     {try{
         searchStr1=s;
         searchText();}
      catch(exception ex){}
     }
    
   Public GlobalSearch(){
   }
  
  Public void searchText(){
   leadList = New List<Lead>();
   conList = New List<contact>();
  system.debug('searchStr'+searchStr1);
   if(searchStr1.length() > 1){
   String searchStr2 = '*'+searchStr1+'*';
   String searchQuery = 'FIND \'' + searchStr2 + '\' IN ALL FIELDS RETURNING  Lead(Id,Name,email),Contact(name,email)';
   List<List <sObject>> searchList = search.query(searchQuery);
   leadList = ((List<Lead>)searchList[0]);
   conList  = ((List<contact>)searchList[1]);
 system.debug('leadList.size()'+leadList.size());
   if(conList.size() == 0 && leadList.size() == 0){
       apexPages.addmessage(new apexpages.message(apexpages.severity.Error, 'Sory, no results returned with matching string..'));
       return;
   }
   }
   else{
   apexPages.addmessage(new apexpages.message(apexpages.severity.Error, 'Please enter at least two characters..'));
   return;
   }
  }
}