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
SathishKumarSathishKumar 

Pass Value From visualforce page to apex controller

Hi All,

I am completely new to Apex and visualforce progamming.
I was trying to develop a visualforce page, which accepts values and i am trying to display the accepted values in debug screen.

I ve written the following vf page:
<apex:page controller="setExample">
    <apex:form>
    <apex:outputLabel>Enter u r name</apex:outputLabel>
       <apex:inputText value= "{!name}" />
        <apex:commandButton value="Click" rerender="one"/>
         <apex:outputLabel id="one">Name is {!name} </apex:outputLabel>
    
    </apex:form>
</apex:page>

and below controller

global class setExample {
    
    public String name;
    public Integer age;
    
    public void setName(String name){
        
        this.name = name;
        System.debug('Name ='+name);
    }
    
    public void setAge(Integer age){
        
        this.age = age;
        System.debug('Age is '+age);
    }

}

i am getting following error


Unknown property 'setExample.name'

Please guide me, where am i going wrong.

Thanks in advance
Dilip_VDilip_V
Satish,

You have to declare name like this in controller to access it in VF page.

Public string name{get;set}

Try this class
 
global class setExample {
    
    public String name{get;set;}
    public Integer age;
    
    public void setName(String name){
        
        this.name = name;
        System.debug('Name ='+name);
    }
    
    public void setAge(Integer age){
        
        this.age = age;
        System.debug('Age is '+age);
    }

}

Let me know if you have any issues.

Mark it as best answer if it works.

Thanks.