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 

rerender fields based on selectlist options

Hey Everyone,

 

Im having issues rerendering fields based on which select option i choose.  The outputfields populate just fine when i add new options to the selectlist, but when I click on another option the fields fail to rerender.  I have already tried both onselect and onclick.  Does anyone see anything wrong?

 

<apex:selectList id="selected_list" required="false" value="{!unselected}" multiselect="true" size="20" style="width:150px">
<apex:selectOptions value="{!selectedOptions}"/>
<apex:actionSupport event="onchange" reRender="Details"/>
</apex:selectList>

<apex:panelGroup >
<apex:actionFunction name="UpdatePopDetails" rerender="AllDetails"/>
<apex:outputPanel id="Details">
<apex:pageBlockSection columns="1" >
<apex:outputField value="{!items.Brand__c}"/>
<apex:outputField value="{!items.Product_Line__c}"/>
<apex:outputField value="{!prodObject.Sub_Product_Line__c}"/>
<apex:outputField value="{!items.SKU__c}"/>
<apex:outputField value="{!prodObject.Description__c}"/>
<apex:outputField value="{!prodObject.Plan_to_Sell__c}"/>
<apex:outputField value="{!prodObject.NPI_Transition__c}"/>
</apex:pageBlockSection>
</apex:outputPanel>
</apex:panelGroup>

 

-hkp716

MagulanDuraipandianMagulanDuraipandian

https://sites.google.com/site/infallibletechie/rerender-based-on-selectlist-option-using-apex-in-salesforce

 

http://infallibletechie.blogspot.in/2012/12/rerender-based-on-selectlist-option.html

 

Check above links....

 

Regards,

Magulan D

Salesforce.com certified Force.com Developer.

SFDC Blog

SFDC Site

If this post is your solution, kindly mark this as the solution.

hkp716hkp716

HI Magu,

 

Thanks for the reply.  Im not sure how to apply the sample.  My selectlist (2) is being populated dynamically by another selectlist (1).  Selectlist (2) can have over 30 options so it would nearly impossible to apply an IF ELSE in the public void to keep rerendering the inputfields everytime i select a new option...

 

-hkp716

 

Here is my full code:

 

<apex:page Controller="custFPUI" extensions="listTransfer">
<br/>
<apex:form >
<apex:actionRegion >
<apex:actionFunction name="UpdateProductList" rerender="ProductList"/>

<apex:pageBlock title="Floor Plan Details" mode="edit" id="temptable">
<apex:pageBlockSection columns="1">
<apex:inputField value="{!fp.Floor_Plan_Title__c}"></apex:inputField>
<apex:inputField value="{!fp.Floor_Plan_Date__c}"></apex:inputField>
<apex:outputField value="{!fp.Account__c}"></apex:outputField>
</apex:pageBlockSection>
</apex:pageBlock>

<apex:pageBlock title="Add Models" mode="edit" id="ptable">
<apex:pageBlockSection columns="1">
<apex:inputField value="{!prodObject.Brand__c}" onchange="UpdateProductList();">
<!--<apex:actionSupport event="onchange" reRender="ptable"/>-->
</apex:inputField>
<apex:inputField value="{!prodObject.Product_Line__c}" onchange="UpdateProductList();">
<!--<apex:actionSupport event="onchange" reRender="ptable"/>-->
</apex:inputField>
<apex:inputField value="{!prodObject.Sub_Product_Line__c}" onchange="UpdateProductList();" >
<!--<apex:actionSupport event="onchange" reRender="ptable"/>-->
</apex:inputField>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageMessages />
<apex:pageBlock title="Move Models" mode="edit" id="selectionBlock">
<apex:panelGrid columns="5">
<apex:outputPanel id="ProductList">
<apex:selectList id="skuname" required="false" value="{!selected}" multiselect="true" size="20" style="width:150px">
<apex:selectOptions value="{!skuNames}"/>
</apex:selectList>
</apex:outputPanel>

<apex:panelGroup >
<apex:commandButton value=" ADD SKU " action="{!doAdd}" rerender="selectionBlock"/>
<br/>
<apex:commandButton value="REMOVE SKU" action="{!doRemove}" rerender="selectionBlock"/>
</apex:panelGroup>

<apex:selectList id="selected_list" required="false" value="{!unselected}" multiselect="true" size="20" style="width:150px">

<apex:selectOptions value="{!selectedOptions}"/>
<apex:actionSupport event="onchange" reRender="Details"/>

</apex:selectList>

<apex:panelGroup >
<apex:actionFunction name="UpdatePopDetails" rerender="AllDetails"/>
<apex:outputPanel id="Details">
<apex:pageBlockSection columns="1" >
<apex:outputField value="{!items.Brand__c}"/>
<apex:outputField value="{!items.Product_Line__c}"/>
<apex:outputField value="{!prodObject.Sub_Product_Line__c}"/>
<apex:outputField value="{!items.SKU__c}"/>
<apex:outputField value="{!prodObject.Description__c}"/>
<apex:outputField value="{!prodObject.Plan_to_Sell__c}"/>
<apex:outputField value="{!prodObject.NPI_Transition__c}"/>
</apex:pageBlockSection>
</apex:outputPanel>
</apex:panelGroup>

<apex:panelGroup >
<apex:pageBlockSection columns="1">
<apex:inputField value="{!fdp.Meet_Comp__c}"/>
<apex:inputField value="{!fdp.In_Vignette__c}"/>
<apex:inputField value="{!fdp.Customer_Floor_Selling_Price__c}"/>
<apex:inputField value="{!fdp.Units_On_Hand__c}"/>
<apex:inputField value="{!fdp.ASM_Transition_Recommendation__c}"/>
<apex:inputField value="{!fdp.Notes__c}"/>
</apex:pageBlockSection>
</apex:panelGroup>

</apex:panelGrid>

</apex:pageBlock>


</apex:actionRegion>
<br/>
</apex:form>
</apex:page>

 

controller:

 

public class listTransfer{

public listTransfer(custFPUI controller) {

}


private Set<String> unSelectedNames = new Set<String>();
private Set<String> selectedNames = new Set<String>();
private set<String> inaccessibleNames = new Set<String>();
public Boolean b {set; get;}
public List<Product2> newProdtLine { set; get; }
public listTransfer(ApexPages.StandardController controller)
{
b = false;
}
public Product2 Items { set; get; }

public Product2 getProdObject()
{
if(items == null)
{
items = new Product2();
return Items;
}
else
return Items;
}

public List<SelectOption> getSkuNames() {
System.debug('******Selected Brand*****'+Items.Brand__c);
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('--Select SKU--', '--Select SKU--', true));
newProdtLine = [SELECT Brand__c,Product_Line__c,SKU__c,Sub_Product_Line__c FROM Product2 WHERE
Brand__c =: Items.Brand__c AND
Product_Line__c =:Items.Product_Line__c AND
Sub_Product_Line__c =: Items.Sub_Product_Line__c ORDER BY SKU__c];
System.debug('*********Product Line*******'+newProdtLine);
try
{
for (Product2 p : newProdtLine) {
options.add(new SelectOption(p.SKU__c, p.SKU__c));
}
}
catch(Exception e)
{
}
return options;
}


public List<String> getDisplayItems() {
List<String> displayItems = new List<String>(selectedNames);
displayItems.sort();
return displayItems;
}



public List<SelectOption> getSelectedOptions() {
return selectOptionsFromSet(selectedNames);
}
public List<SelectOption> getUnSelectedOptions() {
return selectOptionsFromSet(unSelectedNames);
}

private List<SelectOption> selectOptionsFromSet(Set<String> opts) {
List<String> optionsList = new List<String>(opts);
optionsList.sort();
List<SelectOption> options = new List<SelectOption>();
for (String s : optionsList) {
options.add(new
SelectOption(s, decorateName(s), inaccessibleNames.contains(s)));
}
return options;
}

private String decorateName(String s) {
return inaccessibleNames.contains(s) ? '*' + s : s;
}

// These properties receive the customization form postback data

// Each time the [<<] or [>>] button is clicked, these get the contents

// of the respective selection lists from the form

public transient List<String> selected { get; set; }
public transient List<String> unselected { get; set; }

// Handle the actual button clicks. Page gets updated via a

// rerender on the form

public void doAdd() {
moveItems(selected, selectedNames, unSelectedNames);
}
public void doRemove() {
moveItems(unselected, unSelectedNames, selectedNames);
}

private void moveItems(List<String> items,
Set<String> moveTo, Set<String> removeFrom) {
for (String s: items) {
if( ! inaccessibleNames.contains(s)) {
moveTo.add(s);
removeFrom.remove(s);
}
}
}
}