You need to sign in to do that
Don't have an account?

Controller Extension using checkbox
I am trying to write a controller extension where I have created two custom checkbox fields and I want to create two boolean properties to be used with these checkboxes.
I have
if(checkbox1 == 'true'){ ca = true; } if(checkbox2 == 'true'){ cred = true; } public Boolean cred{ get{ if(cred == null){ cred = false; } return cred; } set; } //Property for client agreement checkbox public Boolean ca{ get{ if(ca == null){ ca = false; } return ca; } set; }
I am not sure how to set the checkbox to true or false in apex code. I get an error saying "Comparison Argument must be compatible types:Schema.SObjectField, string"
Any ideas on how to handle this? I am trying to use this boolean property to render pageblock sections in a visualforce page.
Thanks.
I don't know what exactly you're trying to do... but if you use inputCheckbox and boolean, passing values are pretty much easy.
<apex:inputCheckbox value="{!ca}"/>
public class YourExtension { public Boolean ca{ get{ // This is a nice way to set initial value!!! if(ca == null){ ca = false; } return ca; } set; } }
and if you want to render some pageBlock based on the change of the boolean, you just do
<apex:inputCheckbox value="{!ca}"> <apex:actionSupport event="onchange" reRender="pageBlock"/> </apex:inputCheckbox> <apex:pageBlock id="pageBlock">
<apex:pageBlockSection reRender="{!ca}">
...
<apex:pageBlockSection>
</apex:pageBlock>
But, if you want to show/hide the pageBlock itself, you need to re-render bigger area than the pageBlock itself. I assumed that you want to show/hide a pageBlockSection and re-render a pageBlock which contains the section.
ThomasTT
I'm sorry. I don't follow what you mean by "existing checkbox". You wrote you created extension, which means this is about VF page and everything is created by you. What do you mean by "existing checkbox"?
ThomasTT
so when I create a vf page i can say <apex:inputfield "{!Opportunity.StageName}"/>
And that field will display on my page as an editable field. I want to do that with a checkbox I have already created. with the inputCheckBox tag I would create the checkbox there and create a label for it using the label tag. So the checkbox does not really exist as a "Row" in the object table. If that makes sense. At least that is my understanding of how the inputCheckBox tag works.
apex:inputField works for checkbox field... if that's the question...
input/outputField (rather than input/outputText) changes its UI component based on the type of SFDC SObject field. If it's date field, with calendar, if it's checkbox, with checkbox.
That's the beauty of inputField/outputField.
ThomasTT