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
Carter85Carter85 

Outputpanel not rendering properly

I need help figuring out why this isn't working on my VF page.  I have a section on my page set up like this:

<apex:commandButton style="width 50px;" value="Search" action="{!batchDetail}" status="status"/>
          </apex:pageBlockSection>
          </apex:pageBlock>
              <br/>
              <br/>
              <apex:outputPanel rendered="{!listResult == FOUND}">
              <apex:pageBlock >
              <apex:pageBlockSection title="Batch Information" id="resultsBlock" columns="1">
              <apex:pageBlockTable value="{!batchDetails}" var="item" rendered="{!NOT(ISNULL(batchDetails))}">
              <apex:column style="text-align:center;" value="{!item.Name}" headerValue="Batch #" width="95"/>
              <apex:column style="text-align:center;" value="{!item.Total_Contracts__c}" headerValue="Contract Holders" width="105"/>
              <apex:column style="text-align:center;" value="{!item.Product_Group__c}" headerValue="Policy Type" width="85"/>
              <apex:column style="text-align:center;" value="{!item.Form_Number__c}" headerValue="Form" width="95"/>
              <apex:column style="text-align:center;" value="{!item.Cancellable__c}" headerValue="Cancellable" width="95"/>
              <apex:column style="text-align:center;" value="{!item.Cancellation_Fee__c}" headerValue="Cancel Fee" width="95"/>
              <apex:column style="text-align:center;" value="{!item.Received_Date__c}" headerValue="Received Date" width="95"/>
             </apex:pageBlockTable>
            </apex:pageBlockSection>
           </apex:pageBlock>
          </apex:outputPanel>

 and it's governed by my controller here:

public PageReference batchDetail(){
          String qry = 'SELECT Name, Dealer__r.name, Received_Date__c, Product_Group__r.name, Total_Contracts__c FROM MG_Batch__c WHERE Name =:batchSearch AND Agent__c =:account LIMIT 1';
          batchDetails = Database.query(qry);
          if((batchDetails != null)){
          listResult = FOUND;
          return null;
              }
          else{
              listResult = NONE;
              ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'No Batches found which match that information, please try again.'));
              return null;
              }
              } 

 However, regardless of the outcome of the search an empty table is rendering with no error message or found records based on which statements are evaluating to be true and I would appreciate any help on pointing out where the error lies because I'm failing to see at the moment why this is not working when I have other similar sections which are.

Best Answer chosen by Admin (Salesforce Developers) 
Paul.FoxPaul.Fox

Do you have a pagemessages component in your visualforce page? It wasn't on the section you provided.

 

However, I usually do something like this for blank values (style info can go in your css)

<apex:outputPanel layout="block" styleClass="noRecordsFound" rendered="{!records.size == 0}">
			No records to display
		</apex:outputPanel>

<style>
.noRecordsFound{
			border: 1px solid #D4DADC;
			padding: 4px;
		}
</style>

 

All Answers

zachbarkleyzachbarkley

Hi Carter85,

 

You might need to include a rerender in your command button

 

<apex:commandButton style="width 50px;" value="Search" action="{!batchDetail}" status="status" rerender="MyPanel"/>
Carter85Carter85

Apologies, that doen't seem to have solved it.  Any other ideas by chance?

zachbarkleyzachbarkley

Try this VF  - Notice that the rerender is an outer block

 

<apex:commandButton style="width 50px;" value="Search" action="{!batchDetail}" status="status" rerender="MyOuterOutputPanel"/>
<apex:outputPanel id="MyOuterOutputPanel">
  <!----------------- PAGE MESSAGES -------------------------------------->                                
  <apex:PageMessages id="ER"/> <apex:outputPanel rendered="{!listResult == 'FOUND'}"> <apex:pageBlock > <apex:pageBlockSection title="Batch Information" id="resultsBlock" columns="1"> <apex:pageBlockTable value="{!batchDetails}" var="item" rendered="{!NOT(ISNULL(batchDetails))}"> <apex:column style="text-align:center;" value="{!item.Name}" headerValue="Batch #" width="95"/> <apex:column style="text-align:center;" value="{!item.Total_Contracts__c}" headerValue="Contract Holders" width="105"/> <apex:column style="text-align:center;" value="{!item.Product_Group__c}" headerValue="Policy Type" width="85"/> <apex:column style="text-align:center;" value="{!item.Form_Number__c}" headerValue="Form" width="95"/> <apex:column style="text-align:center;" value="{!item.Cancellable__c}" headerValue="Cancellable" width="95"/> <apex:column style="text-align:center;" value="{!item.Cancellation_Fee__c}" headerValue="Cancel Fee" width="95"/> <apex:column style="text-align:center;" value="{!item.Received_Date__c}" headerValue="Received Date" width="95"/> </apex:pageBlockTable> </apex:pageBlockSection> </apex:pageBlock> </apex:outputPanel> </apex:outputPanel>

 

AND Apex

 

public String listResult {get;set;}
	public PageReference batchDetail(){
		String qry = 'SELECT Name, Dealer__r.name, Received_Date__c, Product_Group__r.name, Total_Contracts__c FROM MG_Batch__c WHERE Name =:batchSearch AND Agent__c =:account LIMIT 1';
		batchDetails = Database.query(qry);
		if(batchDetails.IsEmpty()){
			listResult = 'NONE';
			ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'No Batches found which match that information, please try again.'));
			return null;
		}else{
			listResult = 'FOUND';
			return null;
		}
	} 

 

 

Paul.FoxPaul.Fox

Are you getting an empty table or an empty section? If the columns are showing up with no values then you'd have to look in the controller and make sure you're getting data.

 

If you're getting a blank section, then you can modify the rendered attributes. You don't need the listresult variable. Just use the following on the pageblock table and remove the outputpanel.

rendered="{!batchDetails.size > 0}"

 

 

 

Carter85Carter85

Ok, this is working partially, but for some reason I still cant get it to not render the table and show the error messange when no results are found.  Results show up now, but it won't account for when the list is null.

Paul.FoxPaul.Fox

Do you have a pagemessages component in your visualforce page? It wasn't on the section you provided.

 

However, I usually do something like this for blank values (style info can go in your css)

<apex:outputPanel layout="block" styleClass="noRecordsFound" rendered="{!records.size == 0}">
			No records to display
		</apex:outputPanel>

<style>
.noRecordsFound{
			border: 1px solid #D4DADC;
			padding: 4px;
		}
</style>

 

This was selected as the best answer
Carter85Carter85

Thanks, that did resolve it, though I'm still confused as to why other tables set up exactly the same way were working properly but this one was giving me so much grief.  Regardless, it's working now and I do appreciate it, so thanks again.