+ Start a Discussion
newbiewvfdevnewbiewvfdev 

Rerender problem

Hi there,

 

I am having rerender issues. I have a commandLink button and when I click it I am putting a campaign record in the controller.  I have a outputPanel in the bottom of the commandLink button which holds a tabPanel. In the tabPanel, I am showing Contacts and Leads in the Campaign.  I have the rerender property of the commandLink set to outputPanel Id, because I only want to render this when they click the select button.  Also, I have an inline IF statement that checks if the campaign is null and if it's then don't render the Panel. When I click the select button it doesn't do anything. Can someone help me figure this out please. Thank you.

 

visualforce Page: <apex:page Controller="pagingController"> <style> .activeTab {background-color: #236FBD; color:white; background-image:none} .inactiveTab { background-color: lightgrey; color:black; background-image:none} </style> <apex:form > <apex:commandLink value="Select" action="{!pullCampaign}" styleClass="btn" rerender="campaignContactsAndLeads"> <apex:param name="campaignId" value="{!campaign.Id}" /> </apex:commandLink> <apex:outputPanel id="campaignContactsAndLeads" rendered="{!IF(ISNULL(campaign), false, true)}"> <apex:tabPanel switchType="client" selectedTab="tabCampaigns" id="MailingListTabPanel" tabClass="activeTab" inactiveTabClass="inactiveTab"> <apex:tab label="Contacts" name="contactSec" id="tabContacts"> <apex:pageBlock title="Category Results - Page #{!pageNumber}" > <apex:pageBlockTable id="cMContacts" value="{!Contacts}" var="cont"> <apex:column headerValue="First Name"> <apex:outputField value="{!cont.FirstName}"/>&nbsp; </apex:column> <apex:column headerValue="Last Name"> <apex:outputField value="{!cont.LastName}" />&nbsp; </apex:column> <apex:column headerValue="Mailing City"> <apex:outputField value="{!cont.MailingCity}"/>&nbsp; </apex:column> <apex:column headerValue="Mailing Country"> <apex:outputField value="{!cont.MailingCountry}" />&nbsp; </apex:column> </apex:pageBlockTable> </apex:pageBlock> <apex:panelGrid columns="4" id="contactLinks"> <apex:commandLink action="{!first}" rerender="cMContacts, contactLinks">First</apex:commandlink> <apex:commandLink action="{!previous}" rerender="cMContacts, contactLinks" rendered="{!hasPrevious}">Previous</apex:commandlink> <apex:commandLink action="{!next}" rendered="{!hasNext}" rerender="cMContacts, contactLinks">Next</apex:commandlink> <apex:commandLink action="{!last}" rerender="cMContacts, contactLinks">Last</apex:commandlink> </apex:panelGrid> </apex:tab> <apex:tab label="Leads" name="leadSec" id="tabLeads"> <apex:pageBlock title="Category Results - Page #{!pageNumberLead}" > <apex:pageBlockTable id="cMLeads" value="{!Leads}" var="leadM"> <apex:column headerValue="First Name"> <apex:outputField value="{!leadM.FirstName}"/>&nbsp; </apex:column> <apex:column headerValue="Last Name"> <apex:outputField value="{!leadM.LastName}" />&nbsp; </apex:column> <apex:column headerValue="Mailing City"> <apex:outputField value="{!leadM.City}"/>&nbsp; </apex:column> <apex:column headerValue="Mailing Country"> <apex:outputField value="{!leadM.Country}" />&nbsp; </apex:column> </apex:pageBlockTable> </apex:pageBlock> <apex:panelGrid columns="4" id="leadLinks"> <apex:commandLink action="{!firstLead}" rerender="cMLeads, leadLinks">First</apex:commandlink> <apex:commandLink action="{!previousLead}" rerender="cMLeads, leadLinks" rendered="{!hasPreviousLead}">Previous</apex:commandlink> <apex:commandLink action="{!nextLead}" rerender="cMLeads, leadLinks" rendered="{!hasNextLead}">Next</apex:commandlink> <apex:commandLink action="{!lastLead}" rerender="cMLeads, leadLinks">Last</apex:commandlink> </apex:panelGrid> </apex:tab> </apex:tabPanel> </apex:outputPanel> </apex:form> </apex:page> Controller code: public with sharing class pagingController { Campaign campaign; public void pullCampaign() { campaign = [SELECT Id, Name FROM Campaign WHERE Id = :'701A00000000kGz']; } public Campaign getCampaign() { return campaign; } // instantiate the StandardSetController from a query locator public ApexPages.StandardSetController con { get { if(con == null) { con = new ApexPages.StandardSetController( Database.getQueryLocator([ SELECT Id, FirstName, LastName, MailingCity, MailingCountry FROM Contact Where Id in ( Select ContactId From CampaignMember where campaignId =:campaign.Id And ContactId <> null)])); // sets the number of records in each page set con.setPageSize(5); } return con; } set; } // indicates whether there are more records after the current page set. public Boolean hasNext { get { return con.getHasNext(); } set; } // indicates whether there are more records before the current page set. public Boolean hasPrevious { get { return con.getHasPrevious(); } set; } // returns the page number of the current page set public Integer pageNumber { get { return con.getPageNumber(); } set; } // returns the first page of records public void first() { con.first(); } // returns the last page of records public void last() { con.last(); } // returns the previous page of records public void previous() { con.previous(); } // returns the next page of records public void next() { con.next(); } // returns the PageReference of the original page, if known, or the home page. public void cancel() { con.cancel(); } public List<Contact> getContacts() { return (List<Contact>) con.getRecords(); } // instantiate the StandardSetController from a query locator public ApexPages.StandardSetController lead { get { if(lead == null) { lead = new ApexPages.StandardSetController( Database.getQueryLocator([ SELECT Id, FirstName, LastName, City, Country FROM Lead Where Id in ( Select LeadId From CampaignMember where CampaignId =:campaign.Id And LeadId <> null)])); // sets the number of records in each page set lead.setPageSize(5); } return lead; } set; } // indicates whether there are more records after the current page set. public Boolean hasNextLead { get { return lead.getHasNext(); } set; } // indicates whether there are more records before the current page set. public Boolean hasPreviousLead { get { return lead.getHasPrevious(); } set; } // returns the page number of the current page set public Integer pageNumberLead { get { return lead.getPageNumber(); } set; } // returns the first page of records public void firstLead() { lead.first(); } // returns the last page of records public void lastLead() { lead.last(); } // returns the previous page of records public void previousLead() { lead.previous(); } // returns the next page of records public void nextLead() { lead.next(); } // returns the PageReference of the original page, if known, or the home page. public void cancelLead() { lead.cancel(); } public List<Lead> getLeads() { return (List<Lead>) lead.getRecords(); } }

 

Best Answer chosen by Admin (Salesforce Developers) 
newbiewvfdevnewbiewvfdev

I figured it out. :) There is couple of issues here.

 

1. It seems you can't have rendered property set when you are rerendering the control. So I moved the rendered attribute to the tabPanel tag.

 

2. When I click the 'select' button, it doesn't reset the QuerlyLocator. So I have to null out 'con' and 'lead' on pull campaign method which is called when I click the select button.

All Answers

bob_buzzardbob_buzzard

This rings a bell for me.

 

I had something similar where I wanted to rerender an outputpanel that wasn't actually rendered when the page was originally displayed.  As I recall, I couldn't do this - it seemed like the outputpanel had to be present on the page in order to be used as a rerender target.

 

I ended up nesting the conditionally rendered outputpanel inside another outputpanel that was always rendered. 

newbiewvfdevnewbiewvfdev

I figured it out. :) There is couple of issues here.

 

1. It seems you can't have rendered property set when you are rerendering the control. So I moved the rendered attribute to the tabPanel tag.

 

2. When I click the 'select' button, it doesn't reset the QuerlyLocator. So I have to null out 'con' and 'lead' on pull campaign method which is called when I click the select button.

This was selected as the best answer
jdk4702jdk4702

Hi Newbie - can I trouble you to post your updated code?  I'm having a similar issue and can't determine how to reset the query locator or controller.

jdk4702jdk4702

In case others have my problem, I resolved it by ensuring the setController re-intializes even if not null:

http://community.salesforce.com/t5/Visualforce-Development/How-to-Rerender-StandardSetController-in-PageBlockTable/m-p/193785/highlight/false#M25973