2011-11-14 2 views
1

私が探しているのは、オポチュニティ、ケース、潜在的に1つの他のオブジェクトのマッシュアップを表示するカスタムコントローラリストを作成することです。私は私が軌道に乗るためにVisualforceのガイドからクラスを使用して開始しました: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(); 
} 
} 

を、私は今の例のリストを表示するには、いくつかの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> 

私は今、何をしようとしていますテーブル内の項目をクリック可能にします。私は、リストに表示されているレコードをクリックして、レコードをポップアップさせたいと思っています。

ありがとうございました。

答えて

7

あなたは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> 
+0

私はこれを正しく組み込まれていないかもしれないが、私は非常にこれを動作させることはできません。 – Havoc783

+0

commandLinkをこの出力リンクに置き換えてください –

+0

私はVisualforceコードを編集しましたが、まだ動作しません。私は正しく変更していますか? – Havoc783

4

おそらく、私はApexで最も活用recepieは、ラッパークラスです。ラッパークラスを使用すると、コマンドリンク/ボタンだけでなく、チェックボックスやクリック認識イメージ(apex:actionSupportを使用)など、他の関連要素をリストに追加することもできます。 Apexでは、問題のオブジェクトをコンストラクタのパラメータとして取得するリストを作成します。

<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> 

は、私はこのコードをテストしていませんが、私はそれが正しいようだと思う...

(ページ、フォーム、pageblock、pageblocksection内部の)あなたのVisualforceのための今
// 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)); 
    } 
} 

:ここでは次のようになります。とにかく、あなたのクラスにこれらのような複数のリストを作成して、Visualforceで自由にレンダリングできます。アクションボタン/アクションリンクと必要なものがあれば完成します。

乾杯のVisualforceで今

+0

こんにちはアダム、あなたのポストに感謝します。そのリストに2つのオブジェクトタイプをどのように設定するかを私に説明してください。つまり、ケースと機会を同じリストcaseWrapperに追加する方法です。私は混合キューを表示したい。これにより、ケースと機会の両方が1つのリストに表示されます。あなたの投稿に感謝します。 – Havoc783

+0

変更されたコードがそれを行うべきです。 – Adam

+0

ありがとう、私は今ラッパー(私は思う)を作成する方法を知っています:P – theTuxRacer

1
// 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> 
関連する問題