stratoflow

Useful Visualforce attributes

Today we are going to do something slightly different. Instead of me focusing on one particular problem, I will share with you some handy Visualforce attributes that might be helpful in your future projects. They might seem fairly similar to each other because they share common main core but they are used in various different situations.

Rendered

Using this attribute you can hide or display Visualforce component.

Rendered attribute always takes a boolean variable from the controller which decides whether component is displayed or not.

If boolean variable is false then component isn’t displayed and the opposite if it’s true.

In the following example, if “isLink” value is false, there will value displayed in apex:outputText, but if “isLink” is true then we will get apex:outputLink value displayed straight on the page.

Building a Salesforce application or extending your development team?

🚀 We're here to assist you in accelerating and scaling your business. Send us your inquiry, and we'll schedule a free estimation call.

Estimate your project
<apex:outputText rendered="{!isLink == false}
"value="{!$Label.Community_DoesntHaveTrackAndTraceLink}"/>

<apex:outputLink rendered="{!isLink == true}" value="{!trackAndTrace}"/>

reRender

Using this attribute you can refresh a particular section of the page.

You just need to add to attribute an id of visualforce component, which is also a container, and its boundaries are going to be sections that you want to refresh.

In the next example If you click on this command button, the section that is inside apex:pageBlock with id attribute equal “ThePage” will be refreshed.

Of course, the refreshed operation will come after the action which this button defines.

<apex:pageBlock id="ThePage">

<!-- Functionality -->

</apex:pageBlock>
<apex:commandButton
value="{!$Label.Community_previous}"
action="{!previous}" rendered="{!hasPrevious}" reRender="ThePage"/>

renderAs 

This attribute specify in what format certain page should be displayed.

Example below shows page that is going to be displayed in PDF format.

<apex:page standardController="Account" renderAs="pdf">
<apex:pageBlock >
<apex:pageBlocSection>
<apex:outputField value="{!Account.name}"/>
<apex:outputField value="{!Account.AccountNumber}"/>
</apex:pageBlocSection>
</apex:pageBlock>
</apex:page>

As you can see today’s format slightly differs from what I usually post on this blog.

I hope that you’ve still enjoyed this brief tutorial on these seemingly similar Visualforce attributes and that you will find a use for them in your personal work.

Good luck!

Building a Salesforce application or extending your development team?

🚀 We're here to assist you in accelerating and scaling your business. Send us your inquiry, and we'll schedule a free estimation call.

Estimate your project

Testimonials

They have a very good company culture of their own, which gives them a real edge compared to other providers.

CEO

Leading UK system integrator

They're very skilled technically and are also able to see the bigger picture.

Managing Partner

Scalable SaaS for healthcare IoT built on Salesforce platform

They've been consistently able to deliver work on time and within budget.

CTO

High performance SaaS for financial insitutions

We are seriously impressed by the quality and broader picture of anything they do for us.

CEO

Gold trading platform