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
ArjunmcaArjunmca 

HTML If condition in visualforce page

Hi,

 

I need to display  text  'No Records' or  put a button on visualforce page.

 

VF Page:

--------------

<apex:page controller="TestController">

 

<table border="0" width="100%" height="20">
  <tr>

     if({!count}<0)

         <h3> No Records</h3>

     else

     {

       <td>
         <input id="callintent_button" type="button" align="left" value = "More >>" onclick="enablerestoreCallIntent();"/>
        </td>

     }

  </tr>
</table>

</apex:page>

 

Controller:

---------------

 

public class TestController

{

   public integer count;

 

   public integer getCount()

   {

      return count;

   }

 

   public void setCount(integer value)

   {

        this.count=value;

   }

 

}

 

 

Should i use any apex command to check the condition. How can i do that. 

 

Thanks.

ryanjuptonryanjupton

A bit hackish but you could try

 

<apex:page controller="ConditionalController" >
    <table border="0" width="100%" height="20">
      <tr>
        <td>{!IF (count <= 0,'No Records', '')}</td>
      </tr>
      <apex:outputPanel rendered="{!count > 0}">
    	<tr>
            <td><input id="callintent_button" type="button" align="left" value = "More >>" onclick="enablerestoreCallIntent();"/></td>
        </tr>
       </apex:outputPanel>
    </table>
</apex:page>

 

ryanjuptonryanjupton

You could also replace if with another outpanel that renders based on the value of count. I just wanted to show an example of using an if :)

ArjunmcaArjunmca

Thanks for quick reply?

 

I am getting below errors in this line   '<td>{!IF (count <= 0,'No Records', '')}</td>'

 

Create Apex property 'RCPRequestDecisionV2.CallIntentDisplayNonTopSize'
Create Apex method 'RCPRequestDecisionV2.getCallIntentDisplayNonTopSize'

 

 

 

  

 

 

Neha LundNeha Lund

--------------

Just try this one !

<apex:page controller="TestController">

 

<table border="0" width="100%" height="20">
  <tr>

<apex:outputPanel rendered="{!If(count<0,true,false)}">

         <h3> No Records</h3>

</apex:outputPanel>

           <td>
<apeX:outputPanel rendered="{!If(count>0,true,false)}">   

     <input id="callintent_button" type="button" align="left" value = "More >>" onclick="enablerestoreCallIntent();"/>

</apex:outputPanel>


        </td>

     }

  </tr>
</table>

</apex:page>

Avidev9Avidev9

Create Apex property 'RCPRequestDecisionV2.CallIntentDisplayNonTopSize'
Create Apex method 'RCPRequestDecisionV2.getCallIntentDisplayNonTopSize'

 

These are not related to count I guess and should is originating from somewhere else

ryanjuptonryanjupton

I think you didn't post all your code. Please post what you have in the controller and page so we can see specifically where the error is.

ryanjuptonryanjupton

The if statements in the rendered attribute are over kill. You just need rendered="{! count > 0}

QuinnCushingQuinnCushing
I am not well versed in this (at all) so I'm sure it is not the best way to do this, but it worked (finally). I could not get the above suggestions to work.  I did not want to change my controller, so stuck the code in the page itself: (Warrants is a list from the controller called from the page).

<apex:outputPanel rendered="{false}" >
public Integer listSize{get {
if(Warrants != null)
  return Warrants.size();
else
  return 0;}}
</apex:outputPanel>

Then I was able to use warrants.size in either if or outputPanel as noted in earlier posts above. I mostly used outputPanel to show or hide sections of a Visualforce page rendered as a pdf.

<apex:outputPanel rendered="{!Warrants.size>0}">
      stuff to show if there are any records in Warrants list, else don't show
</apex:outputPanel>