i am using lift and scala to create a sample web app.i have two pages in my app. first one have one form which takes the ticket information from the user and while clicking submit it will call the snippet. i want to show my form values to the next page. i referred the question How to get parameters in an HTML page passed from a snippet with Lift framework but some problems with this. i tried the following code so far. in my first page Snippet:
class ticketDetailsResponse(
var source:String="",
var destination:String="")
object BookFirstCityTrain {
def render = {
val responseForm = new ticketDetailsResponse()
var from = ""
var to = ""
def process() {
responseForm.source = from
responseForm.destination = to
S.redirectTo("ConfirmTicket.html", () => showTicketDetails.ticketDetails(Full(responseForm)))
}
"name=source" #> SHtml.text(from, from = _) &
"name=destination" #> SHtml.text(to, to = _) &
"type=submit" #> SHtml.onSubmitUnit(process)
}
}
and my second page snippet
object showTicketDetails {
object ticketDetails extends RequestVar[Box[ticketDetailsResponse]](Empty)
}
class showTicketDetails {
def render = "*" #> {
showTicketDetails.ticketDetails.get.map { r =>
"#fromStation" #> r.source
"#toStation" #>r.destination
}
}
}
and i referred my second page snippet from view like this:
<div data-lift="showTicketDetails" >
From: <span id="fromStation"></span><br />
To: <span id="toStation"></span><br />
</div>
but its working perfectly when there is only one parameter. if i print the second parameter in the page ("#toStation" #>r.destination
) the first printed value is disappearing. only the last value is printing here. how can i print both of these. can anybody answer for me. some inputs will be valuable. Thanks!!!
You have to chain CSS selectors using the &
method.
showTicketDetails.ticketDetails.get.map { r =>
"#fromStation" #> r.source &
"#toStation" #> r.destination
}
Otherwise your code block only returns the last expression and discards the first one as a no-op.