You need to sign in to do that
Don't have an account?
fadwa mangoug
Display Apex maps in Visualforce page
Hey,
Im trying to display maps in a visualforce page but the method that builds the map doesnt seem to be called when i preview my page. I would appreciate some help please :)
Here's my map :
public map<string,string> getMapFieldLabel(){
//List<string> fieldsLabels = new List<string>();
List<Custom_Object__c> defaultFields = [Select Name from Custom_Object__c where Default__c=True];
Map<String, Schema.SObjectField> typeMap = Schema.SObjectType.A_second_Custom_Object__c.fields.getMap();
//Get choosen default fields label
for(Custom_Object__c defaultField : defaultFields) {
Schema.SObjectField field = typeMap.get(defaultField.Name);
string fieldLabel =field.getDescribe().getLabel();
mapFieldLabel.put(defaultField.Name, fieldLabel);
//fieldsLabels.add(fieldLabel);
}
system.debug(mapFieldLabel);
return mapFieldLabel;
}
And my VF code :
<apex:pageBlockSection columns="3" collapsible="true">
<apex:repeat value="{!MapFieldLabel}" var="item" >
<apex:repeat value="{!MapFieldLabel[item]}" var="itemvalue" >
<apex:outputText value="{!itemvalue}" />
</apex:repeat>
</apex:repeat>
</apex:pageBlockSection>
This code doesnt display anything on screen !
Thank you for your help in advance :)
Im trying to display maps in a visualforce page but the method that builds the map doesnt seem to be called when i preview my page. I would appreciate some help please :)
Here's my map :
public map<string,string> getMapFieldLabel(){
//List<string> fieldsLabels = new List<string>();
List<Custom_Object__c> defaultFields = [Select Name from Custom_Object__c where Default__c=True];
Map<String, Schema.SObjectField> typeMap = Schema.SObjectType.A_second_Custom_Object__c.fields.getMap();
//Get choosen default fields label
for(Custom_Object__c defaultField : defaultFields) {
Schema.SObjectField field = typeMap.get(defaultField.Name);
string fieldLabel =field.getDescribe().getLabel();
mapFieldLabel.put(defaultField.Name, fieldLabel);
//fieldsLabels.add(fieldLabel);
}
system.debug(mapFieldLabel);
return mapFieldLabel;
}
And my VF code :
<apex:pageBlockSection columns="3" collapsible="true">
<apex:repeat value="{!MapFieldLabel}" var="item" >
<apex:repeat value="{!MapFieldLabel[item]}" var="itemvalue" >
<apex:outputText value="{!itemvalue}" />
</apex:repeat>
</apex:repeat>
</apex:pageBlockSection>
This code doesnt display anything on screen !
Thank you for your help in advance :)
New code is more destructive:
Please follow step and let me know:
1) Take this code: 2) In VF page: 3) Check in debug log if data is coming in mapField_Label variable.
Thanks
Gulshan Raj
All Answers
You are trying to iterating Schema.SObjectField in the inner repeat which is not list or iterable.
Here is code which will help you to understand where you are wrong:
I am expecting more question as it look like you wanted to achieve something inside inner repeat. Please let me know if I can help you.
Thanks
Gulshan Raj
Try that - I think you'll see the keys and values of the map
@Gulshan Raj11
I tried to convert the Schema.SObjectField Label to a string and to use a Map of lists to iterate over them inn my VF but still not working :
public Map<List<string>,List<string>> getMapFieldLabel(){
system.debug('In the getMapfieldLabel');
List<string> fieldsLabels = new List<string>();
List<string> fieldsNames = new List<string>();
List<Proximity_Search_Engine__c> defaultFields = [Select Name from Custom_Object__c where Default__c=True];
Map<String, Schema.SObjectField> typeMap = Schema.SObjectType.Second_Custom_Object__c.fields.getMap();
//Get choosen default fields label
for(Custom_Object__c defaultField : defaultFields) {
fieldsNames.add(string.ValueOf(defaultField));
Schema.SObjectField field = typeMap.get(defaultField.Name);
string fieldLabel = string.valueOF(field.getDescribe().getLabel());
fieldsLabels.add(fieldLabel);
}
mapFieldLabel.put(fieldsNames, fieldsLabels);
system.debug(mapFieldLabel);
return mapFieldLabel;
}
When executing the class, the method is not even called...
@JeffreyStevens,
Thanks for the quick answer !
I tried the code u suggested but still not displaying anything.
New code is more destructive:
Please follow step and let me know:
1) Take this code: 2) In VF page: 3) Check in debug log if data is coming in mapField_Label variable.
Thanks
Gulshan Raj
Thank so much you for ur answers. So the apex code worked and the map is now populated and the method called, but, the VF is still not displaying the map data.
I appreciate the help thank you !
Fadwa
Thanks
Gulshan Raj
It finally worked, i've put the maps in my constructor and it displayed the values well in my VF.
Thank you for the help :)
Fadwa
Can you please mark this question as solved and choose best answer so it will help other in future to choose best solution.
Thanks
Gulshan Raj
how to display element count in vf page if I am trying to display it while click on show product method value of quantity increasing can you help me .
visualforce page i am displaying like that but problem is if i click on pagination first page,last page method is calling so value is increasing so what i need to do.
vf page
======
<input type="hidden" id='{!a.pricebookentry.Product2.name}q' value="{!elementCount[a.pricebookentry.EN_Code__c]}"/>
Apex class
============
I have added this code in method showproductdata()
elementCount=new map<string,Integer>();
List<String> filterLogicSplittedbySpace = (List<String>)System.JSON.deserialize(barcodeIn, List<String>.class);
system.debug('filterLogicSplittedbySpace'+ filterLogicSplittedbySpace.size());
for (String str : filterLogicSplittedbySpace){
system.debug('str'+str);
str =str.trim();
elementList.add(str);
}
system.debug('elementList size'+elementList.size());
for(String key : elementList)
{
system.debug('elementCount.containsKey(key)'+ elementCount.containsKey(key));
if(!elementCount.containsKey(key)){
elementCount.put(key,0);
}
currentInt=elementCount.get(key)+1;
System.debug('currentInt@@'+currentInt);
elementCount.put(key,currentInt);
}