Richard Searle's Blog

Thoughts about software

Archive for the ‘lift’ Category

Surprising difference between Shtml ajaxButton and Shtml ajaxCheckbox

Posted by eggsearle on August 6, 2011

Consider the following code

 def clear = SHtml.ajaxButton("Clear", ()=> {
     this ! Clear

  def checkbox = SHtml.ajaxCheckbox(true, selected => {
    this ! SetScroll(selected)
  }, "id" -> check)

Note the Noop reference at the end of callback function for the ajaxButton to satisfy the signature: ()=>JsCmd

However the signature for the ajaxCheckbox callback is (Boolean) =>JcCmd. However, in this case the compiler accepts Unit as the “return” value.

This implies there is an implicit conversion from Unit to Noop, that is local to ajaxCheckbox!


Posted in lift, Scala | Leave a Comment »

Controlling jquery tab plugin add

Posted by eggsearle on July 4, 2011

The jquery tab plugin provides a means to dynamically add a tab, but without any evident mechanism to determine the id of the tab. My use case required the population of that panel using Lift  AJAX, which requires the id to identify the  html element to be modified.

Only the tabTemplate accepts parameters, so that mechanism does not suffice. The template mechanism is now depreciated, which would eliminate it from consideration even if the the panelTemplate accepted parameters.

The assigned id turns out to be the fragment id iff a fragment URL is specified on the add call. Specifying a full URL causes a sequential, jquery generated id to be assigned.

Dynamically creating the tab and populating can thus be done using

JsRaw("$('#tabs').tabs( 'add', '#" + id + "', 'title' )") &
SetHtml(id, <i>Id is{id}</i>)

Posted in jquery, lift | Leave a Comment »

Performance feasibility of “Real time” display via comet

Posted by eggsearle on June 4, 2011

Chat and stock tickers are the canonical Comet applications. The latter indicates that web applications might be able to implement “real time” applications that are currently the domain of Swing and SWT applications. For example: process control mimic panels, network status displays, etc.

Lift provides a very easy to use Comet implementation that is particularly well suited to these problem domains. A trivial test of feasibility was created from the Clock example code, modified as follows:

  • two actors per page
  • each actor updating 10 text labels
  • 10 Hz refresh

The test environment is a single dual core 2.8 Ghz processor, running both the Jetty server and the browser.

Chrome javascript console indicates each Comet request has ~ 14ms latency, which is impressive. 

The CPU load is much less impressive: > 50 % of a one core.   This is surprisingly large, but certainly acceptable for a direct replacement of a Swing/SWT application where the machine is dedicated to a single user.  The Jetty server load increases slowly with additional clients, allowing a dozen or so clients to be supported from a single server.  This is more than sufficient for the domains of interest.

Posted in lift, Scala | Leave a Comment »