3

誰かがajaxを使用してページロード時にajaxを介してapexpageBlockTableをロードする方法を教えてもらえますか?apex actionFunctionの使用方法を示す例を見てきましたが、サンプルは通常単純です(たとえば、コントローラーから文字列を返し、それをページに配置します。コントローラーはsObjectのリストを返しますが、よくわかりません。それがどのように行われるか。

ページ:

<apex:pageBlockTable value="{!TopContent}" var="item">
    <apex:column headerValue="Title">
        <apex:outputLink value="/sfc/#version?selectedDocumentId={!item.Id}">
          {!item.Title}
        </apex:outputLink>
    </apex:column>
</apex:pageBlockTable>

コントローラ:

List<ContentDocument> topContent;
public List<ContentDocument> getTopContent()
{
    if (topContent == null)
    {
        topContent = [select Id,Title from ContentDocument limit 10];
    }
    return topContent;
}
4

1 に答える 1

1

私はこれを理解しました。秘訣は、actionFunctionを使用して、JavaScriptから直接呼び出すことです。

したがって、VFページは次のようになります。

<apex:page controller="VfTestController">
    <apex:form>
        <apex:actionFunction action="{!loadDocuments}" name="loadDocuments" rerender="pageBlock" status="myStatus" />
    </apex:form>
    <apex:pageBlock id="pageBlock"> 
        <apex:pageBlockTable value="{!TopContent}" rendered="{!!ISBLANK(TopContent)}" var="item">
            <apex:column headerValue="Title">
                <apex:outputLink value="/sfc/#version?selectedDocumentId={!item.Id}">
                    {!item.Title}
                </apex:outputLink>
            </apex:column>
        </apex:pageBlockTable>
        <apex:actionStatus startText="Loading content..." id="myStatus" />
    </apex:pageBlock>
    <script type="text/javascript">
        window.setTimeout(loadDocuments, 100);
    </script>
</apex:page>

そしてこのようなコントローラー:

public class VfTestController 
{
    List<ContentDocument> topContent;
    public List<ContentDocument> getTopContent()
    {
        return topContent;
    }

    public PageReference loadDocuments()
    {
        if (topContent == null)
        {
            topContent = [select Id,Title from ContentDocument limit 10];
        }
        return null;
    }
}
于 2010-10-06T23:09:30.480 に答える