0
votes

inputmask in combination with gwt in the following way:


public class JQueryMask {

    public native static void setMask(Element elem,String mask) /*-{

        $wnd.jQuery(elem).find("input").inputmask(mask);
        $wnd.jQuery(elem).find("input").change(function(e) {

            });
    }-*/;

    public native static void removeMask(Element elem) /*-{
        $wnd.jQuery(elem).find("input").inputmask("remove");

    }-*/;


    public native static void setMaskWithGreadyFalse(Element elem,String mask) /*-{

    $wnd.jQuery(elem).find("input").inputmask({mask:mask,greedy:false});
    $wnd.jQuery(elem).find("input").change(function(e) {

            });

    }-*/;

}



This methods are called when the widget is initialized and everything works in the browser. The jQuery variable does not get initialized this produces the same exception:


console.log($wnd.jQuery());

also:

console.log($wnd.$());

Which is:


com.google.gwt.core.client.JavaScriptException: (null) @assembly.gwtlib.gui.plugins.JQueryMask::removeMask(Lcom/google/gwt/dom/client/Element;)([JavaScript object(77)]): null
    at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:249)
    at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:576)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNativeVoid(ModuleSpace.java:304)
    at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid(JavaScriptHost.java:107)
    at assembly.gwtlib.gui.plugins.JQueryMask.removeMask(JQueryMask.java)
    at assembly.gwtlib.gui.widget.input.Input.setMask(Input.java:54)
    at assembly.gwtlib.gui.widget.input.DateInput.(DateInput.java:76)
    ...
2

2 Answers

1
votes

GWTTestCases use their own HTML host page (because, well, technically, you may not even have one, or not a static one), so if you need jQuery for your tests, you have to load it from the tests themselves (e.g. using ScriptInjector, either from your test method or from gwtSetUp())

0
votes

Thanks to Thomas Broyer I have implemented the following code:

 Callback c=new Callback() {

        @Override
        public void onSuccess(Void result) {
             ScriptInjector.fromUrl("urlTo/jquery.inputmask.js").setWindow(ScriptInjector.TOP_WINDOW).setCallback(new Callback<Void, Exception>() {

                @Override
                public void onSuccess(Void result) {


                    //Your tests
                }

                @Override
                public void onFailure(Exception reason) {
                    reason.printStackTrace();
                    junit.framework.Assert.fail(reason.getMessage());


                }
            }).inject();

        }

        @Override
        public void onFailure(Exception reason) {
            reason.printStackTrace();
            junit.framework.Assert.fail(reason.getMessage());

        }
    };
    ScriptInjector.fromUrl("urlTo/jQuery-2.1.4.min.js").setWindow(ScriptInjector.TOP_WINDOW).setCallback(c).inject();//setWindow(ScriptInjector.TOP_WINDOW) is important