+ Start a Discussion
prettynerdprettynerd 

Visualforce Map Binding NOT Working???

Need help badly.. T_T

The Map Collection below doesn't store the value that a User enters.. if I try to display the values of the Map, everything is NULL.. anybody, please help..


//In My Controller:

public Map<Integer,Field_Type__c> varFieldTypes {get;set;}
public PageReference MyMethod(){
varFieldTypes = new Map<Integer,Field_Type__c>();
for(Integer i=0; i<10; i++){
varFieldTypes.put(i,new Field_Type__c());
}
return Page.NewPage();
}

 


//In My VF Page:

<apex:variable var="c" value="{!0}"/>
<apex:repeat value="{!someCollection}" var="myVar">
<apex:inputField value="{!varFieldTypes[c].Text__c}"/>
<apex:variable var="c" value="{!c+1}"/>
</apex:repeat>

 

 

Best Answer chosen by Admin (Salesforce Developers) 
aballardaballard

You cannot use apex:variable as an "iteration variable" in repeat.   The value will not be updated for each iteration the way your code expects. 

 

You should be able to just iterate over the map directly... e.g.

 

<apex:repeat value="{!mymap} var="m"/> 

 

makes m reference sucessive elements of the map. 

All Answers

Shashikant SharmaShashikant Sharma

You havee set a new Field_Type__c record in map which has null in Text__c value, change it to

 

public Map<Integer,Field_Type__c> varFieldTypes {get;set;}
public PageReference MyMethod(){
varFieldTypes = new Map<Integer,Field_Type__c>();
for(Integer i=0; i<10; i++){
varFieldTypes.put(i,new Field_Type__c(Text__c = 'Test Text'));
}
return Page.NewPage();
}

 you will see the values the. , let me know if any issues in it.

prettynerdprettynerd

I needed the field to be empty, thus, assigning it to an inputField in the VF Page.. i basically need an input from a User and store the input to the object in the map.. any thoughts??

aballardaballard

You cannot use apex:variable as an "iteration variable" in repeat.   The value will not be updated for each iteration the way your code expects. 

 

You should be able to just iterate over the map directly... e.g.

 

<apex:repeat value="{!mymap} var="m"/> 

 

makes m reference sucessive elements of the map. 

This was selected as the best answer