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