Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
47
rated 0 times [  49] [ 2]  / answers: 1 / hits: 34143  / 15 Years ago, thu, june 11, 2009, 12:00:00

I have a native Javascript method in one of my GWT Java classes, but I'm having trouble calling my Java methods from the native Javascript code. I tried to follow this as closely as I could, but I can't get it to work. I compiled it and ran it in Firefox, and the error console said Error: this.lc is not a function. I tried changing all the methods to public, but that didn't seem to make a difference. What am I doing wrong?



package com.proprintsgear.design_lab.client;
...
public class ValueBox extends HorizontalPanel {
...
private void fireChange() {
...
}

private void increaseValue() {
...
}

private native void addNativeMouseWheelListener(String id) /*-{
function mouseOverHandler(e) {
$wnd.addEventListener(DOMMouseScroll, scrollWheelMove, false);
}

function mouseOutHandler(e) {
$wnd.removeEventListener(DOMMouseScroll, scrollWheelMove, false);
}

function scrollWheelMove(e) {
if ($wnd.event || $wnd.Event) {
if (!e) e = $wnd.event;
if (e.wheelDelta <= 0 || e.detail > 0 ) {
$wnd.alert(DOWN);
} else {
[email protected]_lab.client.ValueBox::increaseValue()();
}
[email protected]_lab.client.ValueBox::fireChange()();
}
}

var box=$doc.getElementById(id);
box.addEventListener(mouseout,mouseOutHandler,false);
box.addEventListener(mouseover,mouseOverHandler,false);
}-*/;

More From » java

 Answers
27

In all the code I've done in the past, I've never used 'this' to identify my class, I have passed the class in.



Eg: Change this:



private native void addNativeMouseWheelListener(String id) /*-{
function mouseOverHandler(e) {
$wnd.addEventListener(DOMMouseScroll, scrollWheelMove, false);
}

function mouseOutHandler(e) {
$wnd.removeEventListener(DOMMouseScroll, scrollWheelMove, false);
}

function scrollWheelMove(e) {
if ($wnd.event || $wnd.Event) {
if (!e) e = $wnd.event;
if (e.wheelDelta <= 0 || e.detail > 0 ) {
$wnd.alert(DOWN);
} else {
[email protected]_lab.client.ValueBox::increaseValue()();
}
[email protected]_lab.client.ValueBox::fireChange()();
}
}

var box=$doc.getElementById(id);
box.addEventListener(mouseout,mouseOutHandler,false);
box.addEventListener(mouseover,mouseOverHandler,false);
}-*/;


To this:



private native void addNativeMouseWheelListener(ValueBox instance, String id) /*-{
function mouseOverHandler(e) {
$wnd.addEventListener(DOMMouseScroll, scrollWheelMove, false);
}

function mouseOutHandler(e) {
$wnd.removeEventListener(DOMMouseScroll, scrollWheelMove, false);
}

function scrollWheelMove(e) {
if ($wnd.event || $wnd.Event) {
if (!e) e = $wnd.event;
if (e.wheelDelta <= 0 || e.detail > 0 ) {
$wnd.alert(DOWN);
} else {
[email protected]_lab.client.ValueBox::increaseValue()();
}
[email protected]_lab.client.ValueBox::fireChange()();
}
}

var box=$doc.getElementById(id);
box.addEventListener(mouseout,mouseOutHandler,false);
box.addEventListener(mouseover,mouseOverHandler,false);
}-*/;

[#99336] Sunday, June 7, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
forrestn

Total Points: 552
Total Questions: 94
Total Answers: 101

Location: Sao Tome and Principe
Member since Thu, Apr 20, 2023
1 Year ago
;