Okay, so the trick here is to use an actionFunction and then call it directly from javascript.
So the VF page looks like this:
<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>
and the controller like this:
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;
}
}
Go for this in-depth job-oriented salesforce course online!