Re Render HTML Template using Scala and Lift


In this section , I will explain how to re-render HTML Template without loading the browser . You can refresh HTML template without loading browser via AJAX using Scala and Ltft .
Lift provides SHtml.memoize which memoize the NodeSeq used in apply() and then call applyAgain() in an Ajax call .
You can re render a particular template part of HTML page or complete page .

1)Define Template

private def renderPageNotes = SHtml.memoize {
".itm *" #> notes.map { note =>
...................
}

2) Set template in RequestVar

object noteTemplate extends RequestVar(renderPageNotes)

3)Now add template into top- level snippet call (render)

def render = {
"#vlist *" #> renderPageNotes&
"#button [onclick]" #> SHtml.ajaxInvoke(() => {
SetHtml("vlist", noteTemplate.is.applyAgain)
})
}

First time , when you go to page , renderPageNotes will be loaded . When you make any changes and you want to
reflect these changes without reloading the browser , you can click on button which will re-render the page via AJAX .
MemoizedTransform will capture the most recently changes applied (for the Request scope) in your ajax call . Then “applyAgain()” will transform these changes into memoized view .

Advertisements

About Ayush Mishra

Ayush is the Sr. Software Consultant @ Knoldus Software LLP. In his 5 years of experience he has become developer with proven experience in architecting and developing web applications. Ayush has a Masters in Computer Application from U.P. Technical University, Ayush is a strong-willed and self-motivated professional who takes deep care in adhering to quality norms within projects. He is capable of managing challenging projects with remarkable deadline sensitivity without compromising code quality. .
This entry was posted in Agile, Java, Scala, Web. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s