0

I’ve tried so many ways and days to try to make this work but can’t get it to behave. Other posts seem to indicate that this doesn’t work. But i really need it so here goes..

Problem:

inputCheckbox works wonderfully for checking and unchecking the box, making the value avail to apex, etc... What is won't do, it seems, is allow you to set the checkbox based upon a data value (or conditional if one tried selected="some condition").(rating__c is a picklist)

Apex class MainController

public Boolean ABCCheckbox {get; set;} 
public Boolean IsABC { 
       get{if (appl==null) return false;     
           if (appl.rating__c==‘ABC’) return true; return false;} set;}   

…startup, so not null or otherwise wonky...
ABCCheckbox           = false; 

…later & before page loads, ABCCheckbox set true…
if (appl.rating__c==‘ABC’) ABCCheckbox = true;

VF Page:

<apex:page controller="MainControllerClass" >
 <apex:form id="abcForm">
 <apex:pageBlock >
  <apex:outputPanel styleClass="panelWrapper" layout="block">
…
 <apex:outputPanel id="abcDetailPanel" layout="block">
    <apex:pageblocksection id="abcDetail"> 
…            
        <apex:pageBlockSectionItem >
          <apex:outputLabel value=“Check if ABC applies?”/>
          <apex:inputCheckbox value="{!ABCCheckbox}" selected="{!IsABC}"/>
       </apex:pageBlockSectionItem>
…
    </apex:pageblocksection>
  </apex:outputPanel>
...
  </apex:outputPanel>
  </apex:pageBlock>
  </apex:form>
</apex:page>

I've also tried many variations using ActionRegions...(although these confuse me sometimes)

<apex:pageBlockSectionItem >
          <apex:outputLabel value=“Check if ABC applies?”>
          <apex:outputPanel layout="block">
             <apex:actionRegion >
            <apex:inputCheckbox value="{!ABCCheckbox}" selected=“true” >
             </apex:actionRegion>
          </apex:outputPanel>       
</apex:pageBlockSectionItem>

…and if i do this, it is checked upon load/rerender but that doesn’t help except shows me “selected” can work sometimes…

<apex:pageBlockSectionItem >
          <apex:outputLabel value=“Check if ABC applies?”>
          <apex:outputPanel layout="block">
             <apex:actionRegion >
            <apex:inputCheckbox value="{!ABCCheckbox}" selected=“true” >
             </apex:actionRegion>
          </apex:outputPanel>       
</apex:pageBlockSectionItem>

When i check the value of ABCCheckbox, it is indeed checked if the user clicks it. I just can’t load the page with it already checked based upon a data value or a conditional. :-(

Anyone?

0

I tried this and its working for me

Apex Class - Controller

public class TestController {
    public String testVal { get; set; }
    public boolean testBoolCheck {get {{if (testVal =='ABC') return true; return false;}} set;}
    public boolean testBoolUncheck {get {{if (testVal =='XYZ') return true; return false;}} set;}

    public TestController() {
        testVal = 'ABC';
    }

}

VF Page

<apex:page controller="TestController">
    <apex:form>
        Check: <apex:inputCheckbox value="{!testVal}" selected="{!testBoolCheck}" />
        Uncheck: <apex:inputCheckbox value="{!testVal}" selected="{!testBoolUnheck}" />
    </apex:form>
</apex:page>

and its selecting the inputCheckbox Check: and not selecting the checkbox Uncheck enter image description here

I highly suspect your rating__c value

0

It turned out that this problem was "fixed" by changing the "Salesforce API" to 36.0 under the "Version Settings" tab on the page edit window. It was at 34.0.

[ This makes me nervous, however, because every time we change the version, many old problems that we spent so much time to fix/find workarounds will now break. :-\ ]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.