+ Start a Discussion
dkorba2k5dkorba2k5 

Rerender Question

Wondering if someone can post a simple example of the following.  I've got two picklists that I'm populating dynamically.  I was able to get this to work within the pageBlockSection tags.  However, I need this to work in terms of a spreadsheet-like/grid-entry.  So I need to see how to do it using a dataTable tag instead.  So it would look something like:

Row 1  Quantity -- Picklist 1 -- Picklist 2
Row 2  Quantity -- Picklist 1 -- Picklist 2

Where Picklist 2 re-renders based on Picklist 1 for each row independently

Thanks in advance
TehNrdTehNrd
Put an outputPanel inside your picklist2 column and then call the rerender on this. Post your code if you have any questions.
dkorba2k5dkorba2k5
TecNrd thanks for the reply.  Here's a snipet of the VF page with the two columns in question.

                 <apex:column width="10"><apex:facet name="header">Category</apex:facet>
                     <apex:selectList value="{!category}" size="1" id="category" styleClass="tabletext">
                         <apex:selectOptions value="{!categories}"/>
                         <apex:actionSupport event="onchange" rerender="family"/>
                     </apex:selectList>
                 </apex:column>
                <apex:column width="10"><apex:facet name="header">Family</apex:facet>
                    <apex:outputPanel id="family">
                        <apex:selectList value="{!family}" size="1" styleClass="tabletext">
                            <apex:selectOptions value="{!families}"/>
                        </apex:selectList>
                    </apex:outputPanel>
                </apex:column>

It's not re-rendering anything.  Thanks for your help.
TehNrdTehNrd
Do you have any other fields on your controller that may be required? Add this code your code and then try to perform the rerender.

Code:

<!--add error to the rerender -->
<apex:actionSupport event="onchange" rerender="family,error"/> <!--put this at the top of page-->
<apex:outputPanel id="error"/> <apex:messages/> </apex:outputPanel>

It also just hit me that this is actually a little more complicated that I thought as there will be many different picklists with many different values. Post your code if possible as this is probably going to require a wrapper class.

-Jason

dkorba2k5dkorba2k5
ok ... so in concept what I'm trying to do is create two things here.  1.  A multi-record view of related items much like a spreadsheet format and 2. Have the picklists for each record dynamically created so that we don't have to maintain them all the time.  I had #1 working fine and wanted to add #2.  I have #2 working fine by itself but am trying to incorporate it into #1.   Appreciate the help

So here's the VF page I have so far:

Code:
<apex:page StandardController="Quote__c" extensions="quoteDetails" tabStyle="Quote__c" sidebar="true" standardStylesheets="true" showHeader="true" id="page">
<style>
.dim_a {width:300px; font-family: Verdana; font-size: 10px; font-weight: normal;}
.dim_b {width:70px; font-family: Verdana; font-size: 10px; font-weight: normal;}
.tabletext {font-family: Verdana; font-size: 10px; font-weight: normal;}
.btabletext {font-family: Verdana; font-size: 10px; font-weight: normal; color: blue;}
</style>
     <apex:detail relatedList="False"/>
     <apex:form >
 <apex:outputPanel id="error">
    <apex:messages />
</apex:outputPanel>
       <apex:pageBlock title="Line Item Details Edit">
        <apex:pageBlockButtons >
            <apex:commandButton value="Save"  action="{!save}" status="outStatus"/>
            <apex:commandButton value="Add"   action="{!add}" rerender="rows" status="outStatus"/>
            <apex:commandButton value="Reset" action="{!reset}" rerender="rows" status="outStatus" immediate="true" />
            <br>&nbsp
            <apex:actionStatus startText="(.................working.................)" stopText="" id="outStatus" onstop="Reset"/>
        </apex:pageBlockButtons>
        <apex:dataTable columns="9" border="1" cellpadding="2" value="{!entries}" var="a" id="rows" styleClass="tabletext"> 
                <apex:column width="5"><apex:facet name="header">Remove</apex:facet><apex:inputField value="{!a.Del__c}" styleClass="tabletext"/></apex:column>
                <apex:column width="5"><apex:facet name="header">Qty</apex:facet><apex:inputField value="{!a.Quantity__c}" required="true" styleClass="dim_b"/></apex:column>
                <apex:column width="5"><apex:facet name="header">Discount %</apex:facet><apex:inputField value="{!a.Discount__c}" required="false" styleClass="dim_b"/></apex:column>
     <apex:column width="10"><apex:facet name="header">Category</apex:facet>
      <apex:selectList value="{!category}" size="1" id="category" styleClass="tabletext">
       <apex:selectOptions value="{!categories}"/> 
       <apex:actionSupport event="onchange" rerender="family,error"/>
      </apex:selectList>
     </apex:column>
    <apex:column width="10"><apex:facet name="header">Family</apex:facet>
     <apex:outputPanel id="family">
      <apex:selectList value="{!family}" size="1" styleClass="tabletext">
       <apex:selectOptions value="{!families}"/>
       <apex:actionSupport event="onchange" rerender="functionality,platform"/>
      </apex:selectList>
     </apex:outputPanel>
    </apex:column>
    <apex:column width="10"><apex:facet name="header">Functionality</apex:facet>
     <apex:selectList value="{!functionality}" size="1" id="functionality" disabled="{!ISNULL(family)}" styleClass="tabletext">
      <apex:selectOptions value="{!functions}"/>
      <apex:actionSupport event="onchange" rerender="platform"/>
     </apex:selectList>
    </apex:column>
     <apex:column width="10"><apex:facet name="header">Platform</apex:facet><apex:selectList value="{!platform}" size="1" id="platform" disabled="{!ISNULL(functionality)}" styleClass="tabletext"><apex:selectOptions value="{!platforms}"/></apex:selectList></apex:column>
            </apex:dataTable>
        </apex:pageblock>
    </apex:form>
</apex:page>

 
Here's the controller:

Code:
public class quoteDetails 
{
 public id pbid;
    String category;
    String family;
    String functionality;
    String platform;
 
    private final Quote__c entry;
    
    Quote__c  t;
    
    public quoteDetails(Quote__c t)
    {
        this.t = t;
        init();
    }
    
    public quoteDetails(ApexPages.StandardController stdController) {
        this.entry = (Quote__c)stdController.getRecord();
        init();
    }
     
    public List<QuoteLine__c> entryList;  // list of components to appear in the multi-line
    
    public PageReference reset() 
    {
        entryList = [SELECT Extended_Net_Price__c, Subscription__c, Platform__c, Category__c, Geography__c, Functionality__c, 
                    Family__c, Order_Category__c, Start_Date__c, End_Date__c, Quantity__c, Product_Code__c, Description__c, 
                    Discount__c, Product_Name__c, Quote__c, Del__c
                    FROM QuoteLine__c
                    WHERE Quote__c = :System.currentPageReference().getParameters().get('id')
                    ORDER BY Start_Date__c];
        return null;
    }  
        
    public List<QuoteLine__c> getEntries() 
    {
        if(entryList == null) reset(); 
        return entryList;
    }
        
    public void setEntries(List<QuoteLine__c> Entries) {entryList = Entries;}
        
    public PageReference save() 
    {
        QuoteLine__c entry = new QuoteLine__c();
        QuoteLine__c[] deleteList = new QuoteLine__c[0];
     
        upsert entryList;

        deleteList = [SELECT id FROM QuoteLine__c WHERE Quote__c=:ApexPages.currentPage().getParameters().get('id') AND del__c=TRUE];

        if (deleteList.size() > 0) {delete deleteList;}
        reset();
        PageReference pageRef = new PageReference('/' + ApexPages.currentPage().getParameters().get('id'));
        pageRef.setRedirect(true);
        return pageRef;
    }

    public PageReference add() 
    {
        entryList.add(New QuoteLine__c(Quote__c = ApexPages.currentPage().getParameters().get('id')));
        return null;
    }
        
    public Quote__c getQuote() {return [SELECT Id, Name FROM Quote__c WHERE id=:ApexPages.currentPage().getParameters().get('id')];}

 public void init() {getPriceBookId();}
    
 public void getPriceBookId() {pbid = ([SELECT id from PriceBook2 WHERE Name='NA Price Book']).id;}

 public String getCategory() {return this.category;}
    public void setCategory(String s) { this.category = s; }    
    public List<SelectOption> getCategories() 
    {
  Set<String> Categories = new Set<String>();
  List<String> CategoryList = new List<String>();
  List<SelectOption> optionList = new List<SelectOption>();
  optionList.add(new SelectOption('','-- NONE --'));  
  for (PricebookEntry[] cat : ([SELECT Product2.Category__c FROM PricebookEntry 
         WHERE IsActive=TRUE AND PriceBook2Id=:pbid 
         ORDER BY Product2.Category__c]))
  {
   for (PricebookEntry entry: cat)
   {
    if (!Categories.contains(entry.Product2.Category__c))
    {
     Categories.add(entry.Product2.Category__c);
     optionList.add(new SelectOption(entry.Product2.Category__c,entry.Product2.Category__c));
    }
   }
  }
       return optionList;
    }  

 public String getFamily() {return this.family;}
    public void setFamily(String s) { this.family = s; }  
 public List<SelectOption> getFamilies() 
    {
  Set<String> Families = new Set<String>();     
  List<SelectOption> optionList = new List<SelectOption>();
  optionList.add(new SelectOption('','-- NONE --'));
  if (category != null)
  {
   for (PricebookEntry Family : ([SELECT Product2.Family FROM PricebookEntry 
          WHERE IsActive=TRUE AND PriceBook2Id=:pbid AND Product2.Category__c = :category 
          ORDER BY Product2.Family])) 
   {
    if (!Families.contains(Family.Product2.Family))
    {
     Families.add(Family.Product2.Family);
     optionList.add(new SelectOption(Family.Product2.Family,Family.Product2.Family));
    }
   }
  }
       return optionList;
    } 

 public String getFunctionality() {return this.functionality;}
    public void setFunctionality(String s) { this.functionality = s; }  
 public List<SelectOption> getFunctions() 
    {
  Set<String> Functions = new Set<String>();     
  List<SelectOption> optionList = new List<SelectOption>();
  optionList.add(new SelectOption('','-- NONE --'));
  if (family != null)
  {
   for (PricebookEntry Function : ([SELECT Product2.Functionality__c FROM PricebookEntry 
          WHERE IsActive=TRUE AND PriceBook2Id=:pbid AND 
          Product2.Category__c = :category AND Product2.Family = :family
          ORDER BY Product2.Functionality__c])) 
   {
    if (!Functions.contains(Function.Product2.Functionality__c))
    {
     Functions.add(Function.Product2.Functionality__c);
     optionList.add(new SelectOption(Function.Product2.Functionality__c,Function.Product2.Functionality__c));
    }
   }
  }
       return optionList;
    }       
 public String getPlatform() {return this.platform;}
    public void setPlatform(String s) { this.platform = s; }  
 public List<SelectOption> getPlatforms() 
    {
  Set<String> Platforms = new Set<String>();     
  List<SelectOption> optionList = new List<SelectOption>();
  optionList.add(new SelectOption('','-- NONE --'));
  if (functionality != null)
  {
   for (PricebookEntry Plats : ([SELECT Product2.Platform__c FROM PricebookEntry 
          WHERE IsActive=TRUE AND PriceBook2Id=:pbid AND 
          Product2.Category__c = :category AND Product2.Family = :family
          AND Product2.Functionality__c = :functionality
          ORDER BY Product2.Platform__c])) 
   {
    if (!Platforms.contains(Plats.Product2.Platform__c) && Plats.Product2.Platform__c != null)
    {
     Platforms.add(Plats.Product2.Platform__c);
     optionList.add(new SelectOption(Plats.Product2.Platform__c,Plats.Product2.Platform__c));
    }
   }
  }
       return optionList;
 }
}