0

Call Java method through Javascript

asked 2010-08-29 04:26:17 +0800

samuele gravatar image samuele
24 2

Hi everybody and congratulation for this beautiful framework.
I need to call a java method in a Javascript ... is that possible??? I try this solution but it seems not to work

<button label="clic" action="onmousedown: send()" />
<script type="text/javascript">
function send(){
sendCommand(5,5);
}
</script>

<zscript>
void sendCommand(int mbox, int com){
//do some stuff
}
</zscript>


Is there anyway the possibility to implement onmousedown/onmouseup on a button?

Please give me an advice or an idea because i'm so frustrated.
Thanks in advice for your time and helps.

delete flag offensive retag edit

16 Replies

Sort by ยป oldest newest

answered 2010-08-29 08:46:57 +0800

caclark gravatar image caclark
1753 2 5
http://clarktrips.intltwi...

updated 2010-08-29 08:47:11 +0800

You using a controller via the apply attribute or a component subclass via the use attribute?

link publish delete flag offensive edit

answered 2010-08-29 09:00:50 +0800

samuele gravatar image samuele
24 2

I don't understand what are you meaning ...
but if you've any advice it will be more appreciate ... Thanks

link publish delete flag offensive edit

answered 2010-08-29 09:41:51 +0800

caclark gravatar image caclark
1753 2 5
http://clarktrips.intltwi...

I need to call a java method in a Javascript ... is that possible???

Why do you need to call a method directly from Javascript? Why not use an event like the MVC smalltalks illustrate?

link publish delete flag offensive edit

answered 2010-08-29 09:53:27 +0800

samuele gravatar image samuele
24 2

I need to control robot movements through buttons.
The problem is that button don't support onMouseDown/onMouseUp events ... the only way is to set an action in the relative button and write a script in Javascript.
But method that permit the robot's movement is written in Java and i need to execute calling it in the script ...
Is there another way?

link publish delete flag offensive edit

answered 2010-08-29 10:22:55 +0800

caclark gravatar image caclark
1753 2 5
http://clarktrips.intltwi...

The problem is that button don't support onMouseDown/onMouseUp events

If your UI is ZUML why don't you hook the onClick event and handle in what ZK calls a "composer?" I'd suggest reading the MVC smalltalks found on the small talks page

link publish delete flag offensive edit

answered 2010-08-29 12:38:56 +0800

samuele gravatar image samuele
24 2

Can you give me a sort of example to understand clearly? Thank you very much

link publish delete flag offensive edit

answered 2010-08-30 07:53:05 +0800

caclark gravatar image caclark
1753 2 5
http://clarktrips.intltwi...

go to the small talks page, click the "next 200" at the bottom, click ZK MVC Made Easy

link publish delete flag offensive edit

answered 2010-08-31 07:57:36 +0800

SimonPai gravatar image SimonPai
1696 1

Hi all,

If you really need to port a onMouseUp/onMouseDown event to server side, here is a sample to do it:

MouseDownButton.java

package samples.component;
public class MouseDownButton extends Button {
	static {
		addClientEvent(MouseDownButton.class, "onMyEvent", 0);
	}
}

zul:

<zk xmlns:w="client">
	<button label="Go" use="samples.component.MouseDownButton">
		<attribute w:name="onMouseDown"><![CDATA[
			this.fire('onMyEvent');
		]]></attribute>
		<attribute name="onMyEvent"><![CDATA[
			lb.value = "onMouseDown fired!";
		]]></attribute>
	</button>
	<label id="lb" />
</zk>

Regards,
Simon

link publish delete flag offensive edit

answered 2010-08-31 11:37:07 +0800

samuele gravatar image samuele
24 2

Thanks a lot for suggestions ....
Regards
Samuele

link publish delete flag offensive edit

answered 2011-08-03 07:57:41 +0800

creata87 gravatar image creata87
197 2

updated 2011-08-03 08:01:17 +0800

what about calling a javascript method from a java class? and i don't mean simple classic "alert". i have my own .js file and i wanna call/access the methods from inside a java controller.

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2010-08-29 04:26:17 +0800

Seen: 1,939 times

Last updated: Aug 15 '12

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More