+ Start a Discussion
Jyothsna ReddyJyothsna Reddy 

DynamicForm Building

Hi all,
I have MappingObject -----> Fields are::::::::::::::FieldName__c,FieldCaption__c && FieldType__c

Here I am trying to  get the  records based on FieldType__c(like ::::text,textarea). If FieldType is text it will show textbox.I did this finally using rendered.But my problem is  after submitting I am not getting the entered value.How can I solve this.
I am not even getting any error.
Please find the below code.I thought problem is storing the values.
<apex:pageBlock id="box">
  <apex:repeat value="{!inputFields}" var="m">
    <apex:outPutLabel value="{!if(m.FieldType__c == 'Text',m.FieldCaption__c,'')}"/>         
    <apex:inputText value="{!inputFields[m]}" rendered="{!if(m.FieldType__c == 'Text' ,true,false)}" />
    <!--<apex:outPutLabel value="{!if(m.FieldType__c == 'Textarea',m.FieldCaption__c,'')}"/>         
    <apex:inputtextarea value="{!inputFields[m]}" rendered="{!if(m.FieldType__c == 'Textarea',true,false)}" /> -->
  </apex:repeat>
  <apex:commandButton action="{!submitFieldData}"  value="Submit" id="button" rerender="box"/> {!strList}

Controller Code:
public class repeatandsave {

    public List<String> strList { get; set; }

    public Map<String,List<String>> outputFields { get; set; }
   
    public Map<Mapping__c,String> inputFields { get; set; }
    public List<Mapping__c> mapList{get;set;}
    public String str{get;set;}
    public repeatandsave(){
       strList=new List<String>();
       inputFields=new Map<Mapping__c,String>();
       mapList=new List<Mapping__c>();
       mapList=[SELECT FieldCaption__c,FieldName__c,FieldType__c,Name from Mapping__c where formname__c ='empform1']; 
       
       for(Mapping__c map1:mapList){
          System.debug(':::::::::::+before ++'+map1);
          inputFields.put(map1,'');
         
          System.debug(':::::::::::+after++'+map1);
          
       }
       System.debug('::::::::::::'+ inputFields.keyset());
        System.debug('::::::::::::::::values::::::::'+inputFields.values());
    
    }
    
     public PageReference submitFieldData() {
        System.debug('Inside submit:::::::::::'+maplist); 
        
         for(Mapping__c  map1 : mapList){
            System.debug('::::::::::::map1 values are::::::::::'+map1);
            inputFields.get(map1);
            System.debug('Map values are:'+inputFields.get(map1));
            //System.debug('::::::::::::::map1values are :::::::::::::::'+outputFields.get(map1.FieldName__c));
            //strList.add(outputFields.get(map1.FieldName__c));
         }/*
        for(String str:strList){
            System.debug('Added Elements are ::::::'+str);
        } 
         System.debug('In submitt::::::::::::');
        */
        return null;
    }
    
}



Screen Shot::::::::::::

User-added image
Best Answer chosen by Jyothsna Reddy
logontokartiklogontokartik
Please try the below and see if this works.

Controller - Change the Map to use Id as the Key instead of SObject
public class repeatandsave {

    public List<String> strList { get; set; }

    public Map<String,List<String>> outputFields { get; set; }
   
    public Map<Id,String> inputFields { get; set; }
    public List<Mapping__c> mapList{get;set;}
    public String str{get;set;}
    public repeatandsave(){
       strList=new List<String>();
       inputFields=new Map<Id,String>();
       mapList=new List<Mapping__c>();
       mapList=[SELECT Id, FieldCaption__c,FieldName__c,FieldType__c,Name from Mapping__c where formname__c ='empform1']; 
       
       for(Mapping__c map1:mapList){
          System.debug(':::::::::::+before ++'+map1);
          inputFields.put(map1.Id,'');
         
          System.debug(':::::::::::+after++'+map1);
          
       }
       System.debug('::::::::::::'+ inputFields.keyset());
        System.debug('::::::::::::::::values::::::::'+inputFields.values());
    
    }
    
     public PageReference submitFieldData() {
        System.debug('Inside submit:::::::::::'+maplist); 
        
         for(Id  map1 : mapList){
            System.debug('::::::::::::map1 values are::::::::::'+map1);
            inputFields.get(map1);
            System.debug('Map values are:'+inputFields.get(map1));
            //System.debug('::::::::::::::map1values are :::::::::::::::'+outputFields.get(map1.FieldName__c));
            //strList.add(outputFields.get(map1.FieldName__c));
         }/*
        for(String str:strList){
            System.debug('Added Elements are ::::::'+str);
        } 
         System.debug('In submitt::::::::::::');
        */
        return null;
    }
    
}

Page - 

<apex:pageBlock id="box">
  <apex:repeat value="{!mapList}" var="m">
    <apex:outPutLabel value="{!if(m.FieldType__c == 'Text',m.FieldCaption__c,'')}"/>         
    <apex:inputText value="{!inputFields[m.Id]}" rendered="{!if(m.FieldType__c == 'Text' ,true,false)}" />
    <!--<apex:outPutLabel value="{!if(m.FieldType__c == 'Textarea',m.FieldCaption__c,'')}"/>         
    <apex:inputtextarea value="{!inputFields[m.Id]}" rendered="{!if(m.FieldType__c == 'Textarea',true,false)}" /> -->
  </apex:repeat>
  <apex:commandButton action="{!submitFieldData}"  value="Submit" id="button" rerender="box"/> {!strList}

Let me know if this works. Thank you


All Answers

logontokartiklogontokartik
Please try the below and see if this works.

Controller - Change the Map to use Id as the Key instead of SObject
public class repeatandsave {

    public List<String> strList { get; set; }

    public Map<String,List<String>> outputFields { get; set; }
   
    public Map<Id,String> inputFields { get; set; }
    public List<Mapping__c> mapList{get;set;}
    public String str{get;set;}
    public repeatandsave(){
       strList=new List<String>();
       inputFields=new Map<Id,String>();
       mapList=new List<Mapping__c>();
       mapList=[SELECT Id, FieldCaption__c,FieldName__c,FieldType__c,Name from Mapping__c where formname__c ='empform1']; 
       
       for(Mapping__c map1:mapList){
          System.debug(':::::::::::+before ++'+map1);
          inputFields.put(map1.Id,'');
         
          System.debug(':::::::::::+after++'+map1);
          
       }
       System.debug('::::::::::::'+ inputFields.keyset());
        System.debug('::::::::::::::::values::::::::'+inputFields.values());
    
    }
    
     public PageReference submitFieldData() {
        System.debug('Inside submit:::::::::::'+maplist); 
        
         for(Id  map1 : mapList){
            System.debug('::::::::::::map1 values are::::::::::'+map1);
            inputFields.get(map1);
            System.debug('Map values are:'+inputFields.get(map1));
            //System.debug('::::::::::::::map1values are :::::::::::::::'+outputFields.get(map1.FieldName__c));
            //strList.add(outputFields.get(map1.FieldName__c));
         }/*
        for(String str:strList){
            System.debug('Added Elements are ::::::'+str);
        } 
         System.debug('In submitt::::::::::::');
        */
        return null;
    }
    
}

Page - 

<apex:pageBlock id="box">
  <apex:repeat value="{!mapList}" var="m">
    <apex:outPutLabel value="{!if(m.FieldType__c == 'Text',m.FieldCaption__c,'')}"/>         
    <apex:inputText value="{!inputFields[m.Id]}" rendered="{!if(m.FieldType__c == 'Text' ,true,false)}" />
    <!--<apex:outPutLabel value="{!if(m.FieldType__c == 'Textarea',m.FieldCaption__c,'')}"/>         
    <apex:inputtextarea value="{!inputFields[m.Id]}" rendered="{!if(m.FieldType__c == 'Textarea',true,false)}" /> -->
  </apex:repeat>
  <apex:commandButton action="{!submitFieldData}"  value="Submit" id="button" rerender="box"/> {!strList}

Let me know if this works. Thank you


This was selected as the best answer
Jyothsna ReddyJyothsna Reddy
Thanks a lot Logontokartik ..From 2 days onwards I am stucked here.It came by placing Id..
I did some more modifications here.
Anyways It helped me...