Kategorien
Administration ( main-category )Softwareentwicklung ( main-category )
- JDK :: 1 ( sub-category )
- Java Enterprise Edition :: 1 ( sub-category )
<section> <header><h3>Kategorien</h3></header> <section class="lift:Categories.mainCategories"> <header><h4><span lift:bind="row:name">main category name</span></h4></header> <ul> <li class="lift:Categories.subCategories"><a subrow:link=""><span lift:bind="subrow:name">sub category name</span></a> :: <span lift:bind="subrow:count">count</span></li> </ul> </section> </section>class Categories { def mainCategories(html: NodeSeq) : NodeSeq = { val resource = new BlogResource // know's how to access the java services val mainCategories = resource.getAllMainCategories return mainCategories.flatMap(category => bind("row", html, "name" -> {category.getName + " : " + category.getId})) }
def subCategories(html: NodeSeq) : NodeSeq = { val resource = new BlogResource // know's how to access the java services val parentId : Long = 1 // for the first test a static id is set val subCategories = resource.getAllChildCategories(parentId) return subCategories.flatMap(category => bind("subrow", html, FuncAttrBindParam("link", {ns : NodeSeq => Text("/blog/category/" + category.getName.toLowerCase)}, "href"), "name" -> {category.getName}, "count" -> {resource.getNoOfArticlesForCategory(category.getId)})) }}val parentId : Long = 1 //in method subCategories--
--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code
<section class="lift:Categories"> <header><h4><span name="main-category-name">main category name</span></h4></header> <ul> <li name="sub-category"><a href="todo"><span name="sub-category-name">sub category name</span></a> :: <span name="sub-category-count">count</span></li> </ul></section>class Categories {
def render = { val resource = new BlogResource // know's how to access the java service val mainCategories = resource.getAllMainCategories
"* *" #> mainCategories.map {mainCategory => "@main-category-name" #> mainCategory.getName & "@sub-category *" #> resource.getAllChildCategories(mainCategory.getId).map {subCategory => "@sub-category-name" #> subCategory.getName & "@sub-category-count" #> resource.getNoOfArticlesForCategory(subCategory.getId) } } }
}object AForum { lazy val menu = Menu.param[Forum]("AForum", // for what is this string good for? Simply a label Loc.LinkText(f => Text(S.?("Forum") +": "+f.name)), // ????? (s: String) => { // is this an anonymous function ?? println("Looking up forum "+s) val ret = Forum.find(s) println("Found "+ret) ret // where will the return ret value be used ?? }, (f: Forum) => f.id) / "forums" / * // this defines the dynamic url. the id will be replaced for the *}
def render = {
/* TODO: - adapt class to support filtering by category - add dynamic href article url */
/* it is not necessary to return all real articles including content. It should be overhead. Only the complete article is requested, if the visitor wants to read the article
--> An articlePreview knows the id of the article */ val articles = asScalaList(BlogJavaService.getAllArticlePreviews) "* *" #> articles.map {article => "@article-title" #> article.getTitle & "a [href]" #> Article.menu.calcHref(BlogJavaService.getArticle(article.getArticleId)) // TODO this is a first test to see, if something at all will work !!! Normally I do not want to call each article! I'm not really shure, how the Menu.param work's !!! } }object Article {