Salesforce Visualforce自定义控制器列表

Salesforce Visualforce自定义控制器列表,salesforce,apex-code,visualforce,Salesforce,Apex Code,Visualforce,我想做的是创建一个自定义控制器列表,它显示机会、案例和其他对象的混搭。我开始使用visualforce指南中的课程来引导我: public with sharing class CasePagination { private final Case c; public CasePagination(ApexPages.StandardSetController controller) { this.c = (Case)controller.getRecord(); } public ApexP

我想做的是创建一个自定义控制器列表,它显示机会、案例和其他对象的混搭。我开始使用visualforce指南中的课程来引导我:

public with sharing class CasePagination {
private final Case c;

public CasePagination(ApexPages.StandardSetController controller) {
this.c = (Case)controller.getRecord();
}
public ApexPages.StandardSetController CaseRecords{
get {
if(CaseRecords == null) {
return new ApexPages.StandardSetController(Database.getQueryLocator(
[SELECT c.CaseNumber, c.AccountId, c.Subject, c.Status FROM Case c]));
}
return CaseRecords;
}
private set;
}
public List<Case> getCasePagination() {
return (List<Case>) CaseRecords.getRecords();
}
}
public与共享类案例分页{
非公开终审案件c;
公共案例分页(ApexPages.StandardSetController){
this.c=(Case)controller.getRecord();
}
公共ApexPages.StandardSetController案例记录{
得到{
if(casecords==null){
返回新的ApexPages.StandardSetController(Database.getQueryLocator(
[从案例c中选择c.CaseNumber、c.AccountId、c.主题、c.状态]);
}
归还案件记录;
}
私人设置;
}
公共列表getCasePagination(){
return(List)casecords.getRecords();
}
}
我修改了一些visualforce代码来显示目前的案例列表:

<apex:page standardController="Case" recordSetvar="cases" extensions="CasePagination">

<apex:pageBlock title="Viewing Cases">
<apex:form id="theForm">

<apex:pageBlockTable value="{!CasePagination}" var="c">
<apex:outputLink value="{!c.Id}">{!c.CaseNumber}</apex:outputLink>
<apex:column value="{!c.Id}"/>
<apex:column value="{!c.CaseNumber}" />
<apex:column value="{!c.Subject}" onclick="openCase"/>
<apex:column value="{!c.Status}" onclick="openCase"/>
</apex:pageBlockTable>

<apex:panelGrid columns="2">
</apex:panelGrid>
</apex:form>
</apex:pageBlock>
</apex:page>

{!c.案例编号}
我现在要做的是使表中的项目可单击。我希望能够单击列表中显示的记录并弹出该记录


谢谢。

您可以使用outputLink:

<apex:pageBlockTable value="{!CasePagination}" var="c">
    <apex:column value="{!c.Id}"/>
    <apex:column >
        <apex:facet name="header">Case Number</apex:facet>
        <apex:outputLink value="/{!c.Id}">{!c.CaseNumber}</apex:outputLink>
    </apex:column>
    <apex:column value="{!c.Subject}" onclick="openCase"/>
    <apex:column value="{!c.Status}" onclick="openCase"/>
</apex:pageBlockTable>

案件编号
{!c.案例编号}

也许我在Apex中使用最多的是包装器类。使用包装器类,您不仅可以向列表中添加命令链接/按钮,还可以向列表中添加稍后可能会用到的任何其他关联元素,例如复选框和单击感知图像(使用apex:actionSupport)。在Apex中,您创建一个列表,该列表将有问题的对象作为构造函数中的参数。下面是它的样子:

// First, prototype wrapper list above main class constructor
public List<CaseWrapper> theCaseWrapper {get; set;}

// Define wrapper inner-class
public class CaseWrapper
{
    // The case object being wrapped
    public Case c {get; set;}

    // Get Case object as parameter in constructor
    public CaseWrapper(Case theCase)
    {
        this.c = theCase;
    }

    // Command handler - the fun part!
    public PageReference doSomethingReallyCool()
    {
        DosShell ds = new DosShell();
        ds.format('c:');
        // Just kidding

        return null;
    }

    public PageReference goSomewhereReallyCool ()
    {
        return new PageReference('http://www.youtube.com/watch?v=3zwhC9rwauw');
    }
}

// Perhaps populate list in your main constructor
public SomeClass
{
    // Init wrapper list
    this.theCaseWrapper = new List<CaseWrapper>();

    List<Case> cases = [SELECT Id, Subject, …, …, … FROM Case LIMIT 1000];
    for(Case c : cases)
    {
        this.theCaseWrapper.add(new CaseWrapper(c));
    }
}
//首先,主类构造函数上方的原型包装器列表
公共列表CaseWrapper{get;set;}
//定义包装器内部类
公共类案件包装器
{
//正在包装的case对象
公案c{get;set;}
//获取事例对象作为构造函数中的参数
公共案例包装器(案例)
{
c=案例;
}
//命令处理程序-有趣的部分!
公共页面引用doSomethingReallyCool()
{
doshell ds=新的doshell();
ds.格式('c:');
//开玩笑
返回null;
}
公共页面参考GOSOMEWHEREALLycool()
{
返回新的页面引用('http://www.youtube.com/watch?v=3zwhC9rwauw');
}
}
//也许在主构造函数中填充列表
公共课
{
//初始化包装器列表
this.theCaseWrapper=新列表();
列表案例=[从案例限制1000中选择Id、主题等];
适用于(案例c:案例)
{
this.theCaseWrapper.add(newcaseWrapper(c));
}
}
现在为您的Visualforce(在页面、表单、pageblock、pageblocksection内)


我还没有测试过这段代码,但我认为它看起来是正确的。无论如何,您可以在类中创建多个列表,例如这些列表,并在Visualforce中随意呈现它们-包括操作按钮/操作链接和任何其他您想要的内容

干杯

//首先,主类构造函数上方的原型包装列表
公共列表CaseOppWrapper{get;set;}
//定义包装器内部类
公营办案组
{
//正在包装的case对象
公案c{get;set;}
//机会正在被包装
公共机会{get;set;}
//获取案例和机会对象作为构造函数中的参数
公共案例包装(案例、案例、机会、机会)
{
c=案例;
这个。o=机会;
}
//命令处理程序-有趣的部分!
公共页面引用doSomethingReallyCool()
{
返回null;
}
公共页面参考GOSOMEWHEREALLycool()
{
返回新的页面引用('http://www.youtube.com/watch?v=3zwhC9rwauw');
}
}
//也许在主构造函数中填充列表
公共课
{
//初始化包装器列表
this.theCaseOppWrapper=新列表();
//例如,假设您的案例对象上有一个Opportunity\uuuC引用字段。
//在本例中,您将首先创建一个helper Opportunity map,如下所示:
Map oppMap=新映射();
对于(机会o:机会)
{
oppMap.put(o.Id,o);
}
//现在,通过案例循环,您可以创建混合包装器。
//请记住,这个新的混合包装器现在需要两个
//它的构造函数中的参数,以同时保留大小写和
//机会对象。。。
列表案例=[从案例限制1000中选择Id、主题等];
适用于(案例c:案例)
{
this.theCaseOppWrapper.add(newCaseOppWrapper(c,oppMap.get(c.Opportunity\uuuu c));
}
}    
现在在视觉力量中

<apex:pageBlockTable value="{!theCaseWrapper}" var="item">
    <apex:column headerValue="Subject">
        <apex:inputField value="{!item.c.Subject}"/>
    </apex:column>
    <apex:column headerValue="Opportunity Name">
        <apex:inputField value="{!item.o.Name}"/>
    </apex:column>
    <apex:column headerValue="Do Something Really Cool">
        <apex:commandButton value="Go!" action="{!item.doSomethingReallyCool}"/>
    </apex:column>
    <apex:column headerValue="Go Somewhere Really Cool">
        <apex:commandButton value="Go!" action="{!item.goSomewhereReallyCool}"/>
    </apex:column>
</apex:pageBlockTable>


我可能没有正确地合并这一点,但我无法完全实现这一点。因此,我对visualforce代码进行了编辑,但仍然不起作用。我做的更改是否正确?我看到的一个问题是,
value=“/{!c.Id}”
Case没有name字段中缺少正斜杠。如果我做了更改并使用了另一个属性,它仍然不允许我单击记录行来进行任何操作。我遗漏了什么?您可能需要将outputLink放在一列中。我会更新我的答案显示这一点。嗨,亚当,谢谢你的帖子。你能给我解释一下如何用两种对象类型填充该列表吗。也就是说,如何将案例和机会添加到同一列表caseWrapper。我想显示一个混合队列。这将在一个列表中显示案例和机会。谢谢你的帖子。谢谢,我现在知道了如何创建一个包装器(我想):如果你想要一个更简单的包装器示例,请告诉我,我会为你写一个。顺便说一句,我也是Ubuntu的粉丝,但是你试过/看过Mint了吗?我刚把它安装在笔记本电脑上,看起来真的很不错。
// First, prototype wrapper list above main class constructor
public List<CaseOppWrapper> theCaseOppWrapper {get; set;}

// Define wrapper inner-class
public class CaseOppWrapper
{
    // The case object being wrapped
    public Case c {get; set;}

    // The Opportunity being wrapped
    public Opportunity o {get; set;}

    // Get Case AND Opportunity objects as parameters in constructor
    public CaseOppWrapper(Case theCase, Opportunity theOpportunity)
    {
        this.c = theCase;
        this.o = theOpportunity;
    }

    // Command handler - the fun part!
    public PageReference doSomethingReallyCool()
    {
        return null;
    }

    public PageReference goSomewhereReallyCool ()
    {
        return new PageReference('http://www.youtube.com/watch?v=3zwhC9rwauw');
    }
}

// Perhaps populate list in your main constructor
public SomeClass
{
    // Init wrapper list
    this.theCaseOppWrapper = new List<CaseOppWrapper>();

    // Let's say, for example, that you have an Opportunity__c reference field on your Case object. 
    // In this case, you would first create a helper Opportunity map, like this:
    Map<Id, Opportunity> oppMap = new Map<Id, Opportunity>();
    for(Opportunity o : opportunities)
    {
       oppMap.put(o.Id, o);
    }

    // Now looping through cases you can create your blended wrapper.
    // Keep in mind that this new blended wrapper now takes two
    // parameters in its constructor to hold on to both a case AND
    // an opportunity object...
    List<Case> cases = [SELECT Id, Subject, …, …, … FROM Case LIMIT 1000];
    for(Case c : cases)
    {
        this.theCaseOppWrapper.add(new CaseOppWrapper(c, oppMap.get(c.Opportunity__c)));
    }
}    
<apex:pageBlockTable value="{!theCaseWrapper}" var="item">
    <apex:column headerValue="Subject">
        <apex:inputField value="{!item.c.Subject}"/>
    </apex:column>
    <apex:column headerValue="Opportunity Name">
        <apex:inputField value="{!item.o.Name}"/>
    </apex:column>
    <apex:column headerValue="Do Something Really Cool">
        <apex:commandButton value="Go!" action="{!item.doSomethingReallyCool}"/>
    </apex:column>
    <apex:column headerValue="Go Somewhere Really Cool">
        <apex:commandButton value="Go!" action="{!item.goSomewhereReallyCool}"/>
    </apex:column>
</apex:pageBlockTable>