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
Mr. MetMr. Met 

Required Field not validating after rerender

On my VF page, I am rerendering the pageblock after the user selects from a picklist.  There can be variable # of rows on the page.  After the user selects a value for each row, additional columns are displayed.  The column with the required flag shows the red bar next to the input box but no error validation takes place when the user click on the save button.


Any ideas????


VF Page - 

<apex:page standardController="STG_Car_Stock_Sale_Items__c" extensions="CarStockSaleItemManageListController" >
<!-- <apex:page controller="ManageListController"> -->
<apex:form >

<apex:pageBlock title="Car Stock Sale Items">
<apex:pageMessages />
<apex:pageBlockButtons location="top">
<apex:commandButton value="Save" action="{!save}"/> 
<apex:commandButton value="Cancel" action="{!cancel}"/> 

<apex:pageBlockButtons location="bottom"> 
<apex:commandButton value="Save" action="{!save}"/> 
<apex:commandButton value="Cancel" action="{!cancel}"/> 

<apex:pageBlockTable value="{!wrappers}" var="wrapper" id="wtable">

<apex:column headerValue="Line #">
<apex:outputText value="{!wrapper.ident}"/>
<apex:column headerValue="Car Stock Sale ID">
<apex:outputField value="{!wrapper.acc.Name}"/>

<apex:column headerValue="Product">
<apex:selectList id="ProdAvail" value="{!wrapper.acc.STG_Car_Stock_Product__c}" size="1" >
<apex:actionSupport event="onchange" action="{!CSProdData}" reRender="wtable">
   <apex:param name="GetProductLine" value="{!wrapper.ident}" assignTo="{!GetProductLine}"/> 
<apex:selectOptions value="{!ProdAvail}"></apex:selectOptions>

<apex:column headerValue="Quantity On Hand" id="test">
<apex:actionRegion >
<!-- <apex:outputField value="{!wrapper.acc.Quantity_Available__c}" rendered="{!DisplayFields}" /> -->
<apex:outputField value="{!wrapper.acc.Quantity_Available__c}"/>
<apex:column headerValue="Quantity (# of Units)">
<apex:inputField value="{!wrapper.acc.Quantity__c}" required="{!DisplayFields}" style="display:{!IF(!DisplayFields == false,'inline', 'none')}" />
<apex:column headerValue="Price (per Unit)">
<apex:inputField value="{!wrapper.acc.Unit_Price__c}" style="display:{!IF(!DisplayFields == false,'inline', 'none')}" />




Controller - 

public with sharing class CarStockSaleItemManageListController 
 public List<AccountWrapper> wrappers {get; set;}
 public STG_Car_Stock_Sale__c css {get; set;}
 private String cssiname;
 Id returnCSid;
 public static Integer GetProductLine {get; set;}
 public static String GetProduct {get; set;}
 public static String GetProductscreen {get; set;}
 Public STG_Car_Stock_Product__c CSPData {get; set;}
 public static Boolean DisplayFields {get; set;}
 private Integer CountProducts;
 public CarStockSaleItemManageListController (ApexPages.StandardController stdController) {
    Id currentStockSaleId = ApexPages.CurrentPage().getParameters().get('carstock');
    returnCSid = currentStockSaleId;
    if(currentStockSaleId != null){
        this.css = [Select Name, Id, Number_of_Lines__c, Customer_Account__c, STG_Car_Stock__c 
                    From STG_Car_Stock_Sale__c where Id =:currentStockSaleId ];
  wrappers=new List<AccountWrapper>();

  for (Integer idx=1; idx<=css.Number_of_Lines__c; idx++)
   if(idx < 10){
      cssiname = + '0' + idx;
   } else {
      cssiname = + idx;
   wrappers.add(new AccountWrapper(idx, cssiname, currentStockSaleId));

  //builds a picklist of Products based on the wholesale account
  public List<selectOption> getProdAvail() {
     //new list for holding all of the picklist options
     List<selectOption> options = new List<selectOption>(); 

     //add the first option of '- None -' in case the user doesn't want to select a value or in case no values are returned from query below  
     options.add(new selectOption('', '- None -')); 
     //System.debug('************ Query:11 ************ ' + scp);   

     //query for Product records 
     for (STG_Car_Stock_Product__c acctpa : [SELECT Id, Product__c FROM STG_Car_Stock_Product__c 
     WHERE STG_Car_Stock__c = :css.STG_Car_Stock__c AND Quantity_On_Hand__c > 0 ORDER BY Product__c]) { 

        //for all records found - add them to the picklist options
        options.add(new selectOption(, acctpa.Product__c)); 
  //return the picklist options
  return options; 
 public PageReference save()
  System.debug('************ Query:ACTION SAVE1 ************ ' + wrappers[1].acc.Quantity__c);
  System.debug('************ Query:ACTION SAVE2 ************ ' + wrappers[0].acc.Unit_Price__c);
  List<STG_Car_Stock_Sale_Items__c> accs=new List<STG_Car_Stock_Sale_Items__c>();
  for (AccountWrapper wrap : wrappers)
  System.debug('************ Query:ACTION SAVE2 ************ ' + accs); 
  insert accs;
  PageReference returnPage = new PageReference('/' + returnCSid);
            return returnPage; 
 public PageReference cancel()
  PageReference returnPage = new PageReference('/' + returnCSid);
            return returnPage; 
 public PageReference CSProdData(){
     GetProductLine = GetProductLine-1;
     GetProduct = Wrappers[GetProductLine].acc.STG_Car_Stock_Product__c;
     if (GetProduct != null) {
        CSPData = [SELECT Id, Last_Purchase_Price_per_Unit__c, Product__c, Quantity_On_Hand__c 
                   FROM STG_Car_Stock_Product__c
                   WHERE Id = :GetProduct.substring(0,15)];
     Wrappers[GetProductLine].acc.Quantity_Available__c = CSPData.Quantity_On_Hand__c;
     Wrappers[GetProductLine].acc.Unit_Price__c = CSPData.Last_Purchase_Price_per_Unit__c.setScale(2);
     Wrappers[GetProductLine].acc.Avg_Purchase_Price__c = CSPData.Last_Purchase_Price_per_Unit__c;
     DisplayFields = false;
     CountProducts = 0;
     for (Integer idx=0; idx<=(Wrappers.size()-1); idx++)
       GetProduct = Wrappers[idx].acc.STG_Car_Stock_Product__c;
       if(GetProduct != null){
          CountProducts = CountProducts + 1;
       if (CountProducts == Wrappers.size()) {
          DisplayFields = true;
       //System.debug('************ Query:ACTION FOR7 ************ ' + CountProducts);
       //System.debug('************ Query:ACTION FOR8 ************ ' + Wrappers.size());
       //System.debug('************ Query:ACTION FOR9 ************ ' + DisplayFields); 
     return null;
 public class AccountWrapper
  public STG_Car_Stock_Sale_Items__c acc {get; private set;}
  public String iname {get; private set;}
  public String inamecss {get; private set;}
  public Integer ident {get; private set;}
  //public AccountWrapper(String inIdent)
  public AccountWrapper(Integer inIdent, String inName, String InNameCSS)
   acc=new STG_Car_Stock_Sale_Items__c(Name = iname, Line_Number__c = ident, STG_Car_Stock_Sale__c = inamecss);





The field is displaying when the DisplayFields variable is false and the required attribute is set to the value in DisplayFields. Therefore, the field is not required. 

The if statement shouldn't have the second !, it should be: {!IF(NOT(DisplayFields), 'inline', 'none')}

You can also use the rendered attribute for displaying: rendered="{!DisplayFields}"


Hope this helps!