0

ActionFuntion not working what i miss can you please tell

class code:

public class EditContact_controller{
    public List<wrapperClass> wrapClassList{get;set;}
    public List<contact> conList{get;set;}
    public wrapperClass wc{get;set;}

    public EditContact_controller(){
        wrapClassList = new List<wrapperClass>();
        conList = new List<Contact>();
        conList = [SELECT Id, FirstName, LastName, email, Phone FROM Contact LIMIT 10];
        For(Contact co : conList){
            wc = new wrapperClass();
            wc.flag = false;
            wc.conWrap = co;
            wrapClassList.add(wc);
        }

    }

    public pagereference updateRecord() {
          Upsert conList;
          return new pageReference('/apex/EditContact').setRedirect(true);   
    }
    public class wrapperClass{
        public boolean flag{get;set;}
        public Contact conWrap{get;set;}

    }
}

VF Page:

<apex:page controller="EditContact_controller" tabStyle="Contact">
    <apex:form id="frm">
        <apex:sectionHeader title="Contact Records"/>
        <apex:actionFunction name="check" reRender="cont_Table"/>
        <apex:pageBlock >
            <apex:pageBlockButtons >
               <apex:commandButton value="Update Record" action="{!updateRecord}" reRender="frm"/>
            </apex:pageBlockButtons>

            <table width = "100%" id="tab">
             <tr>
                 <th> Action </th>
                 <th> First Name </th>
                 <th> Last Name </th>
                 <th> Email </th>
                 <th> Phone </th>
             </tr>

             <apex:repeat value="{!wrapClassList}" var="contactTable" id="cont_Table">
                    <tr>

                        <td> <apex:inputCheckbox value="{!contactTable.flag}" onClick="check();"/> </td>

                        <td> <apex:outputField value="{!contactTable.conWrap.FirstName}" rendered="{!(!contactTable.flag)}" /> 
                             <apex:inputField value="{!contactTable.conWrap.FirstName}" rendered="{!contactTable.flag}" />   
                        </td>

                        <td> <apex:outputField value="{!contactTable.conWrap.LastName}" rendered="{!(!contactTable.flag)}"/> 
                             <apex:inputField value="{!contactTable.conWrap.LastName}" rendered="{!contactTable.flag}"/>                       
                        </td>

                        <td> <apex:outputField value="{!contactTable.conWrap.email}" rendered="{!(!contactTable.flag)}"/>
                             <apex:inputField value="{!contactTable.conWrap.email}" rendered="{!contactTable.flag}"/>                       
                         </td>

                        <td> <apex:outputField value="{!contactTable.conWrap.phone}" rendered="{!(!contactTable.flag)}"/>
                             <apex:inputField value="{!contactTable.conWrap.phone}" rendered="{!contactTable.flag}"/>
                        </td>
                    </tr>
              </apex:repeat>
            </table>
        </apex:pageBlock>
    </apex:form>
</apex:page>
  • Try removing 'return false' from onclick – Raul Feb 15 '17 at 14:22
  • i have removed now checkbox is checked but row will now appear in editmode i mean inputField not working – cloudZigZag Feb 15 '17 at 14:28
  • You have to write some logic to switch the checkboxes – Raul Feb 15 '17 at 14:48
1

You are reRendering to repeat you should use output panel and from actionfunction you should reRender outputpanel. use this it'll work for you.

<apex:page controller="EditContact_controller" tabStyle="Contact">
<apex:form id="frm">
    <apex:sectionHeader title="Contact Records"/>
    <apex:actionFunction name="check"  reRender="cont_Table"/>
    <apex:pageBlock >

        <apex:pageBlockButtons >
           <apex:commandButton value="Update Record" action="{!updateRecord}" reRender="frm"/>
        </apex:pageBlockButtons>
        <apex:outputPanel id="cont_Table">
        <table width = "100%" id="tab">
             <tr>
                 <th> Action </th>
                 <th> First Name </th>
                 <th> Last Name </th>
                 <th> Email </th>
                 <th> Phone </th>
             </tr>

                    <apex:repeat value="{!wrapClassList}" var="contactTable" >
                        <tr>

                        <td> <apex:inputCheckbox value="{!contactTable.flag}" onClick="check();"/> </td>

                        <td> <apex:outputField value="{!contactTable.conWrap.FirstName}" rendered="{!(!contactTable.flag)}" /> 
                             <apex:inputField value="{!contactTable.conWrap.FirstName}" rendered="{!contactTable.flag}" />   
                            </td>

                            <td> <apex:outputField value="{!contactTable.conWrap.LastName}" rendered="{!(!contactTable.flag)}"/> 
                                 <apex:inputField value="{!contactTable.conWrap.LastName}" rendered="{!contactTable.flag}"/>                       
                            </td>

                            <td> <apex:outputField value="{!contactTable.conWrap.email}" rendered="{!(!contactTable.flag)}"/>
                                 <apex:inputField value="{!contactTable.conWrap.email}" rendered="{!contactTable.flag}"/>                       
                             </td>

                            <td> <apex:outputField value="{!contactTable.conWrap.phone}" rendered="{!(!contactTable.flag)}"/>
                                 <apex:inputField value="{!contactTable.conWrap.phone}" rendered="{!contactTable.flag}"/>
                            </td>
                        </tr>
            </apex:repeat>

        </table>  
        </apex:outputPanel>
    </apex:pageBlock>

</apex:form>

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.