Prady
Prady

Reputation: 11320

How can provide link to a record from visualforce page using outputlink

Could anyone help me out on providing link in this scenario

<apex:repeat var="slot" value="{!liTimeSlots}">

<tr class="{!IF(ISNULL(slot.sAppointment), 'Free', 'Fill')}">
    <td ><apex:outputText value="{!slot.tstart1}"/></td>

      <td><apex:outputText value="{!IF(ISNULL(slot.sAppointment), 'Free', slot.sAppointment.name)}"/></td>
      <td><apex:outputText value="{!IF(ISNULL(slot.sAppointment), '', slot.sAppointment.Appointment_Type__c)}"/></td>
      <td><apex:outputText value="{!IF(ISNULL(slot.sAppointment), '', slot.sAppointment.Patient__c)}"/></td>
        </tr> 
    <tr >
    <td></td>

      <td><apex:outputText value="{!IF(ISNULL(slot.sAppointmentOverlap), ' ', slot.sAppointmentOverlap.name)}"/></td>
      <td><apex:outputText value="{!IF(ISNULL(slot.sAppointmentOverlap), '', slot.sAppointmentOverlap.Appointment_Type__c)}"/></td>
      <td><apex:outputText value="{!IF(ISNULL(slot.sAppointmentOverlap), '', slot.sAppointmentOverlap.Patient__c)}"/></td>
        </tr>   
 </apex:repeat>

I want to show the link only if slot.sAppointment or slot.sAppointmentOverlap is not null.

Any idea how to approach this.

Thanks

Prady

Upvotes: 0

Views: 2141

Answers (1)

Matt Lacey
Matt Lacey

Reputation: 8255

Like pretty much all of the apex: Visualforce tags, apex:outputLink has a rendered attribute which can be used to show or hide it, and this can use a merge field / formula for the value, so you'll be looking for something along the lines of:

<apex:outputLink value="url" rendered="{!NOT(ISNULL(slot.sAppointment)) || NOT(ISNULL(slow.AppointmentOverlap))}">The link</a>

Another trick I use for conditional rendering for a group of markup elements is to wrap them in an apex:variable tag:

<apex:variable var="v" value="" rendered="{!ShouldThisRender}">
   <!-- Some page elements -->
</apex:outputVariable>

Upvotes: 4

Related Questions