Ask:
Hi,
I want to add/remove Menu at runtime, for dynamically managing menu
list.
so I need to persist the menu list(SiteMap?) to the database,
and retrieve it from the database when users access the home page.
the menu items link to the same page, pass some different params so
let that page show different data.
so I want to dynamically build the menu of home page.
is it possible to do this by using SiteMap and Menu of liftweb?
Answer:
In a word, yes.
In a bunch of example... well if you have a static menu that you want to
enable, disable based on some calculation, use If() and Unless() when you're
defining your Loc(). You can see an example in ProtoUser.scala.
For a custom menu based on RDBMS content:
class BaseContentLoc(val name: String, _aspect: String) extends
Loc[CustomContent] {
// the name of the page
// def name = "Content"
val BaseAspect = _aspect
def defaultParams = Full(ContentLocStuff.NullCustomContent)
override def forceParam = defaultParams
// the default parameters (used for generating the menu listing)
override def additionalKidParams =
CustomContent.findAll(By(CustomContent.aspect, BaseAspect),
OrderBy(CustomContent.displayOrder, Ascending))
// no extra parameters
def params = List(Loc.PlaceHolder, Loc.Template(myTemplate))
def myTemplate() =
<lift:surround with="default-final" at="content"><lift:display
/></lift:surround>
/**
* Generate a link based on the current page
*/
val link =
new Loc.Link[CustomContent](List(BaseAspect), false) {
override def createLink(in: CustomContent) = {
Full(Text("/"+urlEncode(BaseAspect)+"/"+urlEncode(in.page)))
}
}
/**
* What's the text of the link?
*/
val text = new Loc.LinkText(calcLinkText _)
def calcLinkText(in: CustomContent): NodeSeq = {
if (in.page.length > 0) Text(in.page) else Text(name)
}
object Finder {
def unapply(page: String): Option[CustomContent] =
CustomContent.findContent(page, BaseAspect)
}
/**
* Rewrite the request and emit the type-safe parameter
*/
override val rewrite: LocRewrite =
Full({
case RewriteRequest(ParsePath(BaseAspect :: Finder(content) :: Nil,
_, _, _), _, _) =>
(RewriteResponse(BaseAspect :: Nil), content)
})
/**
* Check for page-specific snippets and
* do appropriate dispatching
*/
override val snippets: SnippetTest = {
case ("display", Full(v)) => display(v) _
}
def display(v: CustomContent)(in: NodeSeq) = v.content openOr in
}
Thanks,
David
分享到:
相关推荐
Office365-ECB-Context-Sensitive--dynamically-hide-and--show--Menu-Items---Source-Code:根据列表项元数据动态隐藏和显示ECB菜单
【标题】"2019-ACL-上交+头条-Dynamically Fused Graph Network for Multi-hop Reading Comprehension" 【描述】"近年来,多跳文本问答(TBQA)研究日益受到关注。传统方法通常集中于单段文本内的答案检索,而复杂...
从压缩包的文件名 "Uploading-Images-To-Node-Dynamically-master" 来看,这是一个Git仓库的主分支(master),其中可能包含以下内容: 1. **前端代码**:这部分通常使用HTML、CSS和JavaScript编写,负责用户界面...
【CEAT-Dynamically-Add-delete-Row---LWC】是一个关于Salesforce Lightning Web Components (LWC)的应用示例,它展示了如何在用户界面中动态地添加和删除表格行。LWC是Salesforce的一种轻量级、高性能的前端开发...
webpack-4-快速启动Webpack 4教程:从0 Conf到生产模式所需的所有知识发展npm i && npm run start元华伦天奴加格里亚蒂- - 执照该项目是在许可下的开源软件。
HTML5中的SVG(Scalable Vector Graphics)是一种用于创建图形的标记语言,它允许开发者在网页上绘制矢量图,这些图像是清晰且可放大的,不会因为尺寸变化而失真。JavaScript则是一种广泛用于浏览器端的编程语言,...
这个实践项目,"Genrate-widgets-dynamically",专注于利用JavaScript来动态地创建和管理页面上的小部件,同时根据页面上存在的小部件生成相应的中间代码。这使得我们可以灵活地构建和更新用户界面,而无需硬编码每...
在本文中,我们将深入探讨如何使用C#动态生成图像,特别是在ASP.NET MVC和ASP.NET Core框架下实现这一功能。...我们将讨论以下几个关键知识点: 1. **用户个人资料图像存储**: 用户的个人资料图像通常以文件形式存储...
JSP allows developers to create dynamically generated web pages, while Hibernate is an Object-Relational Mapping (ORM) tool that provides a framework for mapping an object-oriented domain model to a ...
+ Storage of the library's language resources with the ability to dynamically load + Auto-save PivotGrid layout when reloading data + Showing / hiding total rows/columns in PivotGridEh + New aggregate...
- Dynamically changes rotational limit to zoom level - User friendly hotspot creator included - Create interactive hotspots from any collider in your scene - Play sounds, load scenes and load ...
DB - Unbounded Pipelining in Dynamically Reconfigurable Paxos Clusters.pdf Consensus is an essential ingredient of a faulttolerant distributed system systems. When equipped with a consensus ...
NULL 博文链接:https://linshiquan.iteye.com/blog/513084
* Or using UIPackage.CreateObject to create UI component dynamically, and then use GRoot.inst.AddChild to show it on screen. ----------------- Version History ----------------- 3.4.0 - NEW: Add ...
6. Disable MouseGesture dynamically while you are surfing the Internet on web browser with it's own mousegestures. So far, 6 web browsers are in it. That is, Sougou explorer, QQBrowser, TheWorld, ...