0

I am new to GWT and I need to reslove this problem. I need to create a widget with gwt-links. To make it happened, I need to fetch some data from an ontology, and then based on the result, create the graph. The problem is that, when I mix java code with gwt code it doesn't want to compile.

The question is, how do I create a widged explained above that will be placed in a http page?

The code looks like this now :

public class Example1 {

    @Override
    public void draw() {

        // Create the elements

        String ontology = Ontology.get(1);

        Widget labelHello = new BoxLabel(ontology);
        controller.addWidget(labelHello,25,115);


        // Add DnD logic
        PickupDragController dragController = new PickupDragController(controller.getView(), true);
        dragController.makeDraggable(labelHello);


    }


    public Widget asWidget() {
        return controller.getView();
    }

}

the Ontology.get() doesn't want to compile.

1
  • Could you provide a stack trace ? Commented Sep 26, 2013 at 6:47

3 Answers 3

1

GWT can't compile just any java code.

These are the packages that are emulated by GWT: pls read

The code that can't be translated to javascript, (the stuff that is not emulated) you must handle on the server side.

Sign up to request clarification or add additional context in comments.

3 Comments

In most case you can reimplement the code that can't be translated to javascript (i.e. libs like StringUtils) in your client code.
Yes you are right. Sometimes it's easier to just move this code if possible on the server side.
My guess was that @user2816447 was not aware of the fact that it's not possible to compile any java library to javascript.
1

GWT projects uses three packages (by default)

com.myapp.client
com.myapp.shared
com.myapp.server

By default everything within the shared and client package will be compiled to JavaScript. Every Class, which is imported into a Class, which is inside the shared and client package must be:

  1. emulated by GWT
  2. Compilable to GWT (and inside the client or shared package)
  3. Compilable to GWT (and the package must be whitelists in *.gwt.xml)

Uf you code ISolver can be compiled to JavaScript you will have to create a module.gwt.xml and inheritt your project from this module. This may enable the GWT-compiler to compile ISolver (and its implementation) to JavaScript.

If your code can't be compiled to GWT you will have to write a remote-service to make the calculation.

2 Comments

Thank you for the answer. Looks like remote service is the solution. IF it is on the server side, can it return/pass an gwt object ( a widget) to be later translated to javascript and placed on a page?
No, you should create the Widget at clientside and set the values after you get them from the server. You also can ask the server for the values and create the widget in the success-handler.
0

I don't really want to compile the code to javascript. All i want to do is to create a GWT widget ( which is a graph).

To create the widget, I need to do some calculations and repository fetch. I dont want to translate it( repository fetching), I just need to use it in order to create the model of the graph.

Basically, this is something I want to do:

String l = Repository.getLabel(); // Some advanced calculations that use many JavaSE classes;
GWTWidget widget = new GWTWidget(l);  // widget, that will be displayed on a page.

but when I put something in method onModuleLoad it doesn't compile.

This is probably a simple question, but I'm not really related with GWT and I'm forced to remake someone's work.


 public void onModuleLoad() {
        System.out.println("tes");
        VerticalPanel mainPanel = new VerticalPanel();
        RootPanel.get().add(mainPanel);

        //
        ISolver solver = null;
        System.out.println("TEST2");
    }
ERROR: Line 53: No source code is available for type pr.ISolver; did you forget to inherit a required module?
  ERROR: Unable to find type 'client.Link'
    ERROR: Hint: Previous compiler errors may have made this type unavailable

and other lines sthat start with " No source code..".

ISolver is an interface, but I dont want to translate it. I want to use it for calculations.

3 Comments

pls post the exception
The thing is that Java is translated to Javascript, that's how GWT works, that's why the browser executes a GWT app without a plugin.
But if you add this to the onModuleLoad() you are compiling it to JavaScript.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.