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
SrtSrt 

how get and set works?

I am new to VF and Apex coding and I tried to display 'Hai + text i have entered' in an Visualforce page.
The below code works fine

VF code:

<apex:page controller="disptxt3">
  <apex:form id="form">
  <apex:pageBlock >
  <apex:pageBlockSection >
  <apex:inputtext value="{!textdata}" label="Enter your text"  />
  <apex:outputText value="{!textdatam}" rendered="{!c}" label="Value you entered " />
  </apex:pageBlockSection>
  </apex:pageBlock>  
  </apex:form>
</apex:page>

Class:

public with sharing class disptxt3 {
public string textdata{get;set;}
public boolean c;
public boolean getc()
{
{if(textdata == null) 
       c = false; 
  else c = true;
  }
return c;}
public string gettextdatam()
{
string t = 'Hai ' + textdata;
return t;
}
}

But below doesnot work: Output box not at all displayed
Class:

public with sharing class disptxt3 {
public string textdata{get;
                       set;}
public boolean c;
public disptxt3()
{
{if(textdata == null) 
       c = false; 
  else c = true;
  }
}
public boolean getc()
{
return c;
}
public string gettextdatam()
{
string t = 'Hai ' + textdata;
return t;
}
}
and this too doesnot work; Output box not displaying at all
Class:

public with sharing class disptxt3 {
public string textdata{get;
                       set;}
public boolean c;
public void Setc()
{
{if(textdata == null) 
       c = false; 
  else c = true;
  }
}
public boolean getc()
{
return c;
}
public string gettextdatam()
{
string t = 'Hai ' + textdata;
return t;
}
}

Could you help me figure out why the other ways are not working? Please explain in detail ?
Rahul KumarRahul Kumar (Salesforce Developers) 
Hi,
May I suggest you please refer the below link for reference. Let us know if it helps.

Thanks
Rahul Kumar
SrtSrt
Hi ,

I have seen that, My query is why the other two ways not working?