Results 1 to 10 of 10

Thread: How to use evaluateJavaScript

  1. #1
    Senior Member
    Join Date
    Apr 2014
    Posts
    201

    How to use evaluateJavaScript

    Hi,
    I understand this concept and I have it working ok with a call to a simple javascript function (which I 'think' is server-side) but I have a few question:

    1. I assume the server-side javascript file is '.js' but how do I create a js file from the app builder? no matter where I click in the 'Files' section and choose 'new file', I always get a .prg file. I ended up creating the js file manually in the file system and then had to close + open the app to see the file under 'JavaScript Files' (clicking 'refresh' didn't work).

    2. Once I had the js file & named it properly I could call my function just fine using evaluateJavaScript but what makes this js server-side as it is just another js file in the same folder as my click-handler js file?

    3. Perhaps this will answer (2) - does evaluateJavaScript need the cloud server to work?
    I am not even sure that I am using the cloud server as I am running everything on my desktop as per a standard install - or do all web apps use the cloud server?

    4. Lastly, is there any way to debug server-side js files?

  2. #2
    Lianja Development Team barrymavin's Avatar
    Join Date
    Feb 2012
    Location
    UK, USA, Thailand
    Posts
    7,088
    Blog Entries
    22
    Hi Alia,

    We are on holiday until January 4th.

    1. When entering the filename postfix .js

    2. Clearly you are confused by this. I thought the doc was clear but obviously not. I will answer this in detail when I return from my holidays. This is for web/mobile apps so look at web app view and test in there using the JavaScript console if need be to test call your server-side functions, you don't use this functionality in a desktop app and that us not a client/server web or mobile app, it's all running in one exe.

    3. If you install a apass developer the cloud server is also installed on your development machine. Please open the web examples, view as web app then preview. Once you are familiar with these steps proceed to experiment with calling server side JavaScript if that's your server side scripting kanguage of choice.

    4. Test from the JavaScript console. No there is no remote debugger.
    Principal developer of Lianja, Recital and other products

    Follow me on:

    Twitter: http://twitter.com/lianjaInc
    Facebook: http://www.facebook.com/LianjaInc
    LinkedIn: http://www.linkedin.com/in/barrymavin

  3. #3
    Senior Member
    Join Date
    Apr 2014
    Posts
    201
    Thanks Barry, I'll pick up on this next week then.

    Regarding point 2 - I am only using the web app view and I do get the difference between server vs client-side. My client-side 'evaluateJavascript' call is working fine back to the server file but it will be great if you could expand a little on what actually makes the server file run server-side.

  4. #4
    Lianja MVP
    Join Date
    Feb 2012
    Location
    Berea, KY, USA
    Posts
    2,178
    My understanding: evaluateJavascript effectively does an RPC to the backend, sending the call back in a JSON string, getting the result, and sending it back in a JSON string. Barry has described this somewhere on the forum, IIRC.

    The client-side code is in LianjaHtmlClient*.js, which is present in minified form in the distribution. There are tools on the web for formatting minified scripts if you want to look at it.

    Hank

  5. #5
    Lianja Development Team barrymavin's Avatar
    Join Date
    Feb 2012
    Location
    UK, USA, Thailand
    Posts
    7,088
    Blog Entries
    22
    The framework is not minified unless the app is previewed in release mode. Looking at the framework will not help to prove that it's running server-side.

    Development mode and runtime views are a core requirement to understand how to build apps in Lianja.

    In this case the requirement of the OP to write in JavaScript on the client and the server is fully supported but not yet properly understood.

    I will answer this in more detail after my vacation,
    Principal developer of Lianja, Recital and other products

    Follow me on:

    Twitter: http://twitter.com/lianjaInc
    Facebook: http://www.facebook.com/LianjaInc
    LinkedIn: http://www.linkedin.com/in/barrymavin

  6. #6
    Senior Member
    Join Date
    Apr 2014
    Posts
    201
    Quote Originally Posted by HankFay View Post
    My understanding: evaluateJavascript effectively does an RPC to the backend, sending the call back in a JSON string, getting the result, and sending it back in a JSON string. Barry has described this somewhere on the forum, IIRC.

    The client-side code is in LianjaHtmlClient*.js, which is present in minified form in the distribution. There are tools on the web for formatting minified scripts if you want to look at it.

    Hank
    Hi Hank,

    I assume there is some JSON RPC going back to the server but I am not really concerned about that mechanism. I understand the concept of calling a server script from the client and I can see that evaluateJavacsript will allow js code on both sides to work just fine.
    What I don't understand is which files are sent to the client and which stay on the server because both are defined in app builder in exactly the same way so there is nothing so say which is a 'server' file and which is a 'client' file.

  7. #7
    Lianja Development Team barrymavin's Avatar
    Join Date
    Feb 2012
    Location
    UK, USA, Thailand
    Posts
    7,088
    Blog Entries
    22
    In development mode all JavaScript is referenced in the app or library directories as the "server" is embedded in the app builder.

    When you switch to web app view and then "preview" your server side JavaScript is called using a RPC to the cloud server.

    As explained in an earlier post you can use Lianja.evaluateJavaScript() or setup the exports.conf file to handle the mapping from client to server function calls.

    When using data binding you don't need to perform any CRUD operations programmatically as it is done for you.

    The only time I would perform evaluate() or evaluateJavaScript() RPCs is for validation or custom actions that require specialized CRUD code to be run on the server.

    When binding URLs to webviews you can use {...} macros which are substituted as a Webview is refreshed.

    The data binding hides a lot of the complexity of client/server operations.
    Principal developer of Lianja, Recital and other products

    Follow me on:

    Twitter: http://twitter.com/lianjaInc
    Facebook: http://www.facebook.com/LianjaInc
    LinkedIn: http://www.linkedin.com/in/barrymavin

  8. #8
    Senior Member
    Join Date
    Apr 2014
    Posts
    201
    Thanks Barry. I don't intend using this for simple data binding because, as you say, most of that is already handled. This will come in when we want to fire off some custom function in reaction to some event on a screen, or return more complex data to that screen.

    Could you perhaps point to a sample app where a button on a form uses evaluateJavascript to call a server function, where that server function reads a value from the database and returns it back to the form?
    This scenario actually what prompted my original question because although I got evalauteJavascript working (when returning simple string values), I had trouble when accessing the database object and I wasn't certain that the js as actually 'server' side.

  9. #9
    Lianja Development Team barrymavin's Avatar
    Join Date
    Feb 2012
    Location
    UK, USA, Thailand
    Posts
    7,088
    Blog Entries
    22
    Ok I'll put some small example app together to demonstrate this functionality and post it here.
    Principal developer of Lianja, Recital and other products

    Follow me on:

    Twitter: http://twitter.com/lianjaInc
    Facebook: http://www.facebook.com/LianjaInc
    LinkedIn: http://www.linkedin.com/in/barrymavin

  10. #10
    Lianja Development Team barrymavin's Avatar
    Join Date
    Feb 2012
    Location
    UK, USA, Thailand
    Posts
    7,088
    Blog Entries
    22
    Just to close this thread, there is an example app included in v2.1 that shows you how to make remote calls to server side JavaScript.
    Principal developer of Lianja, Recital and other products

    Follow me on:

    Twitter: http://twitter.com/lianjaInc
    Facebook: http://www.facebook.com/LianjaInc
    LinkedIn: http://www.linkedin.com/in/barrymavin

Tags for this Thread

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Journey into the Cloud
Join us