salesforce extendsion and standart component 继承和标准组件的使用
2013-12-20 11:16
141 查看
//apex class 类 public without sharing class BMS_CN_Speaker_Query {//public without sharing 是这个类的访问限制条件。该类主要是实现查询 是对account类的扩展 public Account account {get;set;}//在官方文档中 是定义为final类型的 public list<Account> searchresult{get;set;}//如果想从页面上拿到这个数值,必须 getset // Constructor public BMS_CN_Speaker_Query(ApexPages.StandardController stdController) {//因为这个类继承了Account,所以用着中写法,这个是固定写法 this.account = (Account)stdController.getRecord();//拿到account对象。可以通过这个变量接收页面中传递过来的数值。 } public PageReference search(){ //页面跳转的的一个方法。当返回值为空的时候 ,就不跳转。具体放在参看,稍后的其他文章 string namestr = account.Name; string hospitalstr = account.Account_Group_vod__c;//医院接收不到数值。所以选择一个text类型的替代 if(namestr != null){ namestr ='%'+namestr+'%'; }else namestr = '%%'; if(hospitalstr != null){ hospitalstr ='%'+hospitalstr+'%'; }else hospitalstr = '%%'; this.searchresult = [SELECT Id,Department_BMS_CN__c, Name, Phone,Primary_Parent_vod__r.Name ,CreatedDate ,Speaker__c FROM Account where Department_BMS_CN__c = :account.Department_BMS_CN__c and Name like :namestr and Primary_Parent_vod__r.Name like :hospitalstr and IsActive_BMS_CN__c = true AND RecordTypeId IN (SELECT Id FROM RecordType WHERE SobjectType = 'Account' AND Name = 'BMS - Individual') ];//查询语句。返回一个list给成员变量赋值。 system.debug('####'+searchresult .size()+'#####'+hospitalstr ); // Search result if(searchresult.size() == 0) { ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, '查无结果'));//提示框,在页面中必须通过 一个<apex:pageMessages /> } return null; } }
<apex:page standardController="Account" extensions="BMS_CN_Speaker_Query" standardStylesheets="true"> <apex:form > <apex:pageBlock mode="edit" id="block" title="Speaker Query"> <apex:pageMessages /> <apex:pageBlockSection title="检索条件" columns="1" > <apex:pageBlockSectionItem > <apex:outputLabel value="医生"></apex:outputLabel> <apex:panelGroup > <apex:inputField value="{! Account.Name}" required="true"/> </apex:panelGroup> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel >科室</apex:outputLabel> <apex:panelGroup > <apex:inputField value="{! Account.Department_BMS_CN__c}" required="false" /> </apex:panelGroup> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel >医院</apex:outputLabel> <apex:panelGroup > <apex:inputField value="{! Account.Account_Group_vod__c}" required="false" /> <apex:commandButton value="查找" action="{! search}" rerender="block" status="status" /> </apex:panelGroup> </apex:pageBlockSectionItem> </apex:pageBlockSection> <apex:actionStatus id="status" startText="查找中..."/> <apex:pageBlockSection title="检索结果" id="resultsBlock" columns="1" rendered="{! NOT(ISNULL(searchresult)) && NOT(searchresult.size == 0) }"> <apex:pageBlockTable value="{! searchresult }" var="act" > <apex:column value="{! act.Name}" headerValue="医生"/> <apex:column value="{! act.Department_BMS_CN__c}" headerValue="科室"/> <apex:column value="{! act.Primary_Parent_vod__r.Name}" headerValue="医院"/> <apex:column > <apex:facet name="header">是否讲者?</apex:facet> <apex:outputText value="{! act.Speaker__c}"/> </apex:column> <apex:column value="{! act.CreatedDate}" headerValue="创建时间"/> </apex:pageBlockTable> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
通过使用标准组件和extendsion,省去了接收数据的过程。在页面上在form表单中红输入内容,数据自动就保存到account对象中去了。后面接数据的时候,直接去相应的属性中拿值就好了。
<apex:actionStatus id="status" startText="查找中..."/> <apex:commandButton value="查找" action="{! search}" rerender="block" status="status" />
单击‘查找’之后,会在页面中显示‘查找中。。。’的字样。 注意actionStatus 中的id和Button中的status的值一样。
在标准的控件中,如果你的数据类型是checkbox,在页面上渲染的时候 自动就是checkbox的形式。如果你想要显示成 true或者false,只好这样写了
<apex:column > <apex:facet name="header">是否讲者?</apex:facet> <apex:outputText value="{! act.Speaker__c}"/> </apex:column>
另外,
<apex:inputField value="{! Account.Department_BMS_CN__c}" required="false" />这句代码只能用在standardcontroller中, required = true 是说 必填。false就是可选的了
相关文章推荐
- salesforce linghtning component 自动添加标准style css样式
- 在Salesforce标准页面上使用Url传参 - Using URL parameters on Salesforce standard pages
- 在Salesforce中使用Javascript调用Apex方法 - Salesforce RemoteAction and webService
- Spring2.5中使用注解装配属性and组件自动扫描
- Salesforce Lightning 组件间的交互
- spring组件扫描<context:component-scan/>使用详解
- 在React中使用extends React.Component定义的组件
- 使用Django Component 系列2 :翻页组件
- spring组件扫描<context:component-scan/>使用详解
- Silverlight入门教程(五): 使用ListBox and DataBinding 组件显示列表数据-教程资料网 www.zhiweinet.com
- ExtJs4组件中initComponent方法介绍以及为什么要使用this.callParent();
- spring组件扫描<context:component-scan/>使用详解
- .Net服务组件(ServicedComponent)简介及其使用
- Dagger2 使用继承方式,简化Component获取
- salesforce中使用标准和自定义组件多种方式实现helpText(tip tool)效果 - 合集/配图
- 使用ComponentArt.WebUI.for.Asp.net.3.0的TreeView控件实现数据驱动的无限级分类管理[图文教程]
- spring组件扫描<context:component-scan/>使用详解
- spring组件扫描<context:component-scan/>使用详解
- android使用ComponentName组件简单示例
- spring组件扫描<context:component-scan/>使用详解