我正在嘗試在我的頁面上顯示關於知識文章的信息。我想要展示的一件事是最常見的文章統計。如何通過SQL查詢從Visualforce頁面獲取KnowledgeArticleViewStat數據?
我有一個Visualforce的Apex組件,如下所示:
<apex:component controller="Component_Query" access="global">
<apex:attribute name="QueryString" type="String" required="true" access="global" assignTo="{!queryString}"
description="A valid SOQL query in string form." />
<apex:variable value="{!results}" var="results"/>
<apex:componentBody />
</apex:component>
我有一個Visualforce頁面,看起來像這樣:
<apex:page >
<table id="articles">
<knowledge:articleList articleVar="article" sortBy="mostViewed" pageSize="5">
<tr>
<td>{!article.articlenumber}</td>
<td><a target="_parent" href="{!URLFOR($Action.KnowledgeArticle.View, article.id)}">{!article.title}</a></td>
<td>{!article.articletypelabel}</td>
<td>{!article.lastpublisheddate}</td>
<td>
<c:Query_component queryString="SELECT NormalizedScore FROM KnowledgeArticleViewStat WHERE ParentId = '{!article.id}'">
<apex:repeat value="{!results}" var="result">
</apex:repeat>
</c:Query_component>
</td>
</tr>
</knowledge:articleList>
</table>
</apex:page>
我把Visualforce頁面到一個標籤。當我查看該頁面時,除了關於查看次數最多的統計信息之外,所有關於知識文章的信息都會顯示出來。我如何看到這個數據?
非常有趣的,你是如何使用自定義Query_component,願意分享你的設計決策中使用替代只是在控制器查詢? –
@Ralph你是什麼意思「只是在控制器查詢」? –
通常,如果您遵循MVC設計原則,visualforce頁面(視圖)只會顯示數據,控制器會在其中處理查詢數據的位置。在這種情況下,「控制器」是驅動你的visualforce頁面(你沒有)的頂級類,通常是你做數據庫查詢的地方。 c:query組件允許您在頁面中指定查詢。以前沒見過有人這樣做過。 –