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
hkp716hkp716 

Select List Doesn't Rerender

Fellow Devs,

I am trying to set up a select list that rerenders after an option is selected in my sub product line picklist. All the products currently being shown right now. I've used action support on my visualforce page but no luck so far.

 

Any suggestions?

hkp716

 

VF:
<apex:page standardController="product2" extensions="brands1,plist1">
<apex:form >
<apex:pageBlock title="Floor Planning" mode="edit">
<apex:pageBlockSection columns="1">
<apex:inputField value="{!product2.Brand__c}">
<b>Product Line:</b> <apex:inputField value="{!product2.Product_Line__c}" />
<b>Sub-Product Line:</b> <apex:inputField value="{!product2.Sub_Product_Line__c}" />
</apex:inputField>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:selectList value="{!Prods}" multiselect="true">
<apex:selectOptions value="{!items}"/>
</apex:selectList><p/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>


</apex:page>

 

 

Controller:

 

public class brands1 {

Public string currentbrand {get; set;}
Public string currentpline {get; set;}
Public string currentspline {get; set;}

public brands1(ApexPages.StandardController controller)
{
currentbrand = currentpline = currentspline = null;
}
public List<SelectOption> getTypes()
{
Schema.sObjectType sobject_type = product2.getSObjectType();
Schema.DescribeSObjectResult sobject_describe = sobject_type.getDescribe();
Map<String, Schema.SObjectField> field_map = sobject_describe.fields.getMap();

List<Schema.PicklistEntry> pick_list_values = field_map.get('Select_Brand__c').getDescribe().getPickListValues();
List<selectOption> options = new List<selectOption>();
for (Schema.PicklistEntry a : pick_list_values)
{
options.add(new selectOption(a.getLabel(), a.getValue()));
}
return options;
}


public with sharing class plist1 {
String[] prods = new String[]{};

public List<SelectOption> getItems() {
List<SelectOption> options = new List<SelectOption>();
List<Product2> ProductsForPage = [Select Id,SKU__c,Brand__c From Product2];
for (Product2 p : ProductsForPage) {
options.add(new SelectOption(p.Id, p.SKU__c));
}
return options;
}

public String[] getprods() {
return prods;
}

public void setprods(String[] prods) {
this.prods = prods;
}


public List<Product2> getProducts() {

List<Product2> ProductsForPage = [Select Id,SKU__c,Brand__c From Product2];
return ProductsForPage;


}
}
}


EXT:


public with sharing class plist1 {

public plist1() {

}


public plist1(ApexPages.StandardController controller) {

}

String[] prods = new String[]{};

public List<SelectOption> getItems() {
List<SelectOption> options = new List<SelectOption>();
List<Product2> ProductsForPage = [Select Id,SKU__c,Brand__c From Product2 WHERE Use_for_Floor_Planning__c = true];
for (Product2 p : ProductsForPage) {
options.add(new SelectOption(p.Id, p.SKU__c));
}
return options;
}

public String[] getprods() {
return prods;
}

public void setprods(String[] prods) {
this.prods = prods;
}

}

hkp716hkp716

 

Updated VF:

 

<apex:page standardController="product2" extensions="brands1,plist1">
<apex:form >
<apex:actionFunction name="UpdateProductList" rerender="ProductList"/>
<apex:pageBlock title="Floor Planning" mode="edit">
<apex:pageBlockSection columns="1">
<apex:inputField value="{!product2.Brand__c}">
<b>Product Line:</b> <apex:inputField value="{!product2.Product_Line__c}" />
<b>Sub-Product Line:</b> <apex:inputField value="{!product2.Sub_Product_Line__c}" onchange="UpdateProductList();" />
</apex:inputField>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:selectList id="ProductList" value="{!Prods}" multiselect="true">
<apex:selectOptions value="{!items}"/>
</apex:selectList><p/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>


</apex:page>

colemabcolemab

try wrapping the area(s) you want to rerender in an apex:outputpanel and then rerender that ID.

hkp716hkp716

Doesn't work.  Not sure if I did this correctly.  This is what I changed it to:

 

<apex:page standardController="product2" extensions="brands1,plist1">
<apex:form >
<apex:actionFunction name="UpdateProductList" rerender="ProductList"/>
<apex:pageBlock title="Floor Planning" mode="edit">
<apex:pageBlockSection columns="1">
<apex:inputField value="{!product2.Brand__c}">
<b>Product Line:</b> <apex:inputField value="{!product2.Product_Line__c}" />
<b>Sub-Product Line:</b> <apex:inputField value="{!product2.Sub_Product_Line__c}" onchange="UpdateProductList();" />
</apex:inputField>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageBlock >
<apex:pageBlockSection >
<apex:outputPanel id="ProductList">
<apex:selectList value="{!Prods}" multiselect="true">
<apex:selectOptions value="{!items}"/>
</apex:selectList><p/>
</apex:outputPanel>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

colemabcolemab

I noticed that you don't have an action defined in your action function which means the page will just refresh.  Shouldn't you be calling an apex method to re-query the data?

hkp716hkp716

I added action="{!Prods}" in the actionfunction tag, didn't work, so then i changed it to action="{!items}", still nothing.  Was the syntax correct?

colemabcolemab

No that looks correct.  I am going to write an example (based on the standard CRM objects) in my dev system and post it here for you to review . . . . more to follow.

hkp716hkp716

I appreciate the help colemab.  

colemabcolemab

I think your issue might not be that the page isn't refreshing but is instead that the data isn't being passed to the controller and/or extensions during the javascript call (action support uses java script to call the apex method).

 

Here is a thread about this.

colemabcolemab

Here is a sample page:

<apex:page controller="testControllerExt" sidebar="false" >
	
	<apex:form >
		<apex:actionRegion >
			<apex:selectList id="SelectedText" value="{!NewAccount.Name}" onchange="RefreshCount();">
				<apex:selectOptions value="{!items}"/>
			</apex:selectList>	

			<apex:actionFunction action="{!IncrementCurrentCount}" name="RefreshCount" rerender="CurrentCountValue">
						 				
			</apex:actionFunction>
			
			<apex:pageBlock title="Count Value">
				<apex:pageBlockSection >
					<apex:outputPanel id="CurrentCountValue">
						<apex:outputText value="{!CurrentCount}" />
						<apex:outputText value="{!NewAccount.Name}" />
					</apex:outputPanel>
				</apex:pageBlockSection>
			</apex:pageBlock>
		
		</apex:actionRegion>		 
	
	</apex:form>	

</apex:page>

 And sample controller:

global with sharing class testControllerExt {

	public integer CurrentCount {get;set;}
	public string SelectedText {get;set;}
	
	public account NewAccount {get;set;}
	
	public testControllerExt ()  
	{
		NewAccount = New Account();
		CurrentCount = 0;
	} // constructor
	
	public void IncrementCurrentCount() 
	{
		CurrentCount += 1;
	}
	
	public List<SelectOption> getItems()
	{
		List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('US','US'));
        options.add(new SelectOption('CANADA','Canada'));
        options.add(new SelectOption('MEXICO','Mexico'));

        return options;		
	}
} // main class

 

colemabcolemab

In the sample I pasted above a new account named "newaccount" is created.   Anytime you select a country from the fixed list, that country becomes the name of the account and the counter gets incremented.

 

Notice that since the Account.Name is a database field, is being set by the value on the select list, and is *inside* the action region, you don't have to pass it as a param as in the other link i sent.  Instead, SFDC is sending that as part of the request.  If this field were outside of the action region it wouldn't be updated.

hkp716hkp716

Yea I see.  I'll work with it and post the results.  Thanks for the help.