function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sarvesh001sarvesh001 

Actionsupport event="onclick".....



Hi ,
I have tried this one in demo version.
I have posted my code when i clicked the checkbob  corresponding row  is in editable mode .
But the issue is it showing same records repetedly
Can you suggest me...


<apex:page StandardController="Contact" extensions="RowEditingcontroller">

  <apex:pageMessages />

    <apex:form id="theForm">
        <apex:pageBlock Title="ALL CONTACTS FOR ROW EIDTING" id="pb">
         
           <apex:commandButton value="Save" action="{!tosave}" id="saveButton"  />

           <apex:outputPanel >

        

              <apex:pageBlockTable value="{!Contacts}" var="c" cellpadding="2" border="1"  rowClasses="odd,even" styleClass="tableClass" id="opp_table">
                
                  <apex:column headerValue="Edit" >
                     <apex:inputcheckbox value="{!c.selected}">
                       <apex:actionSupport event="onclick" action="{!getSelected}"  rerender="pb" />
                     </apex:inputcheckbox>&nbsp;
                  </apex:column>
                   <apex:column headerValue="Contact name" >
                 
                    <b><apex:outputField rendered="{!IF(c.selected==true,false,true)}" value="{!c.con.Name}"/> </b>  
                       <apex:inputfield rendered="{!IF(c.selected==true,true,false)}" value="{!c.con.Name}"/>
                      </apex:column>
                 <apex:column headerValue="Contact No" >
                    <apex:outputfield rendered="{!IF(c.selected==true,false,true)}" value="{!c.con.MobilePhone}" />
                   <apex:inputfield rendered="{!IF(c.selected==true,true,false)}" value="{!c.con.MobilePhone}" />
                 </apex:column>
                 <apex:column headerValue="Email">
                   <apex:outputField rendered="{!IF(c.selected==true,false,true)}" value="{!c.con.Email}"/>
                    <apex:inputField rendered="{!IF(c.selected==true,true,false)}" value="{!c.con.Email}"/>
                 </apex:column>
               <apex:inlineEditSupport event="ondblClick"  showOnEdit="saveButton"/>
              

         </apex:pageBlockTable>

      </apex:outputPanel>

     </apex:pageBlock>
  </apex:form>

  </apex:page>


---------------------------------------------controller------------------------------------
public class RowEditingcontroller {

     //All property....

     public Contact contact{get;set;}
     public Id Id{get;set;}
     List<contactwrapper> contactList = new List<contactwrapper>();
     List<Contact> selectedContacts = new List<Contact>();

     //constructor....

     public RowEditingcontroller(ApexPages.StandardController controller) {
  
      

      }

     //displaying contact pageBlock table....
    
     public  List<contactwrapper> getContacts() {
  
        for(Contact c: [select Id,Name,Account.Name,MobilePhone,Email from Contact order by createdDate desc limit 1  ])
   
              contactList.add(new contactwrapper(c));
              return contactList;
          }

       //all selected contacts...for edit...     
     public PageReference getSelected() {
  
         selectedContacts.clear();
         for(contactwrapper conwrapper: contactList)
            if(conwrapper.selected == true)
     
            selectedContacts.add(conwrapper.con);
     
            return null;
        }
      
      
     public List<Contact> GetSelectedContacts(){
  
        if(selectedContacts.size()>0)
        return selectedContacts;
        else
       // ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Please select at least one Contact.'));
        return null;
    }
   
    //saving edited value...
 
      public PageReference tosave() {
      if(selectedContacts.size()>0){
    
        update selectedContacts;
        PageReference RowEditing=new PageReference('/apex/RowEditing');
        RowEditing.setRedirect(true);
        return RowEditing;
        }
        else{
        ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Please select at least one Contact.'));
         return null;
        }
     
       }
  
    //wrapper class...
  
    public class contactwrapper
    {
        public Contact con{get; set;}
        public Boolean selected {get; set;}
        public contactwrapper(Contact c)
        {
            con = c;
            selected = false;
        }
    }
}
Best Answer chosen by sarvesh001
Sushil KaushikSushil Kaushik
hello servesh,

you are doing the basic programing mistake please change the following function of controller as below :-

public  List<contactwrapper> getContacts() {
              if(contactList.size()!=0)
                  return contactList;
              for(Contact c: [select Id,Name,Account.Name,MobilePhone,Email from Contact order by createdDate desc limit 1  ])
  
              contactList.add(new contactwrapper(c));
              return contactList;
          }

       //all selected contacts...for edit...    
    /* public PageReference getSelected() {
 
         selectedContacts.clear();
         for(contactwrapper conwrapper: contactList)
            if(conwrapper.selected == true)
    
           selectedContacts.add(conwrapper.con);
    
            return null;
        }*/

further, there is no need of the action attribute for actionsupport tag please remove it..  then it should give desired result.. 


regards

Sushil

All Answers

Sushil KaushikSushil Kaushik
hello servesh,

you are doing the basic programing mistake please change the following function of controller as below :-

public  List<contactwrapper> getContacts() {
              if(contactList.size()!=0)
                  return contactList;
              for(Contact c: [select Id,Name,Account.Name,MobilePhone,Email from Contact order by createdDate desc limit 1  ])
  
              contactList.add(new contactwrapper(c));
              return contactList;
          }

       //all selected contacts...for edit...    
    /* public PageReference getSelected() {
 
         selectedContacts.clear();
         for(contactwrapper conwrapper: contactList)
            if(conwrapper.selected == true)
    
           selectedContacts.add(conwrapper.con);
    
            return null;
        }*/

further, there is no need of the action attribute for actionsupport tag please remove it..  then it should give desired result.. 


regards

Sushil
This was selected as the best answer
sarvesh001sarvesh001
Hi Sushil Kaushik,

Thanks for replay its working fine...

Regards,
sarvesh.