2012-08-01 2 views
0

org에있는 모든 apex 클래스 이름을 포함하는 동적 선택 목록 필드가 있습니다. 페이지에는 "표시"단추도 있습니다. 이제 사용자가이 선택 목록에서 값을 선택하고 표시 버튼을 클릭하면 해당 클래스의 정점 코드가 아래에 표시됩니다. Pls는 VF 페이지에서 어떻게 구현할 수 있는지 제안합니다.Show 버튼 클릭시 apex 클래스 코드 표시

감사합니다.

<apex:form > 
<apex:selectList value="{!selectedClass}" size="5"> 
<apex:selectOptions value="{!ClassList}" ></apex:selectOptions> 
</apex:selectList> 
<apex:pageBlock > 
<apex:commandButton action="{!show}" value="Show" id="Button"/> 
<apex:pageBlockSection title="My Current Class"> 

답변

1

당신은 당신이 찾고있는 무엇에 대한 ApexClass 객체의 body 필드를 조회 할 수있다 :

public class SomeController { 

    private List<ApexClass> allApexClasses; 
    public String selectedClass {public get; public set;} 
    public String apexCodeOutput {public get; private set;} 

    public SomeController() { 
     // only select classes that aren't part of a managed package, since you won't be able to view the body 
     allApexClasses = [select id, name, body from ApexClass where lengthwithoutcomments <> -1 order by name asc]; 
    } 

    public List<SelectOption> getClassList() { 
     List<SelectOption> opts = new List<SelectOption> opts; 
     for (ApexClass ac : allApexClasses) 
      opts.add(new SelectOption(ac.Id, ac.Name)); 
     return opts; 
    } 

    public PageReference show() { 
     if (selectedClass != null) { 
      Id classId = (Id) selectedClass; 
      for (ApexClass ac : allApexClasses) { 
       if (classId == ac.Id) { 
        apexCodeOutput = ac.body; 
        break; 
       } 
      } 
     } 
     return null; 
    } 
} 

그리고 당신의 VF 페이지에서 바로 출력 코드를 다시 쓰게 버튼을 클릭하면. 코드 주위에 <pre> 태그를 사용하여 간격을 유지하면 코드를 읽을 수 있습니다.

<apex:form> 
    <apex:selectList value="{!selectedClass}" size="5"> 
     <apex:selectOptions value="{!ClassList}" ></apex:selectOptions> 
    </apex:selectList> 
    <apex:pageBlock > 
     <apex:commandButton action="{!show}" value="Show" rerender="apexoutput" id="Button"/> 
     <apex:pageBlockSection title="My Current Class"> 
      <apex:outputPanel id="apexoutput"> 
       <pre>{!apexcodeoutput}</pre> 
      </apex:outputPanel> 
     </apex:pageBlockSection> 
    </apex:pageBlock> 
</apex:form>