Visualforce自定义控制器列表

Hav*_*783 2 salesforce visualforce apex-code

我要做的是创建一个自定义控制器列表,显示机会,案例和可能的另一个对象的混搭.我开始使用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();
}
}
Run Code Online (Sandbox Code Playgroud)

我调整了一些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>
Run Code Online (Sandbox Code Playgroud)

我现在要做的是让表中的项目可以点击.我希望能够单击列表中显示的记录并弹出记录.

谢谢.

Jer*_*oss 8

你可以使用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>
Run Code Online (Sandbox Code Playgroud)


Ada*_*dam 5

也许我在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));
    }
}
Run Code Online (Sandbox Code Playgroud)

现在为您的Visualforce(在页面内,表单,页面块,pageblocksection)...

<apex:pageBlockTable value="{!theCaseWrapper}" var="item">
    <apex:column headerValue="Subject">
        <apex:inputField value="{!item.c.Subject}"/>
    </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>  
Run Code Online (Sandbox Code Playgroud)

我没有测试过这段代码,但我认为它看起来是正确的.无论如何,您可以在类中创建多个列表,例如在Visualforce中随意渲染它们 - 完成操作按钮/操作链接以及您想要的任何其他内容.

干杯