+ Start a Discussion
MayTheForceBeWithYouMayTheForceBeWithYou 

Apex inputCheckbox tag not functioning properly

Hello all,

 

So I've been trying to develop a VF page that displays my environment's profiles alongside checkboxes in a pageBlockTable.  If a profile is selected, I would like it to appear below in a second pageBlockTable (I'll be adding other, cooler functionality later but I need to get this working first! :-D )

 

The first table loads correctly but for some reason my second table is not being loaded with values once they are selected; it appears like the page refreshes as it is supposed to, but no values are appended to the second table. I've been looking over the code but I just can't see where I've gone wrong so I thought a fresh set of eyes might help.  Here is my VF page and controller code-thanks very much!

 

P.S. Sorry about having some of the code in a different language! :-P

 

VF Page:

 

<apex:page standardController="Janela_de_Acesso__c" extensions="JDAPerfil" sidebar="false">
<apex:sectionHeader title="Janela de Acesso"/>
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection title="Informações" columns="2">
<apex:inputField required="true" value="{!Janela_de_Acesso__c.Name}"/>
<apex:inputField required="true" value="{!Janela_de_Acesso__c.Status__c}"/>
<apex:inputField required="true" value="{!Janela_de_Acesso__c.Data_Inicial__c}"/>
<apex:inputField required="true" value="{!Janela_de_Acesso__c.Data_Inicial__c}"/>
</apex:pageBlockSection>
<apex:pageBlockSection title="Perfils Disponíveis" columns="1">   
<apex:pageBlockTable value="{!myPerfils}" var="perfil">
<apex:column >
<apex:facet name="header">
<apex:inputCheckbox >
<apex:actionSupport event="onclick" action="{!GetSelected}" onsubmit="checkAll(this)" rerender="Selected_Profiles"/>
</apex:inputCheckbox>
</apex:facet>
<apex:inputCheckbox value="{!perfil.isSelected}" id="checkedone">
<apex:actionSupport event="onclick" action="{!GetSelected}" rerender="Selected_Profiles"/>
</apex:inputCheckbox>
</apex:column>
<apex:column headerValue="{!$ObjectType.Profile.Fields.Name.Label}" value="{!perfil.pro.Name}" />
</apex:pageBlockTable>
</apex:pageBlockSection>
<apex:pageBlockSection Title="Perfils Selecionados" id="Selected_Profiles">
<apex:pageBlockTable value="{!SelectedProfiles}" id="table" var="profile">
<apex:column value="{!profile.Name}" headerValue="{!$ObjectType.Profile.Fields.Name.Label}" />
</apex:pageBlockTable>
</apex:pageBlockSection>        
</apex:pageBlock>
</apex:form>
<script>
function checkAll(cb)
{
    var inputElem = document.getElementsByTagName("input");
    for(var i=0; i<inputElem.length; i++)
    {
        if(inputElem[i].id.indexOf("checkedone")!=-1)
            inputElem[i].checked = cb.checked;
    }
}    
</script>
</apex:page>

 

Controller:

 

public class JDAPerfil {
    
    public class profilewrapper
    {
        public Profile pro{get;set;}
        public Boolean isSelected{get;set;}
        public profilewrapper(Profile a){
            pro = a;   
            isSelected = false;
        }
    }
    
    List<profilewrapper> perfils = new List<profilewrapper>();
    List<Profile> selectedProfiles = new List<Profile>();
    
    public JDAPerfil(ApexPages.StandardController controller) {
    
    }
    
    public List<profilewrapper> getMyPerfils() {
        for (Profile p : [select Id, Name, Description from Profile where Name like '%X%']){
            perfils.add(new profilewrapper(p));
        }    
        return perfils;
    }
    
    public pageReference GetSelected(){
        selectedProfiles.clear();
        for(profilewrapper prowrapper : perfils){
            if(prowrapper.isSelected == true){
                selectedProfiles.add(prowrapper.pro);
            }
        }
        return null;    
    }   
        
    public List<Profile> getSelectedProfiles(){
        if(selectedProfiles.size()>0){
            return selectedProfiles;
        }
        else {
            return null;
        }
    }    

}

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
MayTheForceBeWithYouMayTheForceBeWithYou

UPDATE:

 

I discovered the reason it was not updating was because I had to first fill in the required fields above-I am relieved the main functionality is working but this then begs the question of how to allow the reRender to update the page even if the required fields aren't filled in; anyone know the answer to this? Thanks all!

 

P.S. Thanks to the users from the following thread that helped me discover the issue:

 

http://boards.developerforce.com/t5/Visualforce-Development/CheckBox-not-working-with-Action-Support/m-p/228829#M30957

All Answers

MayTheForceBeWithYouMayTheForceBeWithYou

So sorry-forgot to give credit where it is due! I used code from Rajesh Kulkarni's blog located here and then tweaked it to fit my own needs; if you're out there, thanks very much Rajesh!

 


 



MayTheForceBeWithYouMayTheForceBeWithYou

UPDATE:

 

I discovered the reason it was not updating was because I had to first fill in the required fields above-I am relieved the main functionality is working but this then begs the question of how to allow the reRender to update the page even if the required fields aren't filled in; anyone know the answer to this? Thanks all!

 

P.S. Thanks to the users from the following thread that helped me discover the issue:

 

http://boards.developerforce.com/t5/Visualforce-Development/CheckBox-not-working-with-Action-Support/m-p/228829#M30957

This was selected as the best answer
MayTheForceBeWithYouMayTheForceBeWithYou

Okay-problem solved: I can just have the VFPage load some default values so the required fields will be populated, thereby allowing the page to refresh as intended.