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
dmchengdmcheng 

Update viewstate with actionFunction rerender?

Hello.  I need to refresh viewstate on a page to show the latest query results but it's not working. 

I have an inputText on the page for the user to enter a filter value.  When that happens, I re-query records and I rerender the pageBlockTable that displays the records.

I'm using onChange on the inputText and an actionFunction with Javascript.

When I enter a value in the input field, the page is rerendered.  However, the viewstate is not changing so the pageBlockTable still shows the original set of records.

Here are the code snippets.

VF page:
<apex:page>
	<script>
		CCx.thispage = {};
		CCx.thispage.filterByName = function(evt) {
			var name = evt.value;

			// log a google analytics event

			// submit via actionfunction
			doFilterByName(name);
		};
	</script>

	<apex:form id="form">
		<div class="ccx-list-header">
			<div class="ccx-advocate-buttons" id="bulkListActions">
				<apex:inputText value="{!searchName}" onChange="CCx.thispage.filterByName(this); return false;" 
						html-placeholder="Search for advocate" />
			</div>
		</div>
		<apex:actionFunction name="doFilterByName" action="{!filterByName}" 
				rerender="bulkListActions, advocateListTable" />


			<apex:pageBlock id="pageblock">
				<apex:pageBlockSection columns="1" collapsible="false" id="section">
					<apex:pageBlockTable id="advocateListTable" value="{!advocates}" var="advocateListItem">
					</apex:pageBlockTable>
				</apex:pageBlockSection>
			</apex:pageBlock>

Controller:
public class MyController {
	public String currentDeskId;
	public String searchName { get; set; }
	public List<CCx_AdvocateServices.onboardingAdvocateDecorator> advocates { get; set; }

	public void filterByName() {
		system.debug('*** searchName: ' + searchName);
		if (string.isBlank(searchName)) return;
		advocates = CCx_AdvocateSelector.selectAdvocateDecoratorForDeskAndName(currentDeskId, searchName);
		system.debug('*** advocates: ' + advocates);
		searchName = null;
	}
	
	// Constructor
	// etc
}


Edwin VijayEdwin Vijay
Try these two
  1. Rerender the pageblock instead of the pageblocktable.
  2. Do your debug statements produce the correct results when you type in the inputtext box?
Visit Forcetree.com for code samples and tips.
dmchengdmcheng
Thanks for your reply.  Changing the rerender does not make a difference.  The debug shows the correct results.  However, the viewstate still shows the original records.
ShikibuShikibu
I believe I am having this problem too.

I am using a PageBlockTable to show a set of OpportunityLineItems. Some of the columns depend on some info about the products. My controller has a map of that product info, which is referenced in the VF page, using pricebookentryid as key.

When the user uses an autocomplete to set a new pricebookentryid, I need to add the corresponding product info to the cache.

I use an actionfunction to get the controller to add the product info to the cache. Using the developer console, I can see that a new entry is made in the caching map.

However, the viewstate retains the old value of the caching map, so the columns that reference product info get a cache miss, and the page throws an error.
ShikibuShikibu
BTW, this *does* work correctly if I invoke the controller method from apex:actionsupport action="{!myControllerMethod}". But the input whose change needs to trigger this method is in a custom component (apex:component) which implements autocomplete using the js library select2. I have not discovered any way to pass a controller method as an attribute to the component.