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菜单
Dynamically Fused Graph Network for Multi-hop Reasoning1 Shanghai Jiao Tong Univ
CEAT-Dynamically-Add-delete-Row---LWC
Uploading-Images-To-Node-Dynamically:源代码
webpack-4-快速启动Webpack 4教程:从0 Conf到生产模式所需的所有知识发展npm i && npm run start元华伦天奴加格里亚蒂- - 执照该项目是在许可下的开源软件。
使用html5-svg-dynamic-with-pablo.js
动态生成小部件 最后一种做法,我们动态创建小部件并生成中间代码取决于页面中存在的小部件。 保存和加载功能是用php实现的,所以获得了服务器环境。
使用C#动态生成图像 我们要求用户注册新帐户时显示其个人资料图片,稍后他可以更改其个人资料图片。 该项目是解决此目的的示例。
It wraps all the essential elements needed for creating a game, making the task of game building very developer-friendly. Starting with a vital primer to get you up and running with your development...
+ 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 ...
Model-based development of dynamically adaptive software
manner, using familiar Web-page-building tools. You then enclose the code for the dynamic parts in special tags, most of which start with <% and end with %>. For example, Listing 10.1 (Figure 10–1) ...
In the last few years, business process management systems have been employed for handling information systems of ever increasing complexity. As a consequence, the adoption of modelling languages ...
enabling you to create realistic sprite movements, and particle systems to dynamically simulate explosions, fire, rain, and smoke, as well as exploring the sound engine to make your game more robust....
Ultrafastand low-power dynamically tunable plasmon induced transparencies in compactaperture-coupled rectangular resonators
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