This is my VF Page
<apex:page controller="SearchFromURLController">
<apex:pageblock title="Account Search">
<apex:form >
<apex:pageblocksection >
<apex:pageBlockSectionItem >
<apex:outputLabel value="Enter the search string : " />
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:inputText value="{!name}"/>
</apex:pageBlockSectionItem>
<apex:commandButton status="id_stat" value="Go" action="{!popAccounts}"/>
<!--NOTE : adding attribute rerender="results_pb,no_recs" in the above cmdbtn cause no records to be shown-->
</apex:pageblocksection>
<apex:actionstatus starttext="Please wait..." id="id_stat" />
</apex:form>
</apex:pageblock>
<apex:pageblock rendered="{!searched}" title="Results" id="results_pb" >
<apex:pageBlockTable value="{!accounts}" var="a">
<apex:column value="{!a.Name}"/>
<apex:column value="{!a.Industry}" />
<apex:column value="{!a.Type}" />
</apex:pageBlockTable>
</apex:pageblock>
<apex:pageblock id="no_recs" rendered="{!isZero}">
<apex:outputtext value="No Records Found"/>
</apex:pageblock>
</apex:page>
This is my controller
public with sharing class SearchFromURLController {
public String name{get;set;}
public Boolean searched{get;set;}
public Boolean IsZero{get;set;}
public List<Account> accounts{get;set;}
public PageReference popAccounts()
{
isZero = false;
if(name != null)
{
searched = true;
String strquery = '%'+name+'%';
accounts = [SELECT Id,Name,Industry,Type FROM Account WHERE Name like :strquery];
if(accounts.size() == 0)
{
isZero = true;
}
System.debug('~~~~ '+isZero);
System.debug('~~~~~ '+accounts.size());
System.debug('~~~~~ '+strquery);
}
return null;
}
}
This VF page will contain a text box and a command button.
The user will search for any string and it will show all the accounts where the name contains the searched string.
I observed that if I keep rerender on commandbutton to either the results table("results_pb") or to the pageblock("no_recs") nothing is rendered in the VF page.
But if I remove them, the result records are shown as expected.
Can someone let me know why would no records be displayed if we "rerender" the pageblock or the data table after clicking the command button ?