Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
how to solve following snippet implementation?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Christian Thomas  
View profile  
 More options Nov 18 2012, 4:54 am
From: Christian Thomas <chris...@googlemail.com>
Date: Sun, 18 Nov 2012 01:54:26 -0800 (PST)
Local: Sun, Nov 18 2012 4:54 am
Subject: how to solve following snippet implementation?

Hello,

currently I have started to reimplement my existing blog (it is a JSF app :
www.chr-thomas.de) with Lift to learn it (I can simply use my existing
services via jndi lookup do get the appropriate content for the page).

I want to create a side bar, which should show a listing of all existing
main-categories including its sub-categories (if you visit my page, you can
see it on the right side under the header "Kategorien"). The visitor can
click such a sub-category to the filter the result of article-previews on
that page.

*Kategorien*

> Administration ( main-category )

>    - JDK <http://www.chr-thomas.de/blog/category/jdk> :: 1 ( sub-category
>    )

> Softwareentwicklung ( main-category )

>    - Java Enterprise Edition<http://www.chr-thomas.de/blog/category/javaenterpriseedition> ::
>    1 ( sub-category )

Okay, if have startet to write for that part following html conent

<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>

Here the snippet class:

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)}))


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Christian Thomas  
View profile  
 More options Nov 18 2012, 5:00 am
From: Christian Thomas <chris...@googlemail.com>
Date: Sun, 18 Nov 2012 02:00:16 -0800 (PST)
Local: Sun, Nov 18 2012 5:00 am
Subject: Re: how to solve following snippet implementation?

oops, I have accidentally post it...

Okay, here my question:

How can I solve it in Lift:

I have to pass the id of each main-category to the snippet, which generates
the entries for the sub-categories ( currently a static known parentId
val parentId : Long = 1 //in method subCategories
 is set to see, I the rest of the code works ) ?

Can give someone me a hint, example?

Thanks!

Kind regards!

Christian


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
AGYNAMIX Torsten Uhlmann  
View profile  
 More options Nov 18 2012, 5:19 am
From: AGYNAMIX Torsten Uhlmann <T.Uhlm...@agynamix.de>
Date: Sun, 18 Nov 2012 11:19:09 +0100
Local: Sun, Nov 18 2012 5:19 am
Subject: Re: [Lift] Re: how to solve following snippet implementation?

Hi Christian,

so you basically want to support a URL like "/blog/<xyz>/list" where xyz is a category or ID or whatever narrows down the elements to show?

Then Menu.param is one (preferred) solution to do it. Have a look at: https://github.com/d6y/london_class_march_2011_sitemap_css

You might need to put the source code into a new sbt skeleton project, but it still works with the latest Lift libs. There is an example David did with a list of forums and a list of threads per forum.

Does that help?

Torsten.

--
AGYNAMIX(R). Passionate Software.
Inh. Torsten Uhlmann | Buchenweg 5 | 09380 Thalheim
Phone:       +49 3721 273445
Fax:             +49 3721 273446
Mobile:       +49 151 12412427
Web:           http://www.agynamix.de

Am 18.11.2012 um 11:00 schrieb Christian Thomas <chris...@googlemail.com>:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
David Pollak  
View profile  
 More options Nov 18 2012, 12:07 pm
From: David Pollak <feeder.of.the.be...@gmail.com>
Date: Sun, 18 Nov 2012 09:07:43 -0800
Local: Sun, Nov 18 2012 12:07 pm
Subject: Re: [Lift] Re: how to solve following snippet implementation?

Also, please use the CSS Selector Transforms rather than the bind()
syntax... the CSS Selector Transforms lead to more readable
and understandable code.

On Sun, Nov 18, 2012 at 2:19 AM, AGYNAMIX Torsten Uhlmann <

--
Telegram, Simply Beautiful CMS https://telegr.am
Lift, the simply functional web framework http://liftweb.net
Follow me: http://twitter.com/dpp
Blog: http://goodstuff.im

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Christian Thomas  
View profile  
 More options Nov 18 2012, 1:46 pm
From: Christian Thomas <chris...@googlemail.com>
Date: Sun, 18 Nov 2012 10:46:01 -0800 (PST)
Local: Sun, Nov 18 2012 1:46 pm
Subject: Re: [Lift] Re: how to solve following snippet implementation?

@Torsten big thanks for your help via mail :thumbsup:

@Torsten, @David: yes, the css selector transforms is the better way. This
also simply solved my problem.

Now the html look's like:

<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>

and the snippet code:

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)

}
}
}
}

and I really like it : )

Now I have to check, how to use the Menu.param to append the dynamic
link's...

Am Sonntag, 18. November 2012 18:07:48 UTC+1 schrieb David Pollak:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
David Pollak  
View profile  
 More options Nov 19 2012, 6:20 pm
From: David Pollak <feeder.of.the.be...@gmail.com>
Date: Mon, 19 Nov 2012 15:20:14 -0800
Local: Mon, Nov 19 2012 6:20 pm
Subject: Re: [Lift] Re: how to solve following snippet implementation?

Please take a look at the project that Torsten pointed you to.
Specifically, the ForumStuff.scala file which contains the logic to create
a menu link based on a parameter:

class AForum(f: Forum) {
  def render = "li *" #>
  ForumThread.all(f).map(t =>
    "a *+" #> t.name & "a [href]" #> AThread.menu.calcHref(f -> t))

}

On Sun, Nov 18, 2012 at 10:46 AM, Christian Thomas
<chris...@googlemail.com>wrote:

--
Telegram, Simply Beautiful CMS https://telegr.am
Lift, the simply functional web framework http://liftweb.net
Follow me: http://twitter.com/dpp
Blog: http://goodstuff.im

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Christian Thomas  
View profile  
 More options Nov 20 2012, 3:06 pm
From: Christian Thomas <chris...@googlemail.com>
Date: Tue, 20 Nov 2012 12:06:28 -0800 (PST)
Local: Tues, Nov 20 2012 3:06 pm
Subject: Re: [Lift] Re: how to solve following snippet implementation?

Currently I'm trying to find out, how it work's. But at this first time it
is really hard to understand, what there happens (the concrete impl) !

In my example I have got a page blog.html. This contains the snippet above
to show the existing categories. Each rendered sub-category is clickable to
filter the summary of listed blog-articles.

For instance:
/blog <-- has to show all existing blog-article-previews on the blog.html
page
/blog/category/example <-- has to show all blog-article-previews in
relation to the category "example" on the blog.html page
/blog/article/example-article <-- has to show the complete article on the
article page ( I think I have to create an article folder containing a
star.html file )

I have created a small mvn project (contains a lift-app and a tiny
Java-Service (in real world it should be an EJB or something else...) ),
which shows the current state of my test-project.

Please feel free to have a look on
it: https://github.com/Chris81T/learning-lift.git

This version is still running without error's. May someone can support me
to solve my current problem by giving some hints / example code (with may
some short comments) appropriate to the small project.

For instance I really don't understand following code:

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 *

}

*Thank's in advance!*

Christian

Am Dienstag, 20. November 2012 00:20:21 UTC+1 schrieb David Pollak:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Christian Thomas  
View profile  
 More options Nov 21 2012, 2:29 pm
From: Christian Thomas <chris...@googlemail.com>
Date: Wed, 21 Nov 2012 11:29:02 -0800 (PST)
Local: Wed, Nov 21 2012 2:29 pm
Subject: Re: [Lift] Re: how to solve following snippet implementation?

Okay, now I have continued implementing my example project.

First of all I simply want to create the article navigation:

   - behind the "read..." link an appropriate url for the article is
   requested
   - after clicking the "read..." link the article page has to be called
   and has to show the whole article instead of the article-preview on the
   blog page

  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 !!!

}

  }

this is the render function of the ArticlePreviews snippet. This is used to
show on the blog page all existing article-previews (or all previews
appropriate to a selected category ( filter function ))

Here is the Article object:
object Article {
/*
 *  sealed trait MenuSingleton extends AnyRef
   * def param[T <: AnyRef](name: String, linkText: LinkText[T], parser:
(String) ⇒ Box[T], encoder: (T) ⇒ String): PreParamMenu[T]
 */
lazy val menu = Menu.param[de.java.entities.Article]("Article",
  "Reading an article",
                                                     articleId =>
findArticleById(articleId),
                                                     article =>
getIdForArticle(article)
 ) / "article" / *

def findArticleById(articleId: String) : Box[de.java.entities.Article] = {
val article = BlogJavaService.getArticle(articleId.toLong)

/* TODO I dont think, that is the best solution to get the box instance -
source:
https://github.com/d6y/london_class_march_2011_sitemap_css/blob/maste...
-> def find
 */
val map = Map(articleId -> article)
println("Found article=" + article + " for given id=" + articleId)
val box = map.get(articleId)
println("Returning created box=" + box)
box

}

def getIdForArticle(article: de.java.entities.Article) : String = {
val id = article.getId.toString
println("Returning requested id=" + id + " of article=" + article)
id

}
}

This code will create the required dynamic url's for each "read..." link on
the blog page (my first success for that topic). But another solution
should be better:
I think I have only to handle the articleId of each article-preview
instance to create the url's. And if the user will click the "read..."
link, then the whole article has to be loaded.

How do I have to change the Article.menu to solve this?

To see the complete code, please clone my repository:
https://github.com/Chris81T/learning-lift.git

Christian

Am Dienstag, 20. November 2012 21:06:28 UTC+1 schrieb Christian Thomas:

...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »