2012-06-19 162 views
0

我正在嘗試在我的頁面上顯示關於知識文章的信息。我想要展示的一件事是最常見的文章統計。如何通過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頁面到一個標籤。當我查看該頁面時,除了關於查看次數最多的統計信息之外,所有關於知識文章的信息都會顯示出來。我如何看到這個數據?

+0

非常有趣的,你是如何使用自定義Query_component,願意分享你的設計決策中使用替代只是在控制器查詢? –

+0

@Ralph你是什麼意思「只是在控制器查詢」? –

+0

通常,如果您遵循MVC設計原則,visualforce頁面(視圖)只會顯示數據,控制器會在其中處理查詢數據的位置。在這種情況下,「控制器」是驅動你的visualforce頁面(你沒有)的頂級類,通常是你做數據庫查詢的地方。 c:query組件允許您在頁面中指定查詢。以前沒見過有人這樣做過。 –

回答

0

這是我最後用我的Visualforce頁面:

<c:Query_component queryString="SELECT NormalizedScore, Id, ParentId FROM KnowledgeArticleViewStat WHERE Channel='Csp'"> 
     <apex:variable value="{!results[articleid]}" var="result"/> 
      <span class="inlinesparkline">100, {!result}</span> 
    </c:Query_component> 
1

您忘記爲查看屬性添加輸出。您必須在重複中添加<apex:outputText>標記以顯示值。

<apex:outputText>{!result.NormalizedScore}</apex:outputText>

相關問題