I am in a situation where I cannot find a solution ... I have a visualforce page where one of the fields is "Search" that opens a visualforce page with products that go through a filter.

Next there is a button that loads a list of colors available for that product and displays them in an apex:

enter image description here

what I am looking for is that every time I change the product, or every time I click on "search", the selectList is cleaned in such a way that the colors of the new product can be loaded without being confused with the first ones.

btn "buscar":

<div class="item">
<apex:inputHidden id="targetId" value="{!idproduct}"/>
<apex:inputText id="targetName" onFocus="this.blur()" onkeypress="return noenter(event);"  style="width : 560px;"><!--- disabled="false" -->
<a href="#" onclick="openLookupPopup('{!$Component.targetName}', '{!$Component.targetId}'); return false" rerender="out,list">Buscar</a>

div -> colors from products

<div class="form-group mb-10">
 <apex:selectList value="{!DEXTRA }" size="5" style="width: 360px;" id="list">
  <apex:selectOptions value="{!DExtraList}"></apex:selectOptions>
  <apex:actionSupport event="onchange"  rerender="theTable"/>

Please, it would only be that this box is empty every time you change the product or every time you click the "search" button for a new product.

enter image description here

Thanks for your help!

Controller DExtraList:

public List<SelectOption> DExtraList
        //system.debug('PROD CARGADO, populando colores externos' + PE.Producto__c);
        List<Id> ls = new List<Id>();
        List<Color_Externo_del_Producto__c> CES = [select Name, Id, Product__c, Color_Externo__c from Color_Externo_del_Producto__c where Product__c=:PE.Producto__c];
        for(Color_Externo_del_Producto__c e :CES){ls.add(e.Color_Externo__c);}
        try{ETemp2 = [Select Name, Codigo__c, Id from Mantenimiento__c where Id IN :ls];}            catch(exception q){ETemp2 = [Select Name,Id from Mantenimiento__c];}
        //system.debug('LISTA CARGADA ' + ETemp);
        DExtraList= new List<SelectOption>();
        for(Mantenimiento__c temp : ETemp2 )
            DExtraList.add(new SelectOption(temp.Id, temp.Codigo__c + ' - ' + temp.Name));
        return DExtraList;


var newWin=null;

function openLookupPopup(name, id){
    //var inname=document.getElementById("{!$Component.page1.formid.theTable.sec1.item3.Idcatalogo}").value;
    var inname=document.getElementById("{!$Component.formid.theTable.Idcatalogo}").value;

    var url="/apex/PedidoEspLookup?namefield=" + name + "&idfield=" + id +"&parentname="+inname;
newWin=window.open(url, 'Popup','height=500,width=600,left=100,top=100,resizable=no,scrollbars=yes,toolbar=no,status=no');
    if (window.focus){
    return false;
function closeLookupPopup(){
    if (null!=newWin)
  • the controller is going to need to be signaled to clear the collection in DExtraList on each search so ithe getter for DExtraList fetches anew – cropredy Apr 6 at 23:49
  • @cropredy The truth is that I do not have much experience in this, could you tell me how I can achieve this? – Jesús Merino Apr 7 at 15:19
  • You'll need to use edit to show your controller (relevant bits only) – cropredy Apr 7 at 15:37
  • @cropredy okay with that part? – Jesús Merino Apr 7 at 15:44

So, the basic pattern you're going to need is the following:

getter for the selectList - note the test for null value

 public List<SelectOption> DExtraList {
   get {
     if (DExtraList == null) {
        ...construct the selectList by querying the objects
     return DExtraList;
   } private set;

action method that is signaled when product changes or search is done

 public void reset() {
   this.DExtraList == null;

So, reset() can be invoked from elsewhere in the controller (if controller is able to detect the search event or product change event) or can be invoked from the VF page using an apex:actionFunction, apex:commandButton or apex:commandLink . Because reset() sets the selectList to null, the next time the VF page needs to display the selectList, the getter is invoked and it requeries the database using whatever product is now set by the user.

You'll need to make sure the product PE.Producto__c new value is sentback to the controller when it changes; this might require use of an apex:actionSupport component

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.