There are two main approaches to this, both of which are covered in the Lift
book that you've ordered (thanks!). The first is to use a StatefulSnippet.
This lets you use the same snippet class instance, so any member variables
are still there when the next page hit comes. You can see an example of this
in the AddEntry class in the PocketChange app:

http://github.com/tjweir/pocketchangeapp/blob/1f97c96c9a8e3ac4c86f88dd3016a56588289ad4/PocketChange/src/main/scala/com/pocketchangeapp/snippet/AddEntry.scala

This a very simple example, so please look at the API docs for
StatefulSnippet for more details. The other approach (which I prefer) is to
use RequestVars. Combined with the SHtml.link method, you can do something
very similar to what you're doing in Wicket. Check out the Accounts snippet
in PocketChange:

http://github.com/tjweir/pocketchangeapp/blob/1f97c96c9a8e3ac4c86f88dd3016a56588289ad4/PocketChange/src/main/scala/com/pocketchangeapp/snippet/Accounts.scala

Lines 35-49 look like:

    User.currentUser.map({user =>
        user.accounts.flatMap({acct =>
            bind("acct", chooseTemplate("account", "entry", xhtml),
                 "name" -> Text(acct.name.is),
                 "description" -> Text(acct.description.is),
                 "actions" -> { link("/manage", () => acct.delete_!,
Text("Delete")) ++ Text(" ") ++
                               link("/editAcct", () =>
currentAccountVar(acct), Text("Edit")) })
          })
      }) openOr Text("You're not logged in")
  }

  object currentAccountVar extends RequestVar[Account]({
      Account.create.owner(User.currentUser.open_!)
    })
  def currentAccount = currentAccountVar.is

In particular, the line

link("/editAcct", () => currentAccountVar(acct), Text("Edit")) })

Sets up the link so that it loads the current account into the
currentAccountVar RequestVar when the link is clicked. That allows you to
pass info along with links (other transitions are possible). S.redirectTo
has an overload that takes a function, too, so you could similarly pass
state that way.

Derek

On Mon, May 18, 2009 at 9:04 AM, Willis Blackburn <
[email protected]> wrote:

>
> Hi all. I just picked up Lift and Scala a couple of weeks ago. I have
> been using mostly Wicket for the last couple of years. I have ordered
> David's Scala book and a Lift book from Amazon, but they're not here
> yet, so I am hoping that someone can help me with some conceptual
> issues.
>
> In Wicket, pages are components. Something that I like about Wicket is
> how easy it is to create a link to a related page: I can just pass
> state from the current page to the constrictor of the new page. For
> example, given a list of products, I can create a link to a product
> detail page like so:
>
> new Link("mylink") {
>    void onClick() {
>        setResponsePage(new ProductPage(product));
>    }
> }
>
> Basically the product page is returned from the link click. What is
> the recommended way of doing this in Lift? Should I just create a
> regular link to a URL and pass the product ID as a parameter? Or is
> there a better way which will allow me to avoid reloading the product,
> checking privileges, and so on?
>
> Thank you,
> Willis
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to