Dev401-026:Visualforce Pages: Visualforce Controller
 

Module Objectives
1.Identify the functionality that comes with each standard controller
2.Realize when you would need to move to Apex for creating custom controllers or extensions.
3.Compare and contrast controllers and extensions.

Module Agenda
1.Controller Overview
2.Standard Controllers
3.Custom Controllers
4.Controller Extensions

Visualforce Controllers
1.A Visualforce controller is an Apex class that specifies the data available and the behavior when a user interacts with components on a page.
2.Standard Controllers
- Are provided for all API entities/objects,such as Account,Contact,Opportunity,etc.,as well as custom objects.
- Provide access to standard Salesforce data and behavior.
- Are available to work with record lists.
- Are invlked by using:<apex:page standardController="Contact">

What are Custom Controllers and Controller Extensions?
1.A custom controller is an Apex class that implements all of the logic for a page without leveraging a standard controller. Use custom controllers when you want your Visualforce page to run entirely in system mode, which does not enforce the permissions and field-level security of the current user.
2.A controller extension is an Apex class that extends the functionality of a standard or custom controller. Use controller extensions when:
You want to leverage the built-in functionality of a standard controller but override one or more actions, such as edit, view, save, or delete.
You want to add new actions.
3.You want to build a Visualforce page that respects user permissions. Although a controller extension class executes in system mode, if a controller extension extends a standard controller, the logic from the standard controller does not execute in system mode. Instead, it executes in user mode, in which permissions, field-level security, and sharing rules of the current user apply.

Standard Controllers
1.Standard controllers provide the same common data and functionality and logic used for standard Salesforce pages.
- All standard and custom objects that can be queried using the API have a standard controller.
2.Standard controllers are associated on Visualforce pages using:
- <apex: page standardController="Object">

Standard Controllers
1.Standard controllers include a getter method to return the record specified by the id query string parameter(on the URL).
- This allows the page to access data using the {!object} merge field syntax.
- THis also allows developers to test using URL parameters with known IDs.

Standard Controllers
1.As with API queries, you cna use merge field expression syntax to retrievee data from related records:
- You can traverse up five lvels of child-to-parent relationships.
.Example:{!contact.Account.Owner.FirstName}
-You can traverse down one level of parent-to-child relationships to return an array of all child rows for that parent.
.Example:{!account.Contacts}

Standard Controllers
1.Action methods perform logic or navigation when a page event occurs.
- Action methods are invoked using the {!actionmethod} syntax.
2.Standard controllers define the following actionmethods:
- save ()
- quicksave ()
- edit ()
- delete ()
- cancel ()

Standard List Controllers
1.For almost every standard controller there existent standard list controller that allows you to create pages that display and act on a set of records, such as list page,related list,and mass action pages.
2.To select the standard list controller instead of the regular standard controller,use the recordSetVar attribute on the page tag.
- <apex;page standardController="Account" recordSetVar="accounts">
- This also creates a variable that represents the record set for the page.

Pagination with a List Controller
1.You can add pagination to a page using a list controller by utilizing the next and previous actions. For example, if you create a page with the following markup:

<apex:page standardController="Account" recordSetvar="accounts">
  <apex:pageBlock title="Viewing Accounts">
  <apex:form id="theForm">
    <apex:pageBlockSection >
      <apex:dataList var="a" value="{!accounts}" type="1">
        {!a.name}
      </apex:dataList>
    </apex:pageBlockSection>
    <apex:panelGrid columns="2">
      <apex:commandLink action="{!previous}">Previous</apex:commandlink>
      <apex:commandLink action="{!next}">Next</apex:commandlink>
    </apex:panelGrid>
  </apex:form> 
  </apex:pageBlock>
</apex:page>

Custom Controllers
1.A custom controller is an Apex class that implement all of the logic for a page without leveraging a standard controller.
- Custom controllers typically define three different types of methods:
.Getter methods to retrieve data from the controller.
.Setter methods to pass data from the page to the controller.
.Action Methods to perform logic.
- Navigation action methods to take the usersomewhere else.
- Custom controllers mustexplicitly define all action methods, including those found in standard controllers.

Custom Controllers:Getter Methods
1.Getter methods provide ways to return object data in a Visualforce page.
2.Getter methods take the form:getDataname() which uses the name of the data retrueved.
3.In a Visualforce page, the data can be accessed using the {!Dataname} merge field syntax.

Setter Methods
1.Setter methods pass user-specified values from page markup to a controller. Any setter methods in a controller are automatically executed before any action methods.
2.For example, the following markup displays a page that implements basic search functionality for Leads. The associated controller includes getter and setter methods for the search box input, and then uses the search text to issue a SOSL query when the user clicks Go!. Although the markup doesn’t explicitly call the search text setter method, it executes before the doSearch action method when a user clicks the command button:
<apex:page controller="theController">
   <apex:form>
      <apex:pageBlock mode="edit" id="block">
         <apex:pageBlockSection>
            <apex:pageBlockSectionItem>
               <apex:outputLabel for="searchText">Search Text</apex:outputLabel>
               <apex:panelGroup>
                  <apex:inputText id="searchText" value="{!searchText}"/>
                  <apex:commandButton value="Go!" action="{!doSearch}" 
                                      rerender="block" status="status"/>
               </apex:panelGroup>
            </apex:pageBlockSectionItem>
        </apex:pageBlockSection>
        <apex:actionStatus id="status" startText="requesting..."/>
        <apex:pageBlockSection title="Results" id="results" columns="1">
           <apex:pageBlockTable value="{!results}" var="l" 
                               rendered="{!NOT(ISNULL(results))}">
              <apex:column value="{!l.name}"/>
              <apex:column value="{!l.email}"/>
              <apex:column value="{!l.phone}"/>
           </apex:pageBlockTable>
        </apex:pageBlockSection>
      </apex:pageBlock>
   </apex:form>
</apex:page>

Action Methods
1.Action methods perform logic or navigation when a page event occurs, such as when a user clicks a button, or hovers over an area of the page. Action methods can be called from page markup by using {! } notation in the action parameter of one of 
the following tags:
- <apex:commandButton> creates a button that calls an action
- <apex:commandLink> creates a link that calls an action
- <apex:actionPoller> periodically calls an action
- <apex:actionSupport> makes an event (such as “onclick”, “onmouseover”, and so on) on another, named component, call an action
-<apex:actionFunction> defines a new JavaScript function that calls an action
-<apex:page> calls an action when the page is loaded
2. For example, in the sample page in Building a Custom Controller, the controller's save method is called by the action parameter of the <apex:commandButton> tag. Other examples of action methods are discussed in Defining Action Methods.

Exercise 5-1:Creating a Visualforce Page with a Custom Controller
1.Goal(s):
- Create a Visualforce page to accompany a custom controller
2.Scenario:
- Universal Containers wants to start learning more about controllers,and at the same time create a special search page for candidate information that allows you to search for a candidate by first name,last name,or email all at he same time.
3.Tasks:
- Add the pre-existing Visualforce page to your org.
- Add the controller class.
- Test the page by searching for candidates.

Building Applications with Force.com and VisualForce (DEV401) (二五):Visualforce Controller的更多相关文章

  1. Building Applications with Force.com and VisualForce(Dev401)(十八):Visualforce Pages: Introduction to Visualforce

    Dev401-020:Visualforce Pages: Introduction to Visualforce Course Objectives1.Understand the benefits ...

  2. Building Applications with Force.com and VisualForce (DEV401) (二四):JavaScript in Visualforce

    Dev401-025:Visualforce Pages: JavaScript in Visualforce Module Objectives1.Describe the use of AJAX ...

  3. Building Applications with Force.com and VisualForce(Dev401)(十):Designing Applications for Multiple Users: Building Business Processes that You Want

    Dev401-011: Building Business Processes that You Want Course Objectives1.Describe the capabilities o ...

  4. Building Applications with Force.com and VisualForce (DEV401) (四):Building Your user Interface

    Dev 401-004:Application essential:Building Your user Interface: Module Agenda1.Custom Applications2. ...

  5. Building Applications with Force.com and VisualForce (DEV401) (三):Application Essential:Building Your Data Model

    Dev 401-003:Application Essential:Building Your Data Model Object Relationships1.Link two objects- P ...

  6. Building Applications with Force.com and VisualForce (DEV401) (二) : Application Essentials:Designing Application on the Force.com Platform

    Dev 401-002:Application Essentials:Designing Application on the Force.com Platform Course Objectives ...

  7. Building Applications with Force.com and VisualForce(Dev401)(七):Designing Applications for Multiple users:Managing your users' experience I

    Dev 401-007 Designing Applications for Multiple users: Managing your users' experience part 1 Module ...

  8. Building Applications with Force.com and VisualForce (DEV401) (二一):Visualforce Componets (Tags) Library Part 1

    Dev401-022:Visualforce Pages: Visualforce Componets (Tags) Library Part 1 Module Objectives1.List ke ...

  9. Building Applications with Force.com and VisualForce (DEV401) (二三):Visualforce Componets (Tags) Library Part III

    Dev401-024:Visualforce Pages: Visualforce Componets (Tags) Library Part IIIStatic Resources1.Static ...

随机推荐

  1. Docker+Cmd+Cli+Git之前端工程化纪要(一)整体目标

    之前一版的工程化核心产物就是一个IDE,即利用python+node将webpack等技术将FE的开发.编译.部署上线等环境集成在sublime中,产出了一个核心工具.但随着长期的使用与技术栈的优化升 ...

  2. 一天速成Python教程

    一.Python基础 Python是对象有类型,变量无类型的动态类型语言,追求简单优雅易读.可以在终端中逐行运行,也可以编写成大型的面向对象的工程.在开始写之前,注意Python 2.X中,开头要写上 ...

  3. C++走向远洋——59(项目三、图形面积、抽象类)

    */ * Copyright (c) 2016,烟台大学计算机与控制工程学院 * All rights reserved. * 文件名:text.cpp * 作者:常轩 * 微信公众号:Worldhe ...

  4. WebGIS 利用 WebGL 在 MapboxGL 上渲染 DEM 三维空间数据

    毕业两年,一直在地图相关的公司工作,虽然不是 GIS 出身,但是也对地图有些耳濡目染:最近在看 WebGl 的东西,就拿 MapboxGL 做了一个关于 WebGL 的三维数据渲染的 DEMO 练手. ...

  5. 峰哥说技术:04-Spring Boot基本配置

    Spring Boot深度课程系列 峰哥说技术—2020庚子年重磅推出.战胜病毒.我们在行动 04 Spring Boot基本配置 1)容器的相关配置 在Spring Boot中可以内置Tomcat. ...

  6. 基于Unix Socket的可靠Node.js HTTP代理实现(支持WebSocket协议)

    实现代理服务,最常见的便是代理服务器代理相应的协议体请求源站,并将响应从源站转发给客户端.而在本文的场景中,代理服务及源服务采用相同技术栈(Node.js),源服务是由代理服务fork出的业务服务(如 ...

  7. python装饰器见解笔记

    def zsq(fun): def zsq_n(*args,**kwargs) print('这是装饰器需要运行内容') r = fun(*args,**kwargs) print('在被装饰函数执行 ...

  8. ApplicationContextInitializer的理解和使用

    一.ApplicationContextInitializer 介绍 1.1 作用 ApplicationContextInitializer 接口用于在 Spring 容器刷新之前执行的一个回调函数 ...

  9. 初学react

    React特点: 声明式设计:建议使用JSX来描述用户界面;构建组件:单向响应的数据流: JSX:JSX是一种JAVASCRIPT的语法扩展,元素是构成react的最小单位,JSX就是用来声明REAC ...

  10. 题解 NOIP2018【赛道修建】—— 洛谷

    这道题有一点点树上dp的意思(大佬轻喷 我刚拿到这道题的时候毫无头绪,只知道这道题要二分答案 为什么是二分答案??? 题目: 目前赛道修建的方案尚未确定.你的任务是设计一 种赛道修建的方案,使得修建的 ...