2011-12-18 39 views
0

我將使用Exploring Lift一書中稍微修改的清單4.7來問我的問題。如何將View中的參數傳遞給Lift中的代碼片段?

// In Boot.boot: 
LiftRules.viewDispatch.append { 
    case List("Expenses", "recent", acctId, authToken) => 
     Left(() => Full(RSSView.recent(acctId, authToken))) 

    // This is a dispatch via the same LiftView object. The path 
    // "/Site/news" will match this dispatch because of our dispatch 
    // method defined in RSSView. The path "/Site/stuff/news" will not 
    // match because the dispatch will be attempted on List("Site","stuff") 
    case List("Site") => Right(RSSView) 
} 

// Define the View object: 
object RSSView extends LiftView { 
    def dispatch = { 
     case "news" => siteNews 
    } 

    def recent(acctId : String, authToken : String)() : NodeSeq = { 
     // User auth, account retrieval here 
     ... 
     <lift:surround with="rss" at="content"> 
      <lift:Vote.image /> 
     </lift:surround> 
    } 

    // Display a general RSS feed for the entire site 
    def siteNews() : NodeSeq = { ... } 
} 

我如何通過acctId從視圖功能最近入段電梯:Vote.image?謝謝。

回答

0

如果您嘗試從用戶啓動時獲取acctId和authToekn,則這不起作用。引導僅在Web應用程序啓動時運行,而不是每個用戶都運行一次。

您必須在用戶登錄時或者在檢測到自動登錄Cookie後設置SessionVar,然後在需要時訪問sessionVar。

+0

我不想從啓動獲取acctId和authToken。我想從url中獲取acctId,以便我可以渲染不同的內容。但是,SessionVar確實有助於達到這個目的。謝謝。 – coolsuntraveler 2011-12-22 07:43:48

相關問題