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
DCSDCS 

Getting value from apex:inputText field

Do I need to use setter method to get the value of  <apex:inputText> in visual force? For ex: I have a VF page which has a search input field and a search command button

 

       <apex:pageBlock >
         
            <apex:inputText id="searchText" size="50" />
            <apex:commandButton action="{!doSearch}" value="Search" reRender="productList" status="status" />
           
       </apex:pageBlock >  
      
      
      

In the controller, I have a doseacrch() method, but I am not able to get the searchText value as  

public void doSearch()

{

 

 String searchText = ApexPages.currentPage().getParameters().get('searchText');

 

}

 

whereas if I have a hidden field in the form, I can get the value using ApexPages.currentPage().getParameters().get('hiddenfieldname);

 

Can some one please explain

    

Message Edited by DCS on 04-17-2009 01:27 PM
Best Answer chosen by Admin (Salesforce Developers) 
JimRaeJimRae

you need to include a value element on your inputtext, and reference that with the setter.

 

 

<apex:robottongue:ageBlock > <apex:inputText id="searchText" value="{!mysearchtext}"size="50" /> <apex:commandButton action="{!doSearch}" value="Search" reRender="productList" status="status" /> </apex:pageBlock >

 Then in your method, you have the setter and getter.

 

 

public String mysearchtext {get; set;} public void doSearch() { system.debug(mysearchtext);// this will show the value of mysearchtext //put your search code here }