Cloud computing has made significant changes to the IT/software development industry. Cloud platforms are one of the important directions of cloud computing. Cloud platforms allow the developers to develop apps and run them on the Cloud, including platforms for building on-demand applications and platforms as services (PaaS). Salesforce.com has introduced the first on-demand platform called Force.com.
This chapter will introduce you to Visualforce. We will go through the MVC architecture and Visualforce. Furthermore, we will look at the architecture of Visualforce pages. We will define the advantages of Visualforce pages and will get an idea about Visualforce development tools.
This chapter covers the following topics:
The MVC model
Advantages of Visualforce
Visualforce development tools
So let's get started and step into Visualforce.
Controller: This defines the business logic. The rules and actions which manipulate the data controls the view. In Force.com, Apex classes, triggers, workflows, approvals, and validation rules are under this category.
In the Force.com platform, we can develop Force.com applications with custom objects and standard objects. Every object has a standard user interface with one or more page layouts. But we cannot use standard page layouts for sophisticated requirements. Here, Visualforce comes into play.
A Visualforce page has two major elements called Visualforce markup and Visualforce controller. Visualforce markup consists of Visualforce tags with the prefix
After creating the page, we can access the page by using the same URL. The Visualforce markup has a special set of components which is similar to the tag library system of other markups. These components allow us to create complicated components with a single tag. These components are processed and rendered on servers and finally delivered to the client. This methodology has higher performance and enriched functionality when compared to the client-only methods. A Visualforce page runs on the platform shown in following diagram:
The preceding digram illustrates that every time a developer saves a Visualforce page on a platform, the platform compiles the markup and related controllers. On successful compilation, markup is converted into an abstract set of instructions that can be understood by the Visualforce renderer. If there are any compilation errors, then it stops saving the page and returns the errors to the developer. If the saving attempt successfully finished, then the instructions are saved to the metadata repository and sent to the Visualforce renderer. The renderer converts the instructions into HTML, which can be understood by the browsers, and then refreshes the page as shown in the following diagram:
The preceding diagram illustrates that when a non-developer user requests a Visualforce page, the application server retrieves the page from the metadata repository and then sends to the Visualforce renderer for HTML conversion. There is no compilation because the page has already been compiled into instructions during its development.
Model-View-Controller development style: Visualforce adheres to the MVC pattern by providing the View of the application in the Force.com platform. A View is defined by user interfaces and Visualforce markup. The Visualforce controller which can be associated with Visualforce markup takes care of the business logic. Therefore, the designer and the developer can work separately, while the designer focuses on user interface and the developer focuses on business logic.
User-friendly development: A developer (with an administrator profile) user can have a Visualforce editor pane at the bottom of every Visualforce page. This editor pane is controlled by the Development Mode option of the user record. This feature allows us to edit and see the resulting page at the same time and in the same window. This Visualforce editor has the code-saving feature with auto compilation and syntax highlighting.
A broad set of ready-to-serve Visualforce components: Visualforce has a set of standard components in several categories. There are output components, for example,
<apex:pageBlock>,and so on. There are input components, for example,
<apex:selectList>, and so on. These input and output components have a feature called data-driven defaults. For an example, when we specify the
<apex:inputField>component in a particular Visualforce page, the
<apex:inputField>tag provides the edit interface for that field with data-type-related widgets (for example, the Date field has the calendar, and the e-mail/phone fields have their particular validations). There are also AJAX components, for example,
<apex:actionStatus>. AJAX components allow the user to enhance the level of interactivity for a particular interface.
Tightly integrated with Salesforce / Extends with custom components: A Visualforce page can have a custom controller as well as a standard controller. A standard controller is created while creating the object and can be used for the Visualforce controller. A standard controller has the same logic and functionality which is used in standard pages. Visualforce pages adhere to these standardized methods and functionality. And we can also extend the standard components with custom components. For example, we can use an extension class for extending the standard controller of a particular Visualforce page. We can create our own Visualforce custom components instead of Visualforce in-built components for example,
<apex:outputField>, and so on. In the next two chapters we will discuss more about Visualforce controllers and Visualforce custom components.
But, that's not the best way to develop Visualforce pages. There are a few other ways to build Visualforce pages, which are as follows:
The Eclipse plugin for Force.com: This is same as the Force.com IDE, we can use it to create and edit Visualforce pages, custom Visualforce components, static resources, and controllers are some of the major features of the Force.com IDE.