How to call a function on SwingUtilities.invokeLater

Hi,

I need to call a function after onShow has passed, because it calls a javascript method using WebClientUtils, which btw is not called on the onShow of the form! I have another post about this, with no answer, unfortunately. :( viewtopic.php?f=22&t=15821

Now, I want to try to call that function using SwingUtilities.invokeLater to be sure it’s called after the current thread where onShow is called ends the calling. I can create a plugin from where to call invokeLater.

What suggestions do you have for me?

Thanks,
Bogdan.

you talk about webclientutils so i guess you are talking about the webclient?
the SwingUtilities is a big no go.
Maybe a scheduler? But what are you trying to do?

Hi,

I’ve wrote in this post, but didn’t get any response: viewtopic.php?f=22&t=15821

My main concerns are these:

  1. The plugins.WebClientUtils.addCallback generates a Wicket that don’t call the server.
  2. The plugins.WebClientUtils.executeClientSideJS is not called from onShow method of the current form.

I’m trying to fix the second one by calling the plugins.WebClientUtils.executeClientSideJS method on invokeLater. I’ve created this method in a plugin but can’t make it run:

	public void js_invokeCallbackLater(Function callback) {
		final Function callbackFunction = callback;
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				callbackFunction.call(null, null, null, null);
			}
		});
	}

And for the first issue I’m thinking to generate the Wicket code myself, I just hope I can manage it.

Although I appreciate any help that can make my work easier! :)

i dont really know that plugin but that callback is a piece of script that you just have to call yourself

so that callback code can inside a browser js function that you call somewhere in the browser, thats what it is meant for (you don’t have to generate wicket code your self, thats what the plugin does you just need to execute it in the browser)

that invoke later is a big no no. Dont do that it makes no sense what so ever. SwingUtilites is in the first place a Smart client function not a webclient function
Besides that calling it later makes no sense, because what is later? after the request is done??

If you are saying that in the if you do this in the onshow of your form:

application.output(“onshow called”);
plugins.WebClientUtils.executeClientSideJS(“alert(‘test’)”);

and you see that output and nothing happens in the browser then i guess the plugin has some bug or something
please make that known here: https://www.servoyforge.net/projects/webclientutils

I’m calling the Callback method like this:

	body += '\
	<script type="text/javascript" charset="utf-8"> \
		scheduler.showLightbox = function(reservation_id) { \
			' + plugins.WebClientUtils.addCallback(editReservation, ['reservation_id']) + ' \
		} \
		\
	</script>';

Actually I insert what it returns inside the javascript that will run in the browser. This is how I saw it must be done. It actually returns a Wicket code that should call my “editReservation” method on the server. But it doesn’t work.

About the invokeLater, in case the onShow is executed in the event thread in java, which I don’t know if it does, invokeLater ensures me that my execution will be done after the current call of onShow is done. The thing is that I have a test button on my form, and if I press it after the onShow finish to execute, my javascript is called using plugins.WebClientUtils.executeClientSideJS. That’s why I want to call it after onShow finish everything.

Yes, I don’t know if it is the correct approach, but just wanted to try and see what will be!

But thanks, I’ll check also on the link of plugin!

so that generates a piece of script that will create a function on the scheduler obejct that you created before
and if you call that function the script is not called on the server?

what is the output that you see in the browser?

again invokeLater is a SmartClient/SWING method it is NOT for the webclient, It is there to run in the SmartClient/Swing event thread
the webclient doesn’t have a swing event thread. again don’t use that code!!!

udrescu_bogdan:
About the invokeLater, in case the onShow is executed in the event thread in java, which I don’t know if it does, invokeLater ensures me that my execution will be done after the current call of onShow is done. The thing is that I have a test button on my form, and if I press it after the onShow finish to execute, my javascript is called using plugins.WebClientUtils.executeClientSideJS. That’s why I want to call it after onShow finish everything.

Instead of trying to hack down the Swing EDT with something that doesn’t belong here, maybe you could use some other event than the onShow, like an onRecordSelect event (and set a variable to true to call it only once for example)?
I’m not too sure what is not working in your code apart from that.

But what do you do with the body you constructed here exactly???
Actually, it shouldn’t contain the tags, and do you later call your scheduler.showLighbox(anId) later using plugins.WebClientUtils.executeClientSideJS() or what?

Have a look at the generated html source in your browser, it might give you a clue of what is not working in your case…

Hi Patrick,

Thanks for the response!

scheduler.showLightbox is called on the browser when user click on something, I just want that click to be delivered on the server.

Variable body contains a html/javascript page that is displayed in a field with type HTML_AREA.

I checked the html page and post what I saw wrong in my other post: http://www.servoy.com/forum/viewtopic.php?f=22&t=15821
This is what addCallback generates for me inside the previous script that I’ve posted earlier:

<script type="text/javascript" id="html"><![CDATA[/*>]]>*/</script>

To be more concise: I need executeClientSideJS to send information to javascript when one of my forms is displayed, so I can refresh some data inside the javascript objects that runs in the browser. And I need addCallback to send information from javascript to server, when the user do some action in the webpage!

Thanks!
Bogdan.

So what you want to do is create some push behavior from your page to the server, triggered by browser’s DOM event?
Are you sure your scheduler.showLightbox() function is called on event triggered by the web page?
For example if you do a simple alert() in this function, does this work?

You could also think of creating a web service instead declaring a ws_post in your form and then triggering your own call with an Ajax.post()…
Just some suggestions…

I’m off for a bit, but will see if I can try and reproduce in a sample solution later…

Yes, exactly! But I don’t know if the web service will fit for me :( because I have this calendar that I wrote about in the other post. When the user clicks on an item in the calendar I want to show a servoy form where he can fill in the data for that item.
I also checked if the javascript function is called using an alert() and it does. The alert popup appears on the screen.

On the other hand, the javascript calendar populated some divs to display the calendar nicely, but they are removed when I change the form. So each time the form is displayed, I need to send the data to the javascript scheduler object so it can populate again the

s are in this way the calendar will be displayed properly. This works very nice using executeClientSideJS, except on the onShow of the form, BUT when the onShow is called for the first time, it works also from there, too.

If you think it might help, I can try to put an online demo of the application so you can see how it behaves.

Thanks a lot,
Bogdan.