Use Errai Ui with GWT

2019-07-29 15:21发布

I'd really like to use Errai UI(3.2.4) in my GWT (2.8) application. I already have one setup with an EntryPoint implementation and an onModuleLoad. I have restGWT setup and interacting with my server (which uses Jersey).

All of the documentation I find assumes that you are building a full-on Errai project, starting from scratch using the forge addon thing. I'm not. I just want to use the templating stuff and data-binding. I'm working with a barebones setup and I can't even make a label show in my app.

I have this GWT entry point:

public class App implements EntryPoint  
{  
    @Inject  
    private ApplicationContainer applicationContainer;  

    public void onModuleLoad()  
    {  
        RootPanel.get("root").add(applicationContainer);  
    }  
}  

And the ApplicationContainer:

@Templated  
public class ApplicationContainer extends Composite  
{  
    @DataField  
    private Element applicationContainer = DOM.createDiv();  


    @PostConstruct  
    public void init()  
    {  
        GWT.log("Initializing");  
    }  
}  

And it's accompanying template:

<div id="applicationContainer" data-field="applicationContainer">  
    Application Container  
</div>  

I should see "Application Container" in the browser, but I get this error in the browser console:

ComplexPanel.java:96 Uncaught TypeError: Cannot read property 'removeFromParent_0_g$' of undefined

The widget and the template are named the same and in the same package. My widget is created just like the documentation shows: http://erraiframework.org/getting-started/index.html#ErraiUIPage

Can someone tell me what I'm missing here? Examples for this are very minimal, and they all assume a complete Errai project. Do I still need an @EntryPoint? Do I need @PostConstruct? Is Errai even designed to work like this?

Thanks for any help.

标签: java gwt errai
2条回答
叼着烟拽天下
2楼-- · 2019-07-29 15:54

Yes, the @EntryPoint annotation is important and I'm not sure you'll be able to mix up part of this framework with some other approach. It doesn't mean you need to use all the modules, but you should rather follow the Errai's guidelines if about the part you use.

Please see example entry point here: https://github.com/errai/errai/blob/3.2.4.Final/errai-demos/errai-jpa-demo-todo-list/src/main/java/org/jboss/errai/demo/todo/client/local/ClientEntryPoint.java

You'll find also more examples from the path .../3.2.4.Final/errai-demos/

Above is about Errai 3.x. Please also note that Errai 4.x brings some changes if it is just about the Errai UI. It's nicely described here: http://errai-blog.blogspot.com/2016/04/errai-400beta1-released.html

Now your @Templated bean do not need to extend Composite. The root element of the template is accessible as a @DataField etc.

Hope you'll find it helpful. Good luck!

查看更多
男人必须洒脱
3楼-- · 2019-07-29 15:54

The answer to your questions is here: https://github.com/errai/errai-tutorial

You basically need to migrate your app to use Maven so you get the dependencies right first, then use the POM in this project and snap it in your project.

Then you can include a Bootstrap file to add a @EntryPoint class however this is not necessary you can just add a Page in the client path e.g.:

com.mycompany.app.client
-->MyPage.html
-->MyPage.java

Where the java file here contains the default page, i.e.

@Dependent
@Templated
@Page(role = DefaultPage.class)
public class MyPage extends Composite{}
查看更多
登录 后发表回答