Thursday, September 1, 2011

Re: Access static file from onModuleLoad() method

Thank you for your help.  This helped me get my source code to find my config.xml file.

For anyone else who has a similar problem, I also had to make a request for the file, then use the "getText" method, then I could read the file.  I could not just use the file based on the file's path.  See the example below.

        try {
            String fn = GWT.getModuleBaseURL() + "config.xml";
            RequestBuilder requestBuilder = new RequestBuilder(
                    RequestBuilder.GET, fn);
            try {
                requestBuilder.sendRequest(null, new RequestCallback() {
                    public void onError(Request request, Throwable exception) {
                        GWT.log("failed file reading", exception);
                    }

                    public void onResponseReceived(Request request,
                            Response response) {
                        result = response.getText();
                        Config graphConfig = new Config(result);
                        callToMethodThatUsesGraphConfig(graphConfig);
                    }
                });
            } catch (RequestException e) {
                GWT.log("failed file reading", e);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/L57Yoia4xQoJ.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment