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

Refreshing a TreeView

I'm trying to create a treeview of products for a specified Pricebook.  When my page load, the treeview presents itself perfectly.  However, when I select to a different pricebook, I want to refresh the treeview but it doesn't build out with the collapsible view.  My data changes fine but it seems to me the javascript doesn't or can't re-run to build the treeview of the new data.  


I fully admit, I'm not totally sure I get the whole getter setter process either but it does seem from my debug logs that my Products list does reresh with the correct data.  It just doesn't present itself correctly (as a treeview) on the page.  What am I doing wrong?  


Visualforce Page:

<apex:page controller="ProductTreeViewController" sidebar="true" showHeader="true">
	<link rel="stylesheet" href="{!URLFOR($Resource.jsTreeView,'jquery.treeview.css')}"/>
	<script src="{!URLFOR($Resource.jsTreeView,'lib/jquery.js')}" type="text/javascript"></script>
	<script src="{!URLFOR($Resource.jsTreeView,'lib/jquery.cookie.js')}" type="text/javascript"></script>
	<script src="{!URLFOR($Resource.jsTreeView,'jquery.treeview.js')}" type="text/javascript"></script>

	<script type="text/javascript">
				collapsed: false,
				animated: "medium",
				persist: "location"

<apex:form id="formId" title="Product Selection Wizard">
	<div style="width:500px;margin-left:30px;">
		<apex:pageBlock title="Product Selector">
			<apex:OutputLabel value="Pricebook:" style="font-weight:bold"/>
			<apex:selectList id="pbList" value="{!PricebookId}" size="1" title="Pricebook">
				<apex:selectOptions value="{!pb}"/>
  			<apex:commandButton action="{!refreshProducts}" rerender="treeViewPanel" value="Go"/>

			<apex:outputPanel id="treeViewPanel">

				<div class="treeheader" style="height:0px;">&nbsp;</div>
				<div id="sidetreecontrol"><a href="?#"><font style="color:blue;">Collapse All</font></a> | <a href="?#"><font style="color:blue;">Expand All</font></a></div>

				<ul id="tree" class="filetree">
					<apex:repeat value="{!Products}" var="level1">
					<li class="closed"><span class="folder">{!level1.Product2.Cloud__c}</span>
							<apex:repeat value="{!level1.Name}" var="level2">
								<li><span class="file"><a href="/{!level1.Pricebook2Id}" target="_blank">{!level1.Name}</a></span></li>






public with sharing class ProductTreeViewController {
	public list<selectOption> options = new list<selectOption>(); // list to hold Pricebook options
	public list<PricebookEntry> Products = new list<PricebookEntry>();
	private Id PricebookId;

	public ProductTreeViewController(){
		this.PricebookId = getPricebookId();
		//this.Products = getProducts();

	public list<PricebookEntry> getProducts(){
		list<PricebookEntry> Products = [select Pricebook2Id, Id, ProductCode, Name, Product2.Family, Product2.Cloud__c,
                    Product2.Product_Sub_Family__c from PricebookEntry
                    where IsActive = true and Pricebook2Id = :PricebookId limit 10];

        system.debug('----------------------- PricebookId: ' + PricebookId);
        system.debug('----------------------- this.PricebookId: ' + this.PricebookId);
        system.debug('----------------------- Products: ' + Products);
        return Products;

	public Id getPricebookId(){
		if(PricebookId==null) PricebookId='01s4000000024pn';
        return PricebookId;

    public void setPricebookId(Id PricebookId){
        this.PricebookId = PricebookId;

	public PageReference refreshProducts(){
        system.debug('----------------------- xPricebookId: ' + PricebookId);
        system.debug('----------------------- xthis.PricebookId: ' + this.PricebookId);
        system.debug('----------------------- xProducts: ' + Products);
        return null;

	public List<selectOption> getpb() {
		list<selectOption> options = new list<selectOption>(); //new list for holding all of the picklist options
		for (Pricebook2 pb2 : [select Id, Name from Pricebook2 where IsActive = true]) {
			options.add(new selectOption(pb2.Id, pb2.Name));
		return options;