You need to sign in to do that
Don't have an account?
Srt
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 ?
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 ?
May I suggest you please refer the below link for reference.
- http://www.forcetree.com/2009/07/getter-and-setter-methods-what-are-they.html
Let us know if it helps.Thanks
Rahul Kumar
I have seen that, My query is why the other two ways not working?