You need to sign in to do that
Don't have an account?
how to initialize a method without constructor.
sir, i am using list program. This is a apex class program. here i am getting all the colors vales at VF page. VF page and Apex page is working well. here my doubt is how can i use this apex program without constructor. please help. thanks in advance.
I tried this, but it is giving error.
Vf page ( for your reference):-
public class listcolor { public list<string> color{set;get;} public listcolor() { color=new list<string>{'red','white','green'}; list<string> myval=new list<string>(); myval.addall(color); } }
I tried this, but it is giving error.
public class listcolor { public list<string> color{set;get;} mycolors(); public void mycolors() { color=new list<string>{'red','white','green'}; list<string> myval=new list<string>(); myval.addall(color); } } OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR public class listcolor { public list<string> color{set;get;} public list<string> mycolors() { color=new list<string>{'red','white','green'}; list<string> myval=new list<string>(); myval.addall(color); return color; } }
Vf page ( for your reference):-
<apex:page controller="listcolor" title="list of colors"> <apex:form> <apex:pageblock> <apex:pageblocktable var="a" value="{!color}"> <apex:column headervalue="colors" value="{!a}" /> </apex:pageblocktable> </apex:pageblock> </apex:form> </apex:page>
Typically, using a constructor is a way to go. However if you do not want to use the constructor then you would have to call the controller method from your visualforce page so that the method gets executed.
Hope that helps!
All Answers
Typically, using a constructor is a way to go. However if you do not want to use the constructor then you would have to call the controller method from your visualforce page so that the method gets executed.
Hope that helps!
According to VF page life cycle :-
Constructor of controller /extension - > constructor of custom components -> AssignTo any Custom Components -> Action method->Getter or Setter -> Form method -> HTML
http://amitsalesforce.blogspot.in/2015/04/visualforce-page-life-cycle-in.html
if you dnt want to call constructor then you can try action method. But as best practice always use constructor and use action method only when you need to do any DML while loading the VF page.
You Can try beloe code without constructor Please mark this as solution if this will help you
Thanks
Amit Chaudhary
Try below code:-
Below is Order of execution for VF page :-
1) Constructor of controller /extension
2) constructor of custom components
3) AssignTo any Custom Components
4) Action method
5) Getter or Setter
6) Form method -> HTML
If you dnt want to use constructor then you can use action Method of getter/setter direclty
Hope this will help you.