0

組織にあるすべての Apex クラス名を含む動的選択リスト項目があります。ページには「表示」ボタンもあります。ユーザーがこの選択リストから値を選択して [表示] ボタンをクリックすると、そのクラスの Apex コードが下に表示されます。Pls は、VF ページに実装する方法を提案します。

ありがとう!

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

1 に答える 1

1

探しているものについてオブジェクトのbodyフィールドを照会できます。ApexClass

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>
于 2012-08-01T14:38:00.250 に答える