0

for a raison that i ignore, any changes in the visualofrce page on the wrapper input fields are not picked up bu the wrapper class in apex as if there is no binding between the two, all the fields are inputField fields , so i created a cammandbutton with a method Enregistrer to save the changes that the user inserted on the visualforce page, but when i refresh the page all the values are lost :

Apex:

public class Comp_PilotageComptePM {
    public String CompteID {set;get;}
    public String RisqueAEnregistrer {set;get;}
    public Comp_PilotageComptePM(){

    }
    public List<WrapperClass> ListWrapper{
        set;
        get{
            List<WrapperClass> ListWrapper = new List<WrapperClass>();
            List<Risque__c> ListeRisques = [select Id,name,Critere__c,Date_Risque__c,Derniere_Alerte__c,Etat__c,Etat_Actions__c,idcritere__c,Idmapping__c,Libelle__c,
                                            Mapping__c,namepage__c, Priorite__c,Suivi_clientid__c,Suivi_client__c,Type__c,type_object__c from Risque__c where Suivi_client__c =:CompteID];
            system.debug('La taille des risques = '+ListeRisques.size());
            List<Action2__c> listeActions = [select Id,Acteur__c,name,Risque__c,Date_debut__c,Date_fin_prevue__c,Date_realisation__c,   Duree__c,Objectif__c,Pre_requis__c
                                             ,Priorite_risque__c,Resultat__c,Suivi_client__c,Type__c,Type_action__c,Type_risque__c from Action2__c where Risque__c IN (select Id from Risque__c where Suivi_client__c =:CompteID)];
            system.debug('je suis la');
            if(ListeRisques.size()>0){
                for(Risque__c rs: ListeRisques){
                    List<Action2__c> al = new List<Action2__c>();
                    for(Action2__c ac: listeActions){
                        if(ac.risque__c == rs.id){
                            Al.add(ac);
                        }
                    }
                    ListWrapper.add(new WrapperClass(rs,al)); 
                }
            }
            return ListWrapper;
        }
    }

    public class WrapperClass{
        public List<Risque__c> risque {get;set;}
        public List<Action2__c> listActions {get;set;}

        public WrapperClass(Risque__c rs, List<Action2__c> lA){
            risque = new List<Risque__c>();
            risque.add(rs);
            listActions = lA;
        }
    }
    public pagereference Cloturer(){

        return null;
    }

    public pagereference Enregistrer(){
        for(WrapperClass wr: ListWrapper){
            for(Risque__c rs: wr.risque){
                if(rs.id == RisqueAEnregistrer){
                    update wr.listActions;
                }
            }
        }

        return null;
    }
}  

and here is the visualforce page (it's a page component)

   <apex:repeat value="{!ListWrapper}" var="item">
           <div class="row">
               <div class="panel panel-default" id="aa{!item.risque[0].id}">
                   <div class="panel-heading " style="background: #ff0000; color: #fff;">
                       <h4 class="panel-title">{!item.risque[0].name}</h4>
                       </div>

                       <div class="panel-body">
                            <apex:pageBlock title="Le risque">  
                            <apex:pageBlockTable value="{!item.risque}" var="itemRisque" title="Le risque">
                              <apex:column >
                               <apex:facet name="header">Nom de risaque</apex:facet>
                                <apex:outputtext Value="{!itemRisque.name}" />
                                    </apex:column>
                            <apex:column >
                               <apex:facet name="header">Date de risque</apex:facet>

                                      <apex:outputText value="{0,date,dd'/'MM'/'yyyy}">
                             <apex:param Value="{!itemRisque.Date_Risque__c}" /> 
                            </apex:outputText>

                                    </apex:column>
                                <apex:column >
                                <apex:facet name="header">Dérnière alerte</apex:facet>
                                <apex:outputtext Value="{!itemRisque.Derniere_Alerte__c}" />
                                    </apex:column>
                                <apex:column >
                                <apex:facet name="header">Etat</apex:facet>
                                <apex:outputtext Value="{!itemRisque.Etat__c}" />
                                    </apex:column>
                                 <apex:column >
                                <apex:facet name="header">Type</apex:facet>
                                <apex:outputtext Value="{!itemRisque.Type__c}" />
                                    </apex:column>

                                <apex:column >
                                <apex:facet name="header">Cloturer</apex:facet>
                                <apex:Commandbutton Value="Cloturer" action="{!cloturer}" />
                                    </apex:column>




                              </apex:PageBlockTable>
                                </apex:pageBlock>
                                <apex:pageBlock title="Les actions">
                              <apex:pageBlockTable value="{!item.listActions}" var="itemAction" title="Les actions">
                              <apex:column >
                               <apex:facet name="header">Nom</apex:facet>
                                <apex:outputtext Value="{!itemAction.name}" />
                                    </apex:column>

                                  <apex:column >
                               <apex:facet name="header">Acteur</apex:facet>
                                <apex:OutputField Value="{!itemAction.Acteur__c}" />
                                    </apex:column>

                            <apex:column >
                               <apex:facet name="header">Date début</apex:facet>
                                <apex:inputField Value="{!itemAction.Date_debut__c}" />
                                    </apex:column>
                                <apex:column >
                               <apex:facet name="header">Date fin prévu</apex:facet>
                                <apex:inputField Value="{!itemAction.Date_fin_prevue__c}" />
                                    </apex:column>
                                <apex:column >
                               <apex:facet name="header">Objectif</apex:facet>
                                <apex:inputField Value="{!itemAction.Objectif__c}" />
                                    </apex:column>
                                 <apex:column >
                               <apex:facet name="header">Resultat</apex:facet>
                                <apex:inputField Value="{!itemAction.Resultat__c}" />
                                    </apex:column>

                                 <apex:column >
                               <apex:facet name="header">Date de réalisation</apex:facet>
                                <apex:inputField Value="{!itemAction.Date_realisation__c}" />
                                    </apex:column>




                              </apex:PageBlockTable>
                                </apex:pageBlock>           
                        </div>

                  <div class="panel-footer"><apex:commandbutton value="Enregistrer" action="{!Enregistrer}" rerender="test">
                   <apex:param name="Risque" value="{!item.Risque[0].id}" assignTo="{!RisqueAEnregistrer}"/>
                    </apex:commandbutton>
                    </div>

                                </div>

               </div>
           </apex:repeat>
0

You have several things going on here. You don't reinitialize your wrapper class after your update after your command button sends !item.Risque[0].Id back to the controller. This likely wouldn't be an issue if the button fired on !ListWrapper which is what it would seem it should be sending to your controller, especially when you look at how your code works.

It would seem that you'd need to show us the rest of your component to say much further because you have a rerender="test" whose Id doesn't appear in the code you've posted. The rerender could cause the wrapper class to be initialized once again following the update. That said, I think the root cause of all your issues is that your button doesn't send the value !ListWrapper back to the controller.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.