Hello,
> I have HTML to print out expenses for a given month (i.e. URL = .../
> month/12):
>
> <lift:MonthPage.summary>
> ...
> <thismonth:expenseitem>
> <tr>
> <td><month:item /></td>
> <td align="right"><month:amount /></td>
> </tr>
> </thismonth:expenseitem>
> ...
> </lift:MonthPage.summary>
>
> The area I'm having problems with is the code to drive the above
> HTML. I need something like:
>
> class MonthPage {
> def summary( xhtml : NodeSeq ) : NodeSeq = S.param("month") match {
> case Full(m) => {
> val allexpenses : NodeSeq = expensesformonth.flatmap({ month =>
> bind("month", chooseTemplate("thismonth", "expenseitem",
> xhtml),
> "name" -> Text( month.item ),
> "amount" -> Text( month.amount )
> )
> })
> bind("thismonth", xhtml, "expenseitem" -> allexpenses)
> }
> case _ => {
> Text( "Not a valid month." )
> }
> }
> }
I think you're almost there.
Try making the "allexpenses" val a function (def) NodeSeq => NodeSeq. The
function takes the "template" of the month and returns it with bound values. So
something like:
class MonthPage {
def summary( xhtml : NodeSeq ) : NodeSeq = S.param("month") match {
case Full(m) => {
def allexpenses(expenseTemplate: NodeSeq): NodeSeq =
expensesformonth.flatmap({ month =>
bind("month", expenseTemplate,
"name" -> Text( month.item ),
"amount" -> Text( month.amount )
)
})
bind("thismonth", xhtml, "expenseitem" -> allexpenses _)
}
case _ => {
Text( "Not a valid month." )
}
}
}
No need to lookup the right template then using chooseTemplate, as the method
receives the appropriate xhtml.
--
Adam--
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.