You need to sign in to do that
Don't have an account?
Vijay Kumar Rebbala 11
How to Pass input Checkbox values from visualforce page to controller
Initially I have set all the InputCheckbox values to false. And shown the values on PageblockTable in VFP. When user changes the checkbox values and click submit, I wanted to get all the new Checkbox values. How can i do that.
//VFP: <apex:page controller="Testctrl"> <apex:form > <apex:pageBlock > <apex:pageBlockTable value="{!attdmap}" var="attdkey"> <apex:column value="{!attdkey.Name}"/> <apex:column> <apex:facet name="header">Absent</apex:facet> <apex:inputCheckbox label="Absent" value="{!attdmap[attdkey]}" /> </apex:column> </apex:pageBlockTable> </apex:pageBlock> <apex:commandButton action="{!submit}" value="Submit"/> </apex:form> </apex:page> //CTRL: public class Testctrl { public list<Student__c> acctlist {get;set;} public Map<Student__c, Boolean> attdmap{get;set;} public Testctrl(){ attdmap = new Map<Student__c, Boolean>(); acctlist = [SELECT Id, Name FROM Student__c]; for(Student__c atu23 : acctlist){ attdmap.put(atu23,False); } } public void submit(){ } }
AttendanceController.cls
Attendance.vfp
The page needs some stylization work but it's functional. After you click submit it will not refresh the page or take you anywhere else (you'll need to do that yourself by returning a valid PageResult instance). After clicking submit the page will insert all of the Attendance__c objects.
This should at least help you to understand how you can do what I think you're trying to do. If this does not help, let me know.
All Answers
I got the error when i tried your code.
Incorrect parameter type for subscript. Expected java.lang.Class, received Text
Error is in expression '{!attdmap[attdkey.Id]}' in component <apex:inputCheckbox> in page testpage
So, i removed the ID from 8th line of VFP. and executed. I have added debug log in submit button to check the map values but no result.
Still getting the same error: Unknown property 'String.Id'
Error is in expression '{!attdmap[attdkey.Id]}' in component <apex:inputCheckbox> in page testpage.
Don't you thing Onclick event on inputcheckbox can send the values to the controller. Tried in this way but no expected results. I might be missing something
AttendanceController.cls
Attendance.vfp
The page needs some stylization work but it's functional. After you click submit it will not refresh the page or take you anywhere else (you'll need to do that yourself by returning a valid PageResult instance). After clicking submit the page will insert all of the Attendance__c objects.
This should at least help you to understand how you can do what I think you're trying to do. If this does not help, let me know.
<apex:page controller="DisplayOptyStage"> <apex:form > <apex:pageBlock > <apex:inputCheckbox label="AA" value="{!opp.stagename}"/> <apex:commandButton VALUE="CLICK HERE" action="{!DisplayOptyStage1}"/> <apex:pageBlockTable value="{!opty1}" var="v"> <apex:column value="{!v.Name}"/> <apex:column value="{!v.Amount}"/> <apex:column value="{!v.StageName}"/> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>
APEX CLASS
public class DisplayOptyStage{
public Opportunity opp{get;set;}
public List<Opportunity> opty1{get;set;}
public DisplayOptyStage() {
opp=new Opportunity();
opty1=new List<Opportunity>();
}
public pagereference DisplayOptyStage1()
{
system.debug('--opp.stagename--'+opp.stagename);
opty1=[select Name,Amount,stagename from opportunity where stagename =:opp.stagename];
return null;
}
Visualforce page
Controller
You will want to add error handling incase someone unchecks both boxes since that will give you bad results.
NOTE: This code has not been tested and may contain typographical or logical errors
NOTE: When adding code please use the "Add a code sample" button (icon <>) to increase readability and make it easier to reference.