Re: [Lift] How to execute client-side js from ajax callback?

2009-11-18 Thread Eros Candelaresi
Hi,

I ran into the same problem. The Alert case class takes only a string.
|case class Alert(val text : String 
http://java.sun.com/javase/6/docs/api/java/lang/String.html)| |

|I.e. the result of getWidth is quoted such that it remains a plain 
string when it is evaluated on client side. Best thing would be if Alert 
was changed to accept a JsExp as parameter, then your code would work.

A (somewhat unpleasent) workaround would be:
|/* not checked for syntax */
def alert(what: JsExp) = {
  JsRaw(alert( + what.cmd + ););
}
|
Maybe someone knows a more elegant way though.

Regards,
Eros

jhonig wrote:
 Hi All,

 I am trying to execute a local (ie: defined in the template)
 javascript function from an Ajax
 callback.  This is the callback:

 def testAjax2 (theXhtml : NodeSeq) : NodeSeq =
 {
 def getWidth () =
 {
 Call (getAvailableWidth).cmd;
 }

 def alert (what : String) =
 {
 Alert (what);
 }

 bind (fgh, theXhtml, key - SHtml.a (() = {alert
 (getWidth ());}, Text (Click me)));
 }

 The alert is displayed, but the text it shows is getAvailableWidth
 ().  I have been trying dozens
 of variations, but didn't get the result I am hoping for; it's always
 the string...

 What am I doing wrong?

 --

 You received this message because you are subscribed to the Google Groups 
 Lift group.
 To post to this group, send email to lift...@googlegroups.com.
 To unsubscribe from this group, send email to 
 liftweb+unsubscr...@googlegroups.com.
 For more options, visit this group at 
 http://groups.google.com/group/liftweb?hl=.


   

--

You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to lift...@googlegroups.com.
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=.




Re: [Lift] Re: How to execute client-side js from ajax callback?

2009-11-18 Thread Eros Candelaresi
Hi,

as a rule of thumb: when the Lift class expects a String as parameter, 
this will also be a String on JavaScript side. Alert expects a String, 
so it does not matter if the string is Hello World!, 
getAvailableWidth() or anything else. By the time it reaches the 
client, Lift has already made sure that it is a plain text string. I 
guess, Run() is one of very little exceptions.

On the other hand, when a Lift class takes a JsExp as parameter, the 
expression will be sent to the client as JavaScript code and then be 
executed there.
Example:
Stringify(getWidth())
would result in the following JavaScript code:
JSON.stringify(getAvailableWidth)

It got pretty clear to me when I started looking at the source code. 
Most of those JavaScript wrapper classes are simply one-liners that 
create a small piece of JavaScript code.

Btw, I found a nicer solution for your alert problem:
def alert(what: JsExp) = {
  JsFunc(alert, what)
}

Regards,
Eros



jhonig wrote:
 Hi Eros,

 Thanks for your reply!

   
 I ran into the same problem. The Alert case class takes only a string.
 |case class Alert(val text : String
 http://java.sun.com/javase/6/docs/api/java/lang/String.html)| |

 |I.e. the result of getWidth is quoted such that it remains a plain
 string when it is evaluated on client side. Best thing would be if Alert
 was changed to accept a JsExp as parameter, then your code would work.
 

 I will try your workaround, but I still don't understand how
 Javascript
 expressions are evaluated.  From what you say, the result of getWidth
 would be converted to getAvailableWidth () and never actually run.
 But then Alert (Run (what)) should work, shouldn't it?  But the
 results
 are exactly the same!

 Do you know of any comprehensive description of how such expressions
 are evaluated by Lift?

 Job

 --

 You received this message because you are subscribed to the Google Groups 
 Lift group.
 To post to this group, send email to lift...@googlegroups.com.
 To unsubscribe from this group, send email to 
 liftweb+unsubscr...@googlegroups.com.
 For more options, visit this group at 
 http://groups.google.com/group/liftweb?hl=.


   

--

You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to lift...@googlegroups.com.
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=.




Re: [Lift] Re: Where are the dragons hiding?

2009-11-18 Thread Eros Candelaresi
Hi,

Marius wrote:
 On Nov 18, 6:31 pm, Paul Butcher p...@paulbutcher.com wrote:
   
 I'm seriously considering Lift for a new project. I know what the
 benefits of Scala and Lift are (that's why I'm seriously considering
 this as a route forwards :-) What I'm wondering is whether there are
 any lurking nasties that I should be aware of (so that I can avoid
 learning about them the hard way).
 

 Not sure if there is any. One thing though Lift's session state is
 kept in memory and not serialized in the DB. Session serialization is
 a bit tricky since we keep the bound functions on the session state.
 Those functions are in many cases anonymous function that may hold
 other references which are not serializable. Even if everything is
 serializable using Java serialization is likely suboptimal. But
 keeping the sessions in memory and have a session affinity load
 balancing is a very good choice from performance perspective.

   
There are people playing around with Terracotta 
(http://www.terracotta.org/web/display/orgsite/Platform) and Lift. There 
seems to be some success regarding actors running on a cluster. No idea 
if Terracotta plays well with Lift session handling. There's only an 
unanswered post in the ML archive on that.

Regards,
Eros

--

You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to lift...@googlegroups.com.
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en.




[Lift] Re: How to use Box

2009-11-16 Thread Eros Candelaresi

Hi again,

sorry for answering my own post. Should have looked at the documentation 
first.

It's as simple as:

val username = User.find(id).choice( Full(_.name) )( Full(User not 
found) ).open_!
(not checked for syntax!)

Regards,
Eros


Eros Candelaresi wrote:
 Hi,

 I like the getOrElse way of accessing data very much as it allows to 
 handle non-existing values with very little code. However, I am still 
 looking for a more elegant replacement for this:

 val username = User.find(id).getOrElse(User.create.name(User not 
 found)).name

 Ok, this is very short already. But still it feels wrong to create an 
 instance of User (AFAIK a rather expensive operation, especially when 
 used while creating lists) when all I need is a string.

 How do you guys handle such cases?

 Regards,
 Eros


 David Pollak wrote:
   
 On Thu, Nov 12, 2009 at 5:53 AM, Ferdinand Chan unique...@gmail.com 
 mailto:unique...@gmail.com wrote:


 David,

 Thanks for the blog entry and it does a great job in explaining how
 Option works and how to use it.

 May I suggest that we add a link to this blog post on Lift Wiki???
 Correct me if I'm wrong but I think most newbie to Scala / Lift may
 wonder and puzzle how Box / Option works.

 I know you're very busy and with your permission, I'm willing to add
 this to the wiki


 No permission required.  Please add whatever valuable things to the 
 Lift wiki (the one at http://wiki.github.com/dpp/liftweb )
  


 Oh, and I think I really need to tweak my mind a bit and start to
 think in a more functional / scala way


 Yeah... it's a change in mindset, but I think you'll find the change 
 to be welcome in terms of your own productivity, your ability to read 
 others' code, and overall code stability.

 Thanks,

 David
  


 Cheers,

 Ferdinand

 On Nov 12, 6:55 am, David Pollak feeder.of.the.be...@gmail.com
 mailto:feeder.of.the.be...@gmail.com
 wrote:
 
 http://blog.lostlake.org/index.php?/archives/50-The-Scala-Option-clas...
 
  The for comprehension is your friend.
 
 
 
 
 
  On Wed, Nov 11, 2009 at 2:40 PM, Ferdinand Chan
 unique...@gmail.com mailto:unique...@gmail.com wrote:
 
   Wondering what's the normal practice of using a Box. As a Java
   developer, I always want to get the boxed value by a method named
   Value like
 
   val optionalContent = Full(This is optional)
 
   Log.info(  The optional content is  + optionalContent.value)
 
   But I know its not a valid way to do so in lift ( same for
 Option in
   Scala)
 
   From the book programming in Scala , there's an example
 
   val withDefault: Option[Int] = Int = {
   case Some(x) = x
   case None = 0
   }
 
   which suggest the use of match to retrieve the value of the boxed
   content. It make sense to me and I'm totally agree with the
 advantage
   of using match + option (Box) combination.
 
   However, as a newbie to Scala, I'm so tempted to use something
   like .Value to retrieve the box value .
 
   So, what's the normal way to use Box ?? Could someone kindly
 provide
   some example on how to use ? I tried to look through some
 source code
   of Lift but its not easy for a newbie :)
 
   Thanks
 
  --
  Lift, the simply functional web frameworkhttp://liftweb.net
 http://liftweb.net
  Beginning Scalahttp://www.apress.com/book/view/1430219890
 http://www.apress.com/book/view/1430219890
  Follow me:http://twitter.com/dpp
  Surf the harmonics




 -- 
 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 liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: How to use Box

2009-11-15 Thread Eros Candelaresi

Hi,

I like the getOrElse way of accessing data very much as it allows to 
handle non-existing values with very little code. However, I am still 
looking for a more elegant replacement for this:

val username = User.find(id).getOrElse(User.create.name(User not 
found)).name

Ok, this is very short already. But still it feels wrong to create an 
instance of User (AFAIK a rather expensive operation, especially when 
used while creating lists) when all I need is a string.

How do you guys handle such cases?

Regards,
Eros


David Pollak wrote:


 On Thu, Nov 12, 2009 at 5:53 AM, Ferdinand Chan unique...@gmail.com 
 mailto:unique...@gmail.com wrote:


 David,

 Thanks for the blog entry and it does a great job in explaining how
 Option works and how to use it.

 May I suggest that we add a link to this blog post on Lift Wiki???
 Correct me if I'm wrong but I think most newbie to Scala / Lift may
 wonder and puzzle how Box / Option works.

 I know you're very busy and with your permission, I'm willing to add
 this to the wiki


 No permission required.  Please add whatever valuable things to the 
 Lift wiki (the one at http://wiki.github.com/dpp/liftweb )
  


 Oh, and I think I really need to tweak my mind a bit and start to
 think in a more functional / scala way


 Yeah... it's a change in mindset, but I think you'll find the change 
 to be welcome in terms of your own productivity, your ability to read 
 others' code, and overall code stability.

 Thanks,

 David
  


 Cheers,

 Ferdinand

 On Nov 12, 6:55 am, David Pollak feeder.of.the.be...@gmail.com
 mailto:feeder.of.the.be...@gmail.com
 wrote:
 
 http://blog.lostlake.org/index.php?/archives/50-The-Scala-Option-clas...
 
  The for comprehension is your friend.
 
 
 
 
 
  On Wed, Nov 11, 2009 at 2:40 PM, Ferdinand Chan
 unique...@gmail.com mailto:unique...@gmail.com wrote:
 
   Wondering what's the normal practice of using a Box. As a Java
   developer, I always want to get the boxed value by a method named
   Value like
 
   val optionalContent = Full(This is optional)
 
   Log.info(  The optional content is  + optionalContent.value)
 
   But I know its not a valid way to do so in lift ( same for
 Option in
   Scala)
 
   From the book programming in Scala , there's an example
 
   val withDefault: Option[Int] = Int = {
   case Some(x) = x
   case None = 0
   }
 
   which suggest the use of match to retrieve the value of the boxed
   content. It make sense to me and I'm totally agree with the
 advantage
   of using match + option (Box) combination.
 
   However, as a newbie to Scala, I'm so tempted to use something
   like .Value to retrieve the box value .
 
   So, what's the normal way to use Box ?? Could someone kindly
 provide
   some example on how to use ? I tried to look through some
 source code
   of Lift but its not easy for a newbie :)
 
   Thanks
 
  --
  Lift, the simply functional web frameworkhttp://liftweb.net
 http://liftweb.net
  Beginning Scalahttp://www.apress.com/book/view/1430219890
 http://www.apress.com/book/view/1430219890
  Follow me:http://twitter.com/dpp
  Surf the harmonics




 -- 
 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 liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: [Sorta Not Related] Ummm.. at the risk of crashing my browser........

2009-10-16 Thread Eros Candelaresi

Hi,

I'm be interested too. So if you still have invitations left... :)

Regards,
Eros

Jim Barrows schrieb:
 Who wants a wave invite?
 Not sure how long Google will take to process them.. but I have some!

 I just added the lifehack list to my wave account, and I think firefox
 nearly died.  Quite amusing.. in many ways

 -- 
 James A Barrows


 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Script merge similar to head merge?

2009-10-11 Thread Eros Candelaresi
Hi group,

for a project I am working on interactive forms, i.e. fields 
appear/disappear/enable/disable based on the user input in other fields. 
Everything is heavily JavaScript event based, so I am currently writing 
a small library that simplifies the task of binding JS events and 
composing event handlers. My library follows a component based approach, 
so there is a component for text input fields, for dropdowns, etc. Each 
component is able to create its own HTML and JS code.

And now here is my problem: every component ends up with its own 
script section in the HTML output (see example below). Although this 
is not a real problem it's still rather ugly. One solution could be to 
have a JS manager object that collects all JS from the input components 
and creates one single script secion on LiftSession.onEndServicing. 
But I am not sure if my Lift knowledge suffices for that. Also I don't 
want to reinvent the wheel. Is there something that I missed? Some kind 
of script merge?

Kind regards,
Eros Candelaresi


--snip

   script  type=text/javascript
//![CDATA[

jQuery(document).ready(function() 
{jQuery('#'+'F766360102107OWD').change(function() 
{lift_ajaxHandler('F766360102108BAJ=' + jQuery('#'+'F766360102107OWD').val(), 
null, null);});});

// ]]
/scriptscript  type=text/javascript
//![CDATA[

jQuery(document).ready(function() 
{jQuery('#'+'F7663601021044I3').change(function() {alert('foo');});});

// ]]
/scriptscript  type=text/javascript
//![CDATA[


// ]]
/scriptscript  
type=text/javascriptsrc=/classpath/js/jquery-autocomplete/jquery.autocomplete.js
  
view-source:http://localhost:8080/classpath/js/jquery-autocomplete/jquery.autocomplete.js/scriptlink
  href=/classpath/js/jquery-autocomplete/jquery.autocomplete.css  
view-source:http://localhost:8080/classpath/js/jquery-autocomplete/jquery.autocomplete.csstype=text/cssrel=stylesheet/script
  type=text/javascript
//![CDATA[
jQuery(document).ready(function() 
{jQuery('#'+'F766360102105WM1').autocomplete('/ajax_request?F766360102106IRY=whatev',
 {'onItemSelect': function() 
{jQuery('#'+'F766360102103OJK').html(jQuery('#'+'F766360102105WM1').val());}});});


// ]]
/script
--/snip





--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---