0

我有以下 visualforce 页面,需要通过 case.recortype 或 case.recordtype.id 字段过滤相关列表或 pageblocktables。谁能指导我找出如何做到这一点?谢谢

<apex:page standardController="Account" >
 <apex:pageblock title="Cases" >
     <apex:pageblockSection >
     <apex:relatedList title="Support Cases" list="Cases"/>
     </apex:pageblockSection>
     <apex:pageblockSection >
     <apex:relatedList title="Training Cases" list="Cases"/>
     </apex:pageblockSection>
 </apex:pageblock>
 <apex:pageBlock title="Support Cases" >
     <apex:pageBlockTable value="{!Account.Cases}" var="c">
      <apex:column headervalue="Case"><apex:outputLink value="/{!c.id}">{!c.CaseNumber}</apex:outputLink></apex:column>
      <apex:column value="{!c.Contact.Name}"/>
      <apex:column value="{!c.Subject}"/>
      <apex:column value="{!c.Priority}"/> 
      <apex:column value="{!c.CreatedDate}"/> 
      <apex:column value="{!c.status}"/>      
      <apex:column value="{!c.createdbyId}"/>
 </apex:pageBlockTable> 
 </apex:pageBlock>
  <apex:pageBlock title="Training Cases" >
     <apex:pageBlockTable value="{!Account.Cases}" var="c">
      <apex:column headervalue="Case"><apex:outputLink value="/{!c.id}">{!c.CaseNumber}</apex:outputLink></apex:column>
      <apex:column value="{!c.Contact.Name}"/>
      <apex:column value="{!c.Subject}"/>
      <apex:column value="{!c.Priority}"/> 
      <apex:column value="{!c.CreatedDate}"/> 
      <apex:column value="{!c.status}"/>      
      <apex:column value="{!c.createdbyId}"/>
 </apex:pageBlockTable> 
 </apex:pageBlock>

</apex:page>

更新:这就是我最终做的事情:

页:

<apex:page standardController="account" extensions="SupportCasefilter,TrainingCasefilter">
 <apex:form >
     <apex:pageBlock title="Support Cases">    
             <apex:pageBlockTable value="{!SupportCases}" var="s">
                  <apex:column headervalue="Case"><apex:outputLink value="/{!s.id}">{!s.CaseNumber}</apex:outputLink></apex:column>
                  <apex:column value="{!s.Contact.Name}"/>
                  <apex:column value="{!s.Subject}"/>
                  <apex:column value="{!s.Priority}"/> 
                  <apex:column value="{!s.CreatedDate}"/> 
                  <apex:column value="{!s.status}"/>      
                  <apex:column value="{!s.createdbyId}"/>
             </apex:pageBlockTable> 
     </apex:pageBlock>
     <apex:pageBlock title="Training Cases">
             <apex:pageBlockTable value="{!TrainingCases}" var="t">
                  <apex:column headervalue="Case"><apex:outputLink value="/{!t.id}">{!t.CaseNumber}</apex:outputLink></apex:column>
                  <apex:column value="{!t.Contact.Name}"/>
                  <apex:column value="{!t.Subject}"/>
                  <apex:column value="{!t.Priority}"/> 
                  <apex:column value="{!t.CreatedDate}"/> 
                  <apex:column value="{!t.status}"/>      
                  <apex:column value="{!t.createdbyId}"/>
                  <apex:column value="{!t.recordtype.id}"/>
         </apex:pageBlockTable>  
     </apex:pageBlock>
</apex:form>   

控制器1:

public with sharing class SupportCasefilter {

    public id accRecId;

    public SupportCasefilter(ApexPages.StandardController controller) {

    accRecId = [select id from account where id = :ApexPages.currentPage().getParameters().get('id')].id;

    }

    List<case> supportCases;

    public List<case> getSupportCases() {
        if(accRecId != null) {
        supportCases= [SELECT Id, Contact.name, recordtype.id, casenumber, subject, priority, createddate, status, createdbyid 
                        FROM Case 
                        WHERE Record_Type__c='Support' AND account.id=:accRecId];
        }
    return supportCases;
    }    

}

控制器2:

public with sharing class TrainingCasefilter {

    public id accRecId;

    public TrainingCasefilter(ApexPages.StandardController controller) {

    accRecId = [select id from account where id = :ApexPages.currentPage().getParameters().get('id')].id;

    }

    List<case> trainingCases;

    public List<case> getTrainingCases() {
        if(accRecId != null) {
        trainingCases= [SELECT Id, Contact.name, recordtype.id, casenumber, subject, priority, createddate, status, createdbyid 
                        FROM Case 
                        WHERE Record_Type__c='Training' AND account.id=:accRecId];
        }
    return trainingCases;
    }    

}
4

2 回答 2

0

我建议在将结果传递到 pageBlockTable 之前,使用 SOQL 查询在控制器本身内应用记录类型过滤器。

于 2013-11-01T13:58:34.810 回答
0

这是我过去所做的:

1 - 在控制器中创建一个List<RecordType> validRecordTypes包含有效 RecordTypeIds 的

2 - 使用控制器中 Account.Cases的列表过滤您的对象。validRecordTypes

3 - 当您尝试Account.Cases在 VisualForce 页面中访问时,对象应该是后过滤的对象

于 2013-11-03T05:46:37.237 回答