2

Putting checkbox inside outputpanel or using rendered on itself, will display correctly, but will cause null de-reference when its used in the class.

What is the reason behind?

This works:

<apex:inputCheckbox value="{!receiveCopy}" title="It will send a copy" />Receive a copy of email. 

This does not:

<apex:outputPanel rendered="{!renderBox}">
     <apex:inputCheckbox value="{!receiveCopy}" title="It will send a copy" />Receive a copy of email. 
</apex:outputPanel>

Neither this:

<apex:inputCheckbox rendered="{!renderBox}" value="{!receiveCopy}" title="It will send a copy" />Receive a copy of email. 

Controller

public boolean receiveCopy{get;set{receiveCopy= value;}}
public PageReference selectContractor (){
        boolean receiveCopy;
        if(receiveCopy==null){
             receiveCopy = false;
        }
        selectedCase.Receive_Copy__c = receiveCopy; //   <-- Error here

Edit: Please note, that error happens irrespectively if box is checked or not. It always comes up as null.

  • please add your VF controller (the essence only please) - unlike SObject boolean fields, a controller Boolean will not be initialized to true or false; it will initialize to null so any reference to that controller variable before being set will cause a attempt to deref null object. A useful best practice is to make the getters for controller booleans do something like this: return foo == null ? false : foo; – cropredy May 5 '15 at 1:40
  • In this case the foo will always be false. – dzh May 5 '15 at 2:17
  • not true; if setter has executed from a checkbox checked true, , foo will be true – cropredy May 5 '15 at 18:45
1

I've found the problem.

The variable that is used in rendered="" parameter was set as transient.

Probably it is somehow unreachable by VF after first instantiate in pageblockTable earlier in the page.

| improve this answer | |
  • Also be careful with two same declaration of variable name receiveCopy at class level and method level.It might confuse you in future. – unidha May 5 '15 at 2:34

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.