You need to sign in to do that
Don't have an account?

Render if controller does not return any records
I have a simple standard list controller :
<apex:page standardController="Order_Line__c" sidebar="True" showHeader="True"recordSetVar="orderlines">
<apex:form >
<apex:pageBlock >
<apex:pageMessages />
<apex:pageBlockSection title="Inventory details for selected Products">
<apex:pageBlockTable value="{!selected}" var="j" border="1">
<apex:column value="{!j.prod__c}" />
<apex:column value="{!j.Product__r.Available__c}"/>
<apex:column value="{!j.Product__r.Back_Order_Quantity__c}"/>
<</apex:pageBlockTable>
</apex:pageblockSection>
<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Back" action="{!cancel}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
It works fine ,But when there are no records passed to the controller i want it to display a message and render the page.
I tried modifying the code for this as below with the highlighted changes.
But now even if records are returned from the controller, it just displays the output message"Please select a order line".
Please help me.
The modified controller:
<apex:page standardController="Order_Line__c" sidebar="True" showHeader="True"
recordSetVar="orderlines">
<style>
.FontSize {
font-size:20px;
}
</style>
<apex:outputText value="Please select a order line" rendered="{!LEN(Order_Line__c.Id)==0}"/>
<apex:form rendered="{!LEN(Order_Line__c.Id)>0}">
<apex:pageBlock >
<apex:pageMessages />
<apex:pageBlockSection title="Inventory details for selected Products">
<apex:pageBlockTable value="{!selected}" var="j" border="1">
<tr>
<td><apex:column value="{!j.prod__c}" style="white-space:nowrap ;font-weight:bold"/></td>
</tr>
<apex:column />
<apex:column value="{!j.Product__r.Available__c}"/>
<apex:column />
<apex:column value="{!j.Product__r.Back_Order_Quantity__c}"/>
<apex:column />
<apex:column value="{!j.Product__r.Reserve__c}"/>
<apex:column />
<apex:column value="{!j.Product__r.On_Hand_Quantity__c}"/>
<apex:column />
</apex:pageBlockTable>
</apex:pageblockSection>
<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Back" action="{!cancel}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
Personally, I would go with rendered="{!Order_Line__c == null}"/> instead of using LEN and use != for the other condition
Nope,this is not working...
how about:
rendered="{!ResultSize != 0)"
The StandardSetController class has a 'getResultSize()' method that return the number of records in the set. Best, Steve.
Hi Steve,
I modified this to:
<apex:form rendered="{!ResultSize!= 0}">
How do i display an error message if no records are returned?
Why dont you have a pagemessage that contains your error that is only rendered if ResultSize== 0?
If you want something that looks like a standard caught exception, use:
Check out the docs for descriptions of the strength and severity fields
Something like:
<apex:form rendered="{!ResultSize != 0}">
... stuff...
</apex:form>
<apex:outputPanel rendered="{!ResultSize == 0)">
There were no records selected.
</apex:outputPanel>
Either way, once you know how to use the rendered property properly, you can essentially build anything you want.
Best, Steve.