Rick,

Here's a simple example:

import net.liftweb._
import util._
import http._
import js._
import JsCmds._
import JE._
import scala.xml.NodeSeq

class Evently extends CometActor {

  // handle an incoming JSON event
  override def handleJson(in: Any): JsCmd = in match {
    case JsonCmd("pressed", _, key, _) => SetHtml("info", <b>You pressed
{key}</b>)
    case _ => Noop
  }

  def render =
  <div>
  <span id="info"/> <!-- A place to put stuff -->
  {
    Script(jsonInCode) // include the JSON callback
  }
   <input type="text" onkeypress={jsonCall("pressed",
JsRaw("event.which")).toJsCmd}/>
  </div>
}

So, the handleJson message gets called on the server whenever a key is
pressed on the client (this example works in non-IE browsers, but that's
just 'cause I'm using event.which rather than event.keyCode).

Hope this helps.

Thanks,

David


On Wed, Feb 24, 2010 at 8:23 AM, Rick R <[email protected]> wrote:

> I have a textarea in which I process onKeyUp and onKeyDown commands.
> The handlers for such things are custom javascript.
> I would like to invoke functions in a Comet LiftActor /
> ListenerManager via these custom javascript functions. Is there
> documentation on the recommended way to do so?
>
> It looks like I will have to define the functions within a render call
> and use the SHtml.ajaxCall function, since the destination url is
> randomized.  I am just wondering what would be the idiomatic way to do
> this.
>
> This is for a chat style app which processes/distributes data by the
> keystroke rather than by a  line/post command.
>
>
> I'm open to any ideas / alternate suggestions.
>
> Thanks,
> Rick
>
> --
> 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]<liftweb%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/liftweb?hl=en.
>
>


-- 
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Surf the harmonics

-- 
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.

Reply via email to