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
Dman100Dman100 

inputCheckbox is not getting set

I have a inputCheckbox and when the page posts back, the checkbox field is not getting set when the checkbox is selected.  I have a boolean property defined in the controller.  I'm not sure what I'm missing?

 

here is the VF code:

 

<apex:page Controller="AccountMaintenanceController"> <apex:form > <apex:pageBlock title="Update Account and Opportunity Ownership" mode="edit"> <apex:pageBlockButtons > <apex:commandButton action="{!updateAccountsOpportunities}" value="Update" rerender="UpdateAccountsOpportunitiesSuccessMsg" status="AccountsOpportunitiesLoadingStatus" /> <apex:commandButton action="{!cancel}" value="Cancel" immediate="true" /> </apex:pageBlockButtons> <apex:pageMessages rendered="true" id="UpdateAccountsOpportunitiesSuccessMsg" /> <apex:actionStatus id="AccountsOpportunitiesLoadingStatus"> <apex:facet name="start"> Updating records... <img src="{!$Resource.AjaxLoading}"/> </apex:facet> </apex:actionStatus> <apex:pageBlockSection title="Used to transfer ownership of accounts and opportunities from one sales rep to another" columns="1"> <apex:pageBlockSectionItem > <apex:outputLabel value="Change Owner From" for="old_account_owner" /> <apex:inputField value="{!AccountFrom.ownerId}" id="old_account_owner" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="Change Owner To" for="new_account_owner" /> <apex:inputField value="{!AccountTo.ownerId}" id="new_account_owner" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="Account Ownership" for="acct_owner" /> <apex:inputCheckbox value="{!acctChkbox}" id="acct_owner" /> </apex:pageBlockSectionItem> <apex:outputLabel value="{!acctChkbox}" /> <apex:pageBlockSectionItem > <apex:outputLabel value="Opportunity Ownership" for="oppy_owner" /> <apex:inputCheckbox value="{!oppyChkbox}" id="oppy_owner" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="Opportunity Email" for="oppy_email" /> <apex:inputCheckbox value="{!oppyEmailChkbox}" id="oppy_email" /> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>

 

Here is my controller class:

 

public class AccountMaintenanceController { private Account acctFrom = new Account(); private Account acctTo = new Account(); public PageReference updateAccountsOpportunities() { //List<Account> acctsFrom = [Select Id, OwnerId From Account where ownerId =: acctFrom.ownerId]; //List<Opportunity> oppys = [Select Id, OwnerId From Opportunity where ownerId =: acctFrom.ownerId]; //List<Account> acctsToUpdate = new List<Account>(); //for (Account acct: acctsFrom) //{ //acct.OwnerId = acctTo.OwnerId; //acctsToUpdate.add(acct); //} //if (acctChkbox == true) //{ //DbUtil.save(acctsToUpdate); //} //List<Opportunity> oppysToUpdate = new List<Opportunity>(); //for (Opportunity op: oppys) //{ //op.OwnerId = acctTo.ownerId; //oppysToUpdate.add(op); //} //if (oppyChkbox == true) //{ //DbUtil.save(oppysToUpdate); //} //List<Opportunity> oppysCommissionSalespersonToUpdate = new List<Opportunity>(); //for (Opportunity op: oppys) //{ //op.Commission_Salesperson__c = acctTo.ownerId; //oppysCommissionSalespersonToUpdate.add(op); //} //if (oppyEmailChkbox == true) //{ //DbUtil.save(oppysCommissionSalespersonToUpdate); //} //ApexPages.Message msg = new ApexPages.message(ApexPages.Severity.INFO, 'Records updated successfully.'); //ApexPages.addMessage(msg); //PageReference pr = System.Page.AccountMaintenance; //pr.setRedirect(true); //return pr; return null; } public PageReference cancel() { PageReference newpage = new PageReference(System.currentPageReference().getURL()); newpage.setRedirect(true); return newpage; } public Account getAccountFrom() { return acctFrom; } public Account getAccountTo() { return acctTo; } public Boolean acctChkbox { get { if (acctChkbox == null) { acctChkbox = false; } return acctChkbox; } set; } public Boolean oppyChkbox { get { if (oppyChkbox == null) { oppyChkbox = false; } return oppyChkbox; } set; } public Boolean oppyEmailChkbox { get { if (oppyEmailChkbox == null) { oppyEmailChkbox = false; } return oppyEmailChkbox; } set; } }

 

 

Thanks for any help.

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

You are re-rendering the checkbox, but not the label, so you can't guarantee that the value is still set to false.

 

Try re-rendering the entire pageblocksection - that way you will be sure you've re-rendered all the checkbox stuff.  I've found its worth adding an actionstatus to the command that is carrying out the re-rendering, to ensure that it is running to completion.

Message Edited by bob_buzzard on 10-16-2009 03:08 AM

All Answers

ThomasTTThomasTT
Try to re-render what you want to process, too, which are inputCheckboxes in this case. Now you're re-rendering only pageMessages.
ThomasTT
Dman100Dman100

I tried rerendering the inputCheckbox field, but it still does not set the value after the page posts back.  I have an output label showing the inputCheckbox is still set to false.

 

code:

 

<apex:page Controller="AccountMaintenanceController"> <apex:form > <apex:pageBlock title="Update Account and Opportunity Ownership" mode="edit"> <apex:pageBlockButtons > <apex:commandButton action="{!updateAccountsOpportunities}" value="Update" rerender="UpdateAccountsOpportunitiesSuccessMsg, acct_owner" status="AccountsOpportunitiesLoadingStatus" /> <apex:commandButton action="{!cancel}" value="Cancel" immediate="true" /> </apex:pageBlockButtons> <apex:pageMessages rendered="true" id="UpdateAccountsOpportunitiesSuccessMsg" /> <apex:actionStatus id="AccountsOpportunitiesLoadingStatus"> <apex:facet name="start"> Updating records... <img src="{!$Resource.AjaxLoading}"/> </apex:facet> </apex:actionStatus> <apex:pageBlockSection title="Used to transfer ownership of accounts and opportunities from one sales rep to another" columns="1"> <apex:pageBlockSectionItem > <apex:outputLabel value="Change Owner From" for="old_account_owner" /> <apex:inputField value="{!AccountFrom.ownerId}" id="old_account_owner" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="Change Owner To" for="new_account_owner" /> <apex:inputField value="{!AccountTo.ownerId}" id="new_account_owner" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="Account Ownership" for="acct_owner" /> <apex:inputCheckbox value="{!acctChkbox}" id="acct_owner" /> </apex:pageBlockSectionItem> <apex:outputLabel value="{!acctChkbox}" /> <apex:pageBlockSectionItem > <apex:outputLabel value="Opportunity Ownership" for="oppy_owner" /> <apex:inputCheckbox value="{!oppyChkbox}" id="oppy_owner" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="Opportunity Email" for="oppy_email" /> <apex:inputCheckbox value="{!oppyEmailChkbox}" id="oppy_email" /> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>

 

bob_buzzardbob_buzzard

You are re-rendering the checkbox, but not the label, so you can't guarantee that the value is still set to false.

 

Try re-rendering the entire pageblocksection - that way you will be sure you've re-rendered all the checkbox stuff.  I've found its worth adding an actionstatus to the command that is carrying out the re-rendering, to ensure that it is running to completion.

Message Edited by bob_buzzard on 10-16-2009 03:08 AM
This was selected as the best answer
ThomasTTThomasTT
bob_buzzard is right. Of course you need to re-render label to see the result. I assumed that you confirmed the value is not passes in the controller inthe controller side with debug log.