You need to sign in to do that
Don't have an account?
Is it possible to change Map values from visualforce page?
I want to create a table that displays some time slots with a checkbox next to it. At the end of the table, there's a submit button. For the table, I used a Schedule__c object and also declared a Map, with the boolean being the default value for the checkbox.
This is the UI:

This is a part of my VF code:
This is part of my controller:
This is where I assign the default values to the Map, which has no problems at all.
This is supposed to be my Submit function. It's not done yet because I'm trying to get the new values for the input checkboxes first.
This is what I get in the Logs:

This is the UI:
This is a part of my VF code:
<apex:form id="results"> <!-- <apex:outputText rendered="{!availableCourses.size == 0}" value="{!$Label.noResults}" /> --> <br/> <table style="width:100%"> <thead> <th>{!$Label.timeSlot}</th> <th>{!$Label.courseStatus}</th> <th>chose</th> </thead> <tbody> <apex:repeat value="{!availableCourses}" var="result"> <apex:param value="{!courseOptions}"/> <tr> <td class="courseTime"> <apex:outputText value="{!result.Time__c}"></apex:outputText> </td> <td>test</td> <td><apex:inputCheckbox value="{!courseOptions[result]}"/></td> </tr> </apex:repeat> </tbody> </table> <br/> </apex:form> <apex:form> <apex:commandButton value="{!$Label.submit}" action="{!Submit}" styleClass="btn btn-block" style="margin:0px;"> </apex:commandButton> </apex:form>
This is part of my controller:
This is where I assign the default values to the Map, which has no problems at all.
for(ScheduleSetting__c a: availableCourses){ courseOptions.put(a, false); }
This is supposed to be my Submit function. It's not done yet because I'm trying to get the new values for the input checkboxes first.
public Pagereference Submit() { system.debug('aaa'); for(ScheduleSetting__c key : courseOptions.keySet()){ system.debug(courseOptions.get(key)); } return null; }The problem is that even though I check the inputCheckBox when Submit gets called, the Map values don't change at all. I just want to be able to change the Map Boolean values depending on whether the checkbox is checked or not.
This is what I get in the Logs:
Uniqueness of map keys of user-defined types is determined by the equals and hashCode methods, which you provide in your classes. Uniqueness of keys of all other non-primitive types, such as sObject keys, is determined by comparing the objects’ field values.
If you change one of the value of the fields of the object used as a key, the equality test done internally is broken.
I have used : <td><apex:inputCheckbox value="{!courseOptions[result.myId]}"/></td>
or
All Answers
public List<MyObject> availableCourses {get;set;}
public Map<String,Boolean> courseOptions {get;set;}
Thanks a lot for your reply. I'm still unable to get my changed values.
This is how I declared my maps: I ended up changing both maps to contain sObject instead.
I recently changed the form issue. However, I still can't change the boolean values from the courseOptions map. This is how I populate both Maps: I changed the ln 18 of the VF page: This is my save function (Still not complete since I can't still get the new values):
Uniqueness of map keys of user-defined types is determined by the equals and hashCode methods, which you provide in your classes. Uniqueness of keys of all other non-primitive types, such as sObject keys, is determined by comparing the objects’ field values.
If you change one of the value of the fields of the object used as a key, the equality test done internally is broken.
I have used : <td><apex:inputCheckbox value="{!courseOptions[result.myId]}"/></td>
or