Velocity - call Servoy method from html area

Questions and answers on developing, deploying and using plugins and JavaBeans

Velocity - call Servoy method from html area

Postby Gordon McLean » Fri Aug 30, 2013 7:46 pm

Hi
I have used Velocity to render a small calendar inside a webclient app. The calendar is contained inside and html_area and works correctly as expected however there does not seem to be a way to make a function call from Velocity to Servoy. This can be done on render but not after the fact. Has anyone come up with a method where by you can call a function from the browser back to servoy on demand and more importantly from Velocity in this case ?

Best
Gordon
Gordon McLean
Clickdigital.com
Gordon McLean
 
Posts: 253
Joined: Wed Aug 03, 2005 12:24 pm
Location: UK

Re: Velocity - call Servoy method from html area

Postby ptalbot » Fri Aug 30, 2013 8:13 pm

I'm confused, you say your using Velocity inside a web client app... then you say you want Velocity to callback to Servoy.
But once the calendar is rendered, 'after the fact', as you say, it is rendered in the browser, so Velocity has nothing to do with it.
You can use the WebClientUtils to get a callback URL that you can pass to Velocity as-is and use it in your calendar scripts.
Patrick Talbot
Freelance - Open Source - Servoy Valued Professional
https://www.servoyforge.net
Velocity rules! If you don't use it, you don't know what you're missing!
User avatar
ptalbot
 
Posts: 1654
Joined: Wed Mar 11, 2009 5:13 am
Location: Montreal, QC

Re: Velocity - call Servoy method from html area

Postby Gordon McLean » Fri Aug 30, 2013 8:30 pm

Essentially I want to click on a link in the calendar and trigger a script in the Servoy form ?? I am sure this is simple I am just not seeing the how right now :( I did try and stick this into the html

<td class="off"><a href="javascript:testfunc('test')">26</a></td>

which appears on the status bar but does not actually do anything apparently

Best
Gordon
Gordon McLean
Clickdigital.com
Gordon McLean
 
Posts: 253
Joined: Wed Aug 03, 2005 12:24 pm
Location: UK

Re: Velocity - call Servoy method from html area

Postby david » Fri Aug 30, 2013 9:36 pm

More specifically, Patrick is saying you're looking for web client utils "generateCallbackScript()" which you can use to inject a callback to a servoy method in the html output of html areas.

Some good sample code on the forum. To get you started:

Code: Select all
/**
* Auto-hide/show fast find data entry
*
* @param {Boolean} firstShow form is shown first time after load
* @param {JSEvent} event the event that triggered the action
*
* @properties={typeid:24,uuid:"5D86C07E-1F37-4E4E-A7D8-48A56C71F347"}
*/
function FORM_on_show(firstShow, event) {
   if (firstShow && false) {
      var elem = plugins.WebClientUtils.getElementMarkupId(elements.btn_find) // element attaching callback to
      
      var script = plugins.WebClientUtils.generateCallbackScript(ACTION_find) //ACTION_find servoy method to run
      
      //rollover of fast find auto-pops up form
      plugins.WebClientUtils.executeClientSideJS("$('#" + elem + "').on('mouseover','span',function(){" + script + "});");
      
      //rollout of fast find hides form
      plugins.WebClientUtils.executeClientSideJS("$('#" + elem + "').on('mouseout','span',function(){alert('goodbye');});");
   }
David Workman, Kabootit

Image
Everything you need to build great apps with Servoy
User avatar
david
 
Posts: 1727
Joined: Thu Apr 24, 2003 4:18 pm
Location: Washington, D.C.

Re: Velocity - call Servoy method from html area

Postby Gordon McLean » Sun Sep 01, 2013 11:05 am

Thanks David/Patrick for the replies, there was in fact a spectacularly simple answer that I had overlooked. Essentially I used a template calendar rather than wasting my time growing a new one. I cut/pasted the code into a velocity template rendering the days for the given month - all works brilliantly fast as expected. When I came to attach methods to the href functions they failed

ie <a href="javascript:testfunc('hello')">$!number.format('#',$!record.row)</a>

Which should work as we all know !! The issue was the original file started

<!DOCTYPE html>
<!--[if lt IE 7]> <html class="lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
etc....

Remove the !DOCTYPE and the problem went away. Now Servoy triggers the scripts as expected :)

All the best and thanks for your inputs .....

Gordon
Gordon McLean
Clickdigital.com
Gordon McLean
 
Posts: 253
Joined: Wed Aug 03, 2005 12:24 pm
Location: UK


Return to Plugins and Beans

Who is online

Users browsing this forum: No registered users and 22 guests

cron