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
Dogen ZenjiDogen Zenji 

Messages component not displaying errors

For the life of me, I can't get error messages to display on an <apex:messages> component.  Neither custom messages nor standard required field messages show in the component though they do show up in the system log.  Any help would be much appreciated!

Page
Code:
<apex:page controller="OpportunityController" tabStyle="Opportunity">
 <apex:sectionHeader title="Brand Selection" subtitle="Step 1 of 2"/>
 <apex:messages id="msgs" layout="list"/>
 <apex:form >
  <apex:pageBlock id="pbSearch" title="Search Criteria" mode="edit">
   <apex:pageBlockButtons >
    <apex:commandButton value="Search" action="{!searchProducts}" rerender="pbResults" status="status"/>
   </apex:pageBlockButtons>
   <apex:pageBlockSection columns="2">
    <apex:inputField id="picklistLOB" value="{!product.LineofBusiness__c}"/>
    <apex:inputField id="textName" value="{!product.Name}" required="true"/>
    <apex:inputField id="textPosition" value="{!product.Product__c}" required="false"/>
    <apex:inputField id="textPositionDetail" value="{!product.Product_Sub_Category__c}" required="false"/>
   </apex:pageBlockSection>
  </apex:pageBlock>
  <apex:pageBlock id="pbResults" title="Matching Results" mode="detail">
   <apex:pageBlockButtons >
    <apex:commandButton value="Select"/>
   </apex:pageBlockButtons>
   <apex:actionStatus id="status" startStyle="font-weight:bold; color:green;" startText="Loading...">
    <apex:facet name="stop">
     <apex:pageBlockTable value="{!Products}" var="prod">
      <apex:column value="{!prod.Name}"/>
      <apex:column value="{!prod.ProductCode}"/>
      <apex:column value="{!prod.LineofBusiness__c}"/>
     </apex:pageBlockTable>
    </apex:facet>
   </apex:actionStatus>
  </apex:pageBlock>
  <apex:pageBlock id="pbSelected" title="Selected Brands" mode="edit">
   <apex:pageBlockButtons >
    <apex:commandButton value="Remove"/>
    <apex:commandButton value="Next"/>
    <apex:commandButton action="{!Cancel}" value="Cancel"/>
   </apex:pageBlockButtons>
  </apex:pageBlock>
 </apex:form>
</apex:page>

 

Controller
Code:
public class OpportunityController
{
 private final Opportunity opp;
 private Product2 product;
 private Product2[] productArray = new Product2[0];
 
 public OpportunityController()
 {
  this.opp = [select Id, Name from Opportunity where Id = :ApexPages.currentPage().getParameters().get('id')];
 }
 
 public PageReference Cancel()
 {
  PageReference oppPage = new PageReference('/' + this.opp.id);
  oppPage.setRedirect(true);
  
  return oppPage;
 }
 
 public Product2 getProduct()
 {
  if(product == null) product = new Product2();
  return product;
 }
 
 public void setProduct(Product2 p)
 {
  product = p;
 }
 
 public Product2[] getProducts()
 {
  return productArray;
 }
 
 public PageReference searchProducts()
 {
  productArray.clear();

  String searchName = product.Name == null— '%': product.Name;
  String searchPosition = product.Product__c == null– '%': product.Product__c;
  String searchPositionDetail = product.Product_Sub_Category__c == null˜ '%': product.Product_Sub_Category__c;

  if(searchName.length() < 3 || searchPosition.length() < 3 || searchPositionDetail.length() < 3)
  {
   ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR, 'Please enter a minimum of 3 characters and click Search again.');
   ApexPages.addMessage(msg);
   System.debug(LoggingLevel.ERROR, 'Please enter a minimum of 3 characters and click Search again.');
  }

  for(Product2 p : [select p.Product__c, p.Product_Sub_Category__c, p.ProductCode, p.Name, p.LineofBusiness__c, (select Id from PricebookEntries)
   from Product2 p where p.LineofBusiness__c = :product.LineofBusiness__c
   and p.Name like :('%' + searchName + '%')
   and p.Product__c like :('%' + searchPosition + '%')
   and p.Product_Sub_Category__c like :('%' + searchPositionDetail + '%')
   order by p.Name, p.Product__c, p.LineofBusiness__c])
  {
   productArray.add(p);
  }
  return null;
 }
}

 

Best Answer chosen by Admin (Salesforce Developers) 
TehNrdTehNrd
In addition to my post above try tweaking this section:

Code:
<apex:outputPanel id="msgs">
 <apex:messages layout="list"/>
</apex:outputPanel>

 

All Answers

TehNrdTehNrd
Try this:

Code:
    <apex:commandButton value="Search" action="{!searchProducts}" rerender="pbResults,msgs" status="status"/>

 

Dogen ZenjiDogen Zenji
Thanks for the reply!  Unfortunately, no go.
TehNrdTehNrd
In addition to my post above try tweaking this section:

Code:
<apex:outputPanel id="msgs">
 <apex:messages layout="list"/>
</apex:outputPanel>

 

This was selected as the best answer
Dogen ZenjiDogen Zenji
That last suggestion did the trick.  Thanks again!