0
votes

I am calling a javascript function from gwt client side using JSNI like follow:

anchor.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
               execute(notification.getActionCode(), notification.getParams());
            }
});

private static native String execute(String functionName, String params)/*-{
        try{
           $wnd[functionName](params);
        }catch(e){
            alert(e.message);
        }
}-*/;

My problem is that my javascript function contains window.open("ServletName?...."). When clicking on the anchor, the window opened with error below: The requested resource (/es/gwt/core/ServletName) is not available.

if i replace window.open("ServletName?....") by window.open("../../ServletName?...."), the window open successfully, but these javascript functions are used also outside gwt so i cant modify it .

I dont know why the part /gwt/core is being added to the url which is causing the problem. Is there a way in gwt before executing the javascript function, to extract its content and adding the "../.." before the url? i mean heaving the javascript function name, can we get its content before calling the execute function? in my case my javascript function is a follow:

function everlinked_AddSpace(spaceId){
        window.open('ELUtilities?Service=Space&action=homePage&SpaceId='+spaceId+'&Template=apps/everlinked/templates/spaces/space_main.htm','_blank');;
    }

i need to modify it in gwt client side and call it with the new modifications.

I appreciate if someone could help me.

1
I have updated my post. I hope it is clearer. I dont know if this is the right solution. If you have any better solution i will be grateful. - user2318955
Thank you Baadshah for your help. but where i should use the method getHostPageBaseURL() - user2318955
My jsni method is the one containing the url to be modified. if i get the base url by GWT.get...URL() how can i include it in my jnsi method? - user2318955
Either pass it as an argument of your method, or call it from JS using JSNI syntax: @com.google.gwt.core.client.GWT::getHostPageBaseURL(). - Andrea Boscolo

1 Answers

0
votes

I think you are trying to resolve your problem using a bad approach.

The easier way is to use an url re-writer, or to modify your web.xml url-pattern to route the relative path sent by your gwt app to the same servlet.

Probably you have in your web.xml something like this:

<servlet>
    <servlet-name>myservlet</servlet-name>
    <servlet-class>maynamespace.ServletName</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>myservlet</servlet-name>
    <url-pattern>/ServletName</url-pattern>
</servlet-mapping>

So you can add this block to your web.xml.

<servlet-mapping>
    <servlet-name>myservlet</servlet-name>
    <url-pattern>/es/gwt/core/ServletName</url-pattern>
</servlet-mapping>

Note that url-pattern has a very limited set of regular expressions (/path/* and *.ext), so in your case you have to write the full path.