Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Problem with JSNI call to Java Method in FormItem's setValue

    I tried to extend TextItem and overwrite its setValue method to call via JSNI a Java method.
    It succeeded with a static method but failed with a instance method.
    Running this code in Hosted Mode throws an exception:
    Uncaught JavaScript exception [Das Objekt unterstützt diese Eigenschaft oder Methode nicht.]

    Could anyone help me?

    Code:
    package de.auco.smartgwt.test.client;
    
    import com.smartgwt.client.util.SC;
    import com.smartgwt.client.widgets.form.fields.TextItem;
    
    public class CustomTextItem extends TextItem {
    	
    	static {
    		defineClass();
    	}
    	
    	
    	private final static native void defineClass()/*-{
    		$wnd.isc.defineClass("CustomTextItem", $wnd.isc.TextItem);
    		$wnd.isc.CustomTextItem.addProperties({
    			setValue: function(value) {
    				@de.auco.smartgwt.test.client.CustomTextItem::staticDoSomething(Ljava/lang/String;)(value);
    				this.@de.auco.smartgwt.test.client.CustomTextItem::instanceDoSomething(Ljava/lang/String;)(value);
    				this.Super("setValue", arguments);
    			}
    		});
    	}-*/;
    	
    	public static void staticDoSomething(String value){
    		SC.say("static method called");
    	}
    	
    	public void instanceDoSomething(String value){
    		SC.say("instance method called");
    	}
    	
    	protected CustomTextItem(String name) {
    		super(name);
    		setType("CustomText");
    	}
    }

    #2
    Have you read the basic gwt tutorial on JSNI? It explictly says that putting this.something in a function call will not work like you think it will.

    Work around is
    Code:
    var blah = this;
    		$wnd.isc.CustomTextItem.addProperties({
    			setValue: function(value) {
    				@de.auco.smartgwt.test.client.CustomTextItem::staticDoSomething(Ljava/lang/String;)(value);
    				blah.@de.auco.smartgwt.test.client.CustomTextItem::instanceDoSomething(Ljava/lang/String;)(value);
    				blah.Super("setValue", arguments);
    			}
    		});

    Comment

    Working...
    X