+ Start a Discussion
s.mafoders.mafoder 

Updating Map values from Visualforce

Hello , 

I'm struggling for a while with a visualforce page. This Page should have two filters . a filter that determine how many columns to display , and another to determine data to display. 

 

I used a wrapper class to do so and a map. My problem now is that i can't update the map values from visualforce page :

 

Here is my page :

 

<apex:page controller="wrapperClassController2" action="{!init}">

    <apex:form >

    <apex:commandButton value="Filter" action="{!filter}"/>
       
        <apex:pageBlock >
             <apex:pageBlockSection columns="2" >
        <apex:selectList multiselect="true" size="5" value="{!FilterProduit}" >
                <apex:selectOptions value="{!modeles}"/>
       </apex:selectList>
       <apex:selectList value="{!Filterdealer}" size="1" id="Filterdealer">
          <apex:selectOptions value="{!Dealers}"/>
       </apex:selectList>
        </apex:pageBlockSection>
         
          
          
        </apex:pageBlock>
   
   
    <table border="1">
    <tr>
     <th>Name</th>
     <th>Email</th>
    
     <apex:repeat value="{!lstmodeles }" var="item">
       
       <th><apex:outputText value="{!item.Name}"/></th>
    
        
      </apex:repeat>
      </tr>
      <apex:repeat value="{!lignes}" var="item">
     
      <tr>
      
      <td width="20%"><apex:outputText value="{!item.con.Name}"/></td>
      <td width="20%"><apex:outputText value="{!item.con.Email}"/></td>
        <apex:repeat value="{!lstmodeles }" var="c"> 
   
      <td width="20%"><apex:inputText value="{!item.volumeparmodele[c.Id]}"/></td>   
      </apex:repeat>
     
     </tr> 
    </apex:repeat>
      
    </table>
    <apex:commandButton value="Save" action="{!save}"/>
  </apex:form>
</apex:page>

 And the controller : 

public class wrapperClassController2 
{
publi<c class Ligne
{
    public Contact con {get; set;}
    public Map <String,Integer> volumeparmodele  {get; set;}
    public Ligne(Contact c, Map <String,Integer> volumeparmodele2 )
    {
            this.con = c;
            this.volumeparmodele =volumeparmodele2  ;
    }
}

    //Our collection of the class/wrapper objects cContact 
    public List<Ligne> lignes{get; set;}
    public String FilterProduit {get; set;}
    public String FilterDealer {get; set;}
   // public List<Product2> modeles{get; set;}
    public list<SelectOption> lst {get; set;}
    public List<Product2> lstmodeles {get; set;}
    public  Set<Id> idmodeles{get; set;}
    
    public Map<String,Integer> volumeparmodele{get; set;}
    
    public void init()
    {   
        volumeparmodele=new Map<String,Integer>();
        List<Product2>lstmodelesAll=new List<Product2>(); 
        lstmodelesAll =[select Id,Name from Product2];
        for(Product2 product:lstmodelesAll )
         {
            volumeparmodele.put(product.Id,0);
         }
    
    }
    
public Pagereference filter()
{
  
  lstmodeles =new List<Product2>();
  idmodeles=new Set<Id>();
  List<String>lststring=FilterProduit.split(','); 
   for(Integer i=0;i<lststring.size();i++)
   {
   
            if(lststring[i]!='')
            { 
                String s2 = lststring[i].removeStart('[');
                String s3 = s2.removeEnd(']');
                Id myId=s3.trim();
                idmodeles.add(myId);
            }
   
   }
  
    lstmodeles =[select Id,Name from Product2 where Id IN:idmodeles];
     
        if(lignes== null)
        {
            lignes= new List<Ligne>();
            for(Contact c : [select Id, Name, Email, Phone from Contact limit 10]){
          
                
                lignes.add(new Ligne(c,volumeparmodele));
            }
        }
    
    return null;
    
    }
    public List<SelectOption> getDealers() 
    {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('','- None -'));
        List<Contact> Lstcontacts =new List<Contact> ();
        Lstcontacts =[select Id,Name from contact];
        for(Contact contact : Lstcontacts )
        {
                   
                   
            options.add(new SelectOption(contact.Id, contact.Name));  
                    
        }
               
        return options;
    
    
    }
    public List<SelectOption> getModeles()
    {
      lst = new List<SelectOption>() ;
      List<Product2> modeles=new List<Product2>();
      modeles=[select Id,Name from Product2];
      for(Product2 product:modeles)
      {
         lst.add(new SelectOption(product.Id, product.Name)) ;
      }
      return lst; 
    
    
    
    }
    
    //This method uses a simple SOQL query to return a List of Contacts
    public Pagereference save()
    {
       System.debug('#######save');
       List<CustomerOrders__c> lstcustomerorders=new List<CustomerOrders__c >();
       
       lstmodeles =[select Id,Name from Product2 where Id IN:idmodeles];

       for(Integer i=0;i<lignes.size();i++)
       {
       CustomerOrders__c customorder=new CustomerOrders__c ();
       customorder.Contact__c=lignes[i].con.Id;
       //comment insérer le volume
       customorder.Volume__c=lignes[i].volumeparmodele.get('01td0000001BDD5');
       //comment insrer le produit a partir du MAP
       customorder.Product__c='01td0000001BDD5';
       lstcustomerorders.add(customorder);
       
       
       }
       System.debug('#######lstcustomerorders'+lstcustomerorders.size());
       insert lstcustomerorders;
       return null;
    
    
    
    }


    
 
   
 
}

 So on the Save method how can i update the Map values depending on what the user enter?

 

It is very urgent and i hope you can Help me. 

 

Ti test the code , you can simply Add an object related to a contact and a product  and add a custom field named "Volume__c".

 

Many Thanks

 

 

 

s.mafoders.mafoder

Please Help Me :( , how can i update the map values from the inputText in the visualforce?