On Sun, Sep 30, 2012 at 7:36 PM, Chenguang He <
gao...@gmail.com> wrote:
> Sorry, I forgot to attach the code.
>
> object jobDetail {
Don;t use an object, you a class, by using an object, you are having
just one instance of this snippet across your complete application,
that means that visiting this url with one parameter value, will show
up on another browser window with the same value. You use object only
when there is no value stored in the snippet (in practice, I hardly
ever use an object)
> var id = S.param("jobid")
and once you move to a class, you also don;t need to use a var here,
if yo uare not changing the value of id, you should use a val
> var theJob = Jobs.find(By(Jobs.id, id.open_!.toLong)).open_!
Same here, no need for a var.
And then there is the open_!, when you see in Lift method that ends
with _!, it means "don;t use unless you really know what you are
doing". It is not safe to use open_!, because if the S.param(jobid)
does not have a value, then you will see an ugly Null pointer
exception on the screen (not what most users want to see)
but then you may ak, what do I di? I want to get the value from the
Box, yo ucan do something like:
val theJob = id.map{ jobId => Jobs.find(By(Jobs.id, jobId.toLong) }
but I think that will give you a Box[Box[Jobs]], and you really just
want Box[Jobs], so you can use:
val theJob = id.flatMap{ jobId => Jobs.find(By(Jobs.id, jobId.toLong) }
The use of flatMap there basically gets rid of the outer Box.
>
> def render = "#title" #> <p><strong>{theJob.title}</strong></p> &
then you do things like:
def render = "#title" #> <p><strong>{theJob.map(_.
title.is)}</strong></p> &
theJob.map(_.
title.is) is a Box[String] but there are implicit
conversions in Lift that convert from a Box[String] to something that
can be use in css selectors.
Note how I added then .is after title, calling .is will give you the
raw type of the column, meaning, a String, an Int, etc
> "#location" #> <p>{theJob.location}</p> &
> "#duration" #> <p>{theJob.duration}</p> &
> "#req" #> <p>{theJob.req}</p> &
> "#cha" #> <p>{theJob.chas}</p> &
> "#resp" #> <p>{theJob.respons}</p> &
> "#apply [onClick]" #>
> SHtml.ajaxInvoke(()=>JsCmds.RedirectTo("/jobapply.html?jobid="+theJob.id))
>
> }
>
> i use
http://localhost:8080/jobDetail.html?jobid=2 to try to get the id=2
>
> But the page also return the job with id=1
>
If you are still having issues, please put together a sample app
https://www.assembla.com/wiki/show/liftweb/Posting_example_code
and I'll walk you through the steps to get it working as you want.
Regards,
Diego
> --
> --
> 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
>
>
>
--
Diego Medina
Lift/Scala Developer
di...@fmpwizard.com
http://www.fmpwizard.com