You need to sign in to do that
Don't have an account?
Walter@Adicio
Is there a easy way to set a boolean based on the size of a list?
I was trying to see if I can do it with something like this.
public boolean productAndServicesPod { get; set;} {if(quotes.size()==0)productAndServicesPod=false;}
You could do it two ways:
public class TestForBlog { public boolean productAndServicesPod { get; set;} public TestForBlog() { productAndServicesPod = (quotes.size()==0)? false : true; } }
Since the constructor is run first when the controller is called it will set the value for you.
The syntax of the inline if/then statment I used is as follows
value = (condition) ? true : false;
also could be written
if (condition) { value = true; } else { value = false; }
The second way would be:
private boolean pproductAndServicesPod; public boolean productAndServicesPod { get { return (quotes.size()==0)? false : true; } set { this.pproductAndServicesPod = value; } }
All Answers
You could do it two ways:
public class TestForBlog { public boolean productAndServicesPod { get; set;} public TestForBlog() { productAndServicesPod = (quotes.size()==0)? false : true; } }
Since the constructor is run first when the controller is called it will set the value for you.
The syntax of the inline if/then statment I used is as follows
value = (condition) ? true : false;
also could be written
if (condition) { value = true; } else { value = false; }
The second way would be:
private boolean pproductAndServicesPod; public boolean productAndServicesPod { get { return (quotes.size()==0)? false : true; } set { this.pproductAndServicesPod = value; } }
Hi Bbrantly1,
Is this regular JAVA syntax versus apex specific? This is working for me by the way, thanks again.
private boolean ccustomer;public boolean customer{get{return (customerList.size()==0)? false : true;} set{this.ccustomer = value;}}
Thank you,
Walter
I'm glad it's working and what you were looking for.
value = (condition) ? true : false; Can be used in almost all programming languages
The other method is also very common in other languages.
So to answer your question, neither. They aren't Java or apex specific.
Hope this helps.
Yes singling this out does help me, thanks again.
value = (condition) ? true : false;
The only thing i changed was a add a {get;set;} to the private boolean so I can call to that in a rendered attribute in the visualforce page.
private boolean showCustomer {get;set;}public boolean customer{get{return (customerList.size()==0)? false : true;} set{this.showCustomer = value;}}
<apex:outputPanel layout="block" rendered="{!showCustomer}">
Assuming you are never writing to the showCustomer boolean, you don't need a seperate var. You can simply use:
public boolean customer { get { return (customerList.size()==0)? false : true; } }
There is no need for a seperate boolean (showCustomer in this case)
You could also do it like this:
public boolean getCustomer() { return (customerList.size()==0)? false : true; }
Of course if you are writing back to the showCustomer boolean you will need to use a seperate boolean value like you have done.
This is great, you are right, I only need this.
public boolean customer{get{return (customerList.size()==0)? false : true;}}