Activity Forums Salesforce® Discussions Re-render issue with pageblock section for Contact

  • Re-render issue with pageblock section for Contact

    Posted by Raghav Chaturvedi on May 29, 2018 at 11:50 am

    Here is My code and a screen shot which i want

    <apex:page controller="SearchRecords" showHeader="true" >
    <apex:form id="frm">
    <!----<apex:actionFunction name="showcon" action="{!showContact}" reRender="frm" /> --->
    <apex:pageblock >
    <apex:pageBlockSection title="Search Account Records" columns="1">
    Enter Name<apex:inputText value="{!getstring}" id="theTextInput"/>
    <apex:commandButton action="{!searchRecords}" value="Search" id="theSearch" reRender="frm"/>
    </apex:pageBlockSection>

    <apex:pageBlockSection title="Account Detail" id="pb">
    <apex:pageBlocktable value="{!accountlist}" var="acc">
    <apex:column >
    <input type="radio" name="group1" reRender=""/>
    <apex:actionSupport event="onclick" action="{!showContact}" reRender="frm" >
    <apex:param assignTo="{!AccId}" name="accname" value="{!acc.id}"/>
    </apex:actionSupport>
    </apex:column>
    <apex:column value="{!acc.Name}"/>
    <apex:column value="{!acc.Phone}" />
    </apex:pageBlocktable>
    </apex:pageBlockSection>

    <apex:pageBlockSection title="Related Contact" id="conpgblk" rendered="{!display}" >
    <apex:outputPanel rendered="{!listWrapper.size == 0}">
    <b> NO RELATED CONTACTS FOR THIS ACCOUNT.</b>
    </apex:outputPanel>

    <apex:outputPanel rendered="{!listWrapper.size != 0}">
    <div align="center" draggable="false" >
    <apex:commandButton value="Send Email" action="{!SendEmail}" />
    <apex:commandButton value="Print Detail" action="{!PrintDetail}"/>
    </div>
    <apex:pageBlockTable value="{!listWrapper}" id="pbt1" var="wrap">
    <apex:column headerValue="Select">
    <apex:inputCheckbox value="{!wrap.checked}" id="inputBox"/>
    </apex:column>
    <apex:column value="{!wrap.con.Name}"/>
    <apex:column value="{!wrap.con.Phone}"/>
    <apex:column value="{!wrap.con.Email}"/>
    <apex:column value="{!wrap.con.Account.Name}"/>
    <apex:column value="{!wrap.con.AccountId}"/>
    <apex:column value="{!wrap.con.Id}"/>
    </apex:pageBlockTable>
    </apex:outputPanel>
    </apex:pageBlockSection>
    </apex:pageblock>
    </apex:form>
    </apex:page>
    public class SearchRecords {
    public boolean display{get;set;}
    private integer totalRecs = 0;
    private integer OffsetSize = 0;
    private integer LimitSize=0;
    public String AccId{get;set;}
    public string getstring{get;set;}
    public List<Account> accountlist {get;set;}
    public list<Contact> conList{get;set;}
    public void searchRecords(){

    display=false;
    accountlist= new list<Account>();
    if(getstring!=null){
    accountlist= Database.query('select id,AccountNumber,name,Phone from Account where name like \'%'+getstring+'%\'');
    }
    }

    public List<WrapperClass> listWrapper {get;set;}

    public void showContact(){

    display=true;
    listWrapper = new List<WrapperClass>();
    List<Contact> conlist = [SELECT id,Title,Fax,Birthdate,Name,Account.Name,Phone,Email FROM Contact WHERE AccountId=:AccId];
    if(Accid!=NULL)
    for(contact con:conlist)
    {
    listWrapper.add(new WrapperClass(con));
    }

    }
    public class WrapperClass {
    public boolean fgjj;
    public Boolean checked {get;set;}
    public contact con {get;set;}
    public WrapperClass(contact con) {
    this.con=con;
    checked=false;
    }
    }
    public pageReference SendEmail(){
    return null;
    }
    public pageReference PrintDetail(){
    return new pageReference('apex/PrintContactDetail');
    }

    }CaptureRaghav

    Nagesh replied 4 years, 2 months ago 3 Members · 2 Replies
  • 2 Replies
  • Aman

    Member
    May 30, 2018 at 9:20 am

    Hi Raghav,

    You are re-rendering the complete form in the action:support instead of doing this re-render only the pageblock section for contact. Add an output panel for pageblock section for contact details and rerender its id in the action support then it will work fine.

    <input type="radio" name="group1" id="radio"> </input>
    <apex:actionSupport event="onclick" action="{!showContact}" reRender="rad">
    <apex:param assignTo="{!AccId}" name="accname" value="{!acc.account.id}"/>
    </apex:actionSupport>

    <apex:outputPanel id="rad">
    <apex:pageBlockSection title="Related Contact" id="conpgblk" rendered="{!display}" >
    <apex:outputPanel rendered="{!listWrapper.size == 0}">
    <b> NO RELATED CONTACTS FOR THIS ACCOUNT.</b>
    </apex:outputPanel>

    <apex:outputPanel rendered="{!listWrapper.size != 0}">
    <div align="center" draggable="false" >
    <apex:commandButton value="Send Email" action="{!SendEmail}" />
    <apex:commandButton value="Print Detail" action="{!PrintDetail}"/>
    </div>
    <apex:pageBlockTable value="{!listWrapper}" id="pbt1" var="wrap">
    <apex:column headerValue="Select">
    <apex:inputCheckbox value="{!wrap.checked}" id="inputBox"/>
    </apex:column>
    <apex:column value="{!wrap.con.Name}"/>
    <apex:column value="{!wrap.con.Phone}"/>
    <apex:column value="{!wrap.con.Email}"/>
    <apex:column value="{!wrap.con.Account.Name}"/>
    <apex:column value="{!wrap.con.AccountId}"/>
    <apex:column value="{!wrap.con.Id}"/>
    </apex:pageBlockTable>
    </apex:outputPanel>
    </apex:pageBlockSection>
    </apex:outputPanel>

    Below is the screen shot of the preview :Screenshot from 2018-05-30 14-51-31

     

  • Nagesh

    Member
    October 18, 2020 at 6:21 pm

    Thanks Aman..This really helped a lot...was struggling with weired behaviour of re-rendering in such case

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos