You need to sign in to do that
Don't have an account?
Map in Visualforce results Incorrect parameter type for subscript. Expected Number, received Text
This is a bit of breif bit of code:
controller:
<pre>
public List<String> partTypes = new List<String>{'Accessories', 'Electronics', 'Fishing', 'Fun and Entertainment', 'Graphics and Decals', 'Pontoon Covers', 'Safety', 'Seating', 'Trailering and Covers'};
public Map<String, List<Product2>> availablePartOptions{ get; set;}
.
.
.
List<Product2> boatOptions = [SELECT Id, Name, RecordType.Name, Family,
(SELECT Id, Name, UnitPrice, Pricebook2Id
FROM PricebookEntries WHERE Pricebook2Id = :pb2Id),
(SELECT Id, Standard__c, Maximum__c FROM From_Product_Options__r)
FROM Product2
WHERE Id IN :ids];
availablePartOptions = new Map<String,List<Product2>>();
for(String partName : partTypes) {
availablePartOptions.put( partName, new List<Product2>() );
}
for(Product2 opt: boatOptions() ) {
if(opt.RecordType.Name == 'Part'){
availablePartOptions.get(opt.Family).add(opt);
}
}
</pre>
Visualforce test:
<pre>
<ul>
<apex:repeat value="{!availablePartOptions}" var="key">
<li>
<apex:outputText value="{!key}" /> -
<apex:outputText value="{!availablePartOptions[key].size}" />
</li>
</apex:repeat>
</ul>
</pre>
This all results in:
Incorrect parameter type for subscript. Expected Number, received Text
Error is in expression '{!availablePartOptions[key].size}' in component <apex:outputText> in page boatbuilder
If I omit the offending line I get a ugly but valid list of keys which is the same as my partTypes List
Accessories -
Electronics -
Fishing -
Fun and Entertainment -
Graphics and Decals -
Pontoon Covers -
Safety -
Seating -
Trailering and Covers -
This is the method every doc I have read said to use when dealing with maps in visualforce.
If anyone has any Ideas it would be a tremendous help
controller:
<pre>
public List<String> partTypes = new List<String>{'Accessories', 'Electronics', 'Fishing', 'Fun and Entertainment', 'Graphics and Decals', 'Pontoon Covers', 'Safety', 'Seating', 'Trailering and Covers'};
public Map<String, List<Product2>> availablePartOptions{ get; set;}
.
.
.
List<Product2> boatOptions = [SELECT Id, Name, RecordType.Name, Family,
(SELECT Id, Name, UnitPrice, Pricebook2Id
FROM PricebookEntries WHERE Pricebook2Id = :pb2Id),
(SELECT Id, Standard__c, Maximum__c FROM From_Product_Options__r)
FROM Product2
WHERE Id IN :ids];
availablePartOptions = new Map<String,List<Product2>>();
for(String partName : partTypes) {
availablePartOptions.put( partName, new List<Product2>() );
}
for(Product2 opt: boatOptions() ) {
if(opt.RecordType.Name == 'Part'){
availablePartOptions.get(opt.Family).add(opt);
}
}
</pre>
Visualforce test:
<pre>
<ul>
<apex:repeat value="{!availablePartOptions}" var="key">
<li>
<apex:outputText value="{!key}" /> -
<apex:outputText value="{!availablePartOptions[key].size}" />
</li>
</apex:repeat>
</ul>
</pre>
This all results in:
Incorrect parameter type for subscript. Expected Number, received Text
Error is in expression '{!availablePartOptions[key].size}' in component <apex:outputText> in page boatbuilder
If I omit the offending line I get a ugly but valid list of keys which is the same as my partTypes List
Accessories -
Electronics -
Fishing -
Fun and Entertainment -
Graphics and Decals -
Pontoon Covers -
Safety -
Seating -
Trailering and Covers -
This is the method every doc I have read said to use when dealing with maps in visualforce.
If anyone has any Ideas it would be a tremendous help
<apex:variable value="{!availablePartOptions[key]}" var="myMap"/ >
<apex:outputText value="{!myMap.size}" />
Does this works for you ?