You need to sign in to do that
Don't have an account?
sfdcFanBoy
Pageblock Checkbox value not captured in wrapper class
I have a pageblock with 2 columns and a ceckbox column.. when I select the checkbox, the value is not being captured. Yes im using the wrapper class as per the salesforce example.
In my code, the list "selectedEngs" is empty. To this list, Im adding the selected rows. But the size is zero, even after checkbox is ticked.
Did I miss anything, below is my code. Please let me know.
VF Page: 2 columns. one is checkbox
Apex class
Cheers!
In my code, the list "selectedEngs" is empty. To this list, Im adding the selected rows. But the size is zero, even after checkbox is ticked.
Did I miss anything, below is my code. Please let me know.
VF Page: 2 columns. one is checkbox
<apex:repeat value="{!Engagements}" var="item"> <apex:pageBlockSection id="Selected_PBS" columns="3" > <apex:outputPanel layout="block"> <label>Program</label> <apex:outputText value="{!item.eng.Program__c}"/> </apex:outputPanel> <apex:outputPanel layout="block"> <apex:inputCheckbox value="{!item.selected}" id="checkedone"> <apex:actionSupport event="onclick" action="{!GetSelected}" rendered="false"/> </apex:inputCheckbox> </apex:outputPanel> </apex:pageBlockSection> </apex:repeat>
Apex class
List <Engagement__c> selectedEngs = new list<Engagement__c>(); List<EngagementWrapper> engList = new List<EngagementWrapper>(); public PageReference getSelected() { selectedEngs.clear(); for(EngagementWrapper engwrapper : engList) { if(engwrapper.selected == true) selectedEngs.add(engwrapper.eng); } return null; } public List<EngagementWrapper> getEngagements() { engList.clear(); for(Engagement__c e : studentList) engList.add(new EngagementWrapper(e)); return engList; } public List<Engagement__c> GetSelectedEngs() { if(selectedEngs.size()>0) return selectedEngs; else return null; }
Cheers!
This must be due to one of the following reasons
I am not sure why you are using Action support, you can grab all selected items by iterating wrapper list.
You can remove that action support and you can add that grabbing the selected items code inside the button.
If you want to select some items and then continue to select, you can add one more button where you will get the items and renders the pageblock.
In the main class :
If the above change doesn't work, I suggest you to remove Actionsupport and
Call the method 'Getselected()' from a command button like 'Add Itmes'
I hope adding the property will solve your issue.
if this is fixed, everything should be working fine.
I have tried all your suggestions. I have now removed actionSupport and used that action method code in a command button. still this is not setting to true.
Make sure that you have the property for 'engList'
Try debugging 'engWrapper.selected' in side grabbing the records.
captured in save method.
You are not setting the value 'selected' in the list engList.
In the pageblock try this