Dear Matt,
Thank you for responding and offering further help. I ended up getting
help from a Lift expert outside this forum to solve my this issue. I
am presenting below the solution, along with my understanding of how
it works, so that others can benefit.
The final HTML:
<form data-lift="form.ajax">
<div data-lift="PackageSearch.search">
<div id="memoizethis">
<input type="text" name="packagenumber"
placeholder="package number"/>
<input type="submit">
<div id="result">Your package number number will
be echoed here.</div>
<table class="table table-bordered table-hover
table-striped">
<thead>
<tr>
<th>Package Number</th>
<th>Package Owner</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</div>
</div>
</form>
</div>
The final code snippet:
object PackageSearch {
def populateTableWithPackageData = {
var packagenumber = ""
SHtml.idMemoize(body => {
val PackageData = Vector(
Vector("package48", "Alice"),
Vector("package49", "Bob")
)
"@packagenumber" #> text(packagenumber, s => packagenumber = s)
& // first arg is value that will in the html when
// the page first loads, and in subsequent reloads. Second arg
is a function, "will get some value and assign
// that value to the packagenumber variable. The function
represents what will happen when the form
// is submitted.
"type=submit" #> SHtml.ajaxOnSubmit(() => body.setHtml()) & //
redraws part of page that is
// contained in the #memoize div (because of the code in def
search below). The parts of the page
// outside of #memoize are not in the body variable.
"#result *" #> Text(packagenumber) &
"tbody tr *" #> PackageData.map { v => {
"td *" #> v
}
}
})
}
def search(in: NodeSeq): NodeSeq = {
val cssSel = "#memoizethis" #> populateTableWithPackageData
cssSel(in)
}
}
My understanding of this is as follows:
Using SHtml.idMemoize 'memoizes the contents of the div with id
#memoizethis' (because of this line: val cssSel = "#memoizethis" #>
populateTableWithPackageData). The 'body' variable thus contains the
html of the div tag and its contents, as well as the methods necessary
to redraw this html. When the page first loads, and on subsequent
submissions, the table is populated with the contents of the
PackageData variable. What is handy is that the ponumber variable
receives the text from the ponumber input field in the html form each
time the page is submitted, and so this can be used in a database
query to deliver different values to the PacakgeData variable and thus
the table within the #memoizethis element.
> You received this message because you are subscribed to a topic in the
> Google Groups "Lift" group.
> To unsubscribe from this topic, visit
>
https://groups.google.com/d/topic/liftweb/in8prxaZIgU/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to