4 Replies Latest reply on May 7, 2015 11:33 AM by Juan Calderón

    DataBinding Injection

    Juan Calderón Newbie

      Sorry for my inexperience.

       

      I'm using Errai DataBinding as Standalone module and it is working fine.

       

      Now, I want to replace the manual set-up by Injection (@PostConstruct, @Inject, @Bound, @AutoBound, tec.), but it is not working.

       

      I already added the empty file ErraiApp.properties and the default beans.xml with bean-discovery-mode="annotated".

       

      Thanks a lot,

       

      Juan

        • 1. Re: DataBinding Injection
          Juan Calderón Newbie

          package org.yournamehere.client;

           

           

          import com.google.gwt.core.client.EntryPoint;

          import com.google.gwt.core.client.GWT;

          import com.google.gwt.user.client.ui.Button;

          import com.google.gwt.user.client.ui.Label;

          import com.google.gwt.user.client.ui.RootPanel;

          import com.google.gwt.event.dom.client.ClickEvent;

          import com.google.gwt.event.dom.client.ClickHandler;

          import com.google.gwt.user.client.ui.TextBox;

          import javax.annotation.PostConstruct;

          import javax.enterprise.context.Dependent;

          import javax.inject.Inject;

          import org.jboss.errai.databinding.client.BindableProxyLoader;

          import org.jboss.errai.databinding.client.api.DataBinder;

          import org.jboss.errai.ui.shared.api.annotations.AutoBound;

          import org.jboss.errai.ui.shared.api.annotations.Bound;

          import org.jboss.errai.ui.shared.api.annotations.Model;

           

           

          @Dependent

          public class MainEntryPoint implements EntryPoint {

           

           

              public MainEntryPoint() {

                 

                  // Errai Binding

                  BindableProxyLoader proxyLoader = GWT.create(BindableProxyLoader.class);

                  proxyLoader.loadBindableProxies();       

                 

              }

           

           

              @Inject @Model private Customer customer;

             

              @Inject @AutoBound private DataBinder<Customer> dataBinder;

              @Inject @Bound(property = "nom") private Label nameLabel;

              @Inject @Bound(property = "nom") private TextBox nameTextBox;   

           

           

             

              @Override

              public void onModuleLoad() {

                 

          //        this.nameTextBox = new TextBox();

          //        this.nameLabel = new Label("Two");

          //

          //        this.dataBinder = DataBinder.forType(Customer.class);

          //        this.customer = dataBinder.getModel();

                 

                  final Label label = new Label("Hello, GWT!!!");

                  final Button button = new Button("Click me!");

                 

                  button.addClickHandler(new ClickHandler() {

                      @Override

                      public void onClick(ClickEvent event) {

                          label.setVisible(!label.isVisible());

                      }

                  });

                 

                 

          //        DataBinder<Customer> dataBinder = DataBinder.forType(Customer.class);

          //        customer = dataBinder

          //        .bind(nameTextBox, "name")

          //        .bind(nameLabel, "name")

          //        .getModel();

                 

                  RootPanel.get().add(button);

                  RootPanel.get().add(label);

                  RootPanel.get().add(nameTextBox);

                  RootPanel.get().add(nameLabel);

              }

             

              @PostConstruct

              private void init() {

                  GWT.log("Just Hello Injection!");

              }

             

          }

          • 2. Re: DataBinding Injection
            Juan Calderón Newbie

            package org.yournamehere.client;

             

             

            import org.jboss.errai.databinding.client.api.Bindable;

             

             

            /**

            *

            * @author juan.calderon

            */

            @Bindable

            public class Customer {

              private String nom;

             

              public String getNom() {

                return nom;

              }

              public void setNom(String nom) {

                this.nom = nom;

              }

            }

            • 3. Re: DataBinding Injection
              Christian Sadilek Master

              Hi Juan,

               

              In previous posts, you wrote that you want to use Errai DataBinding as a standalone library since you didn't want to use other Errai libs. But now you want dependency injection which of course requires IOC.

               

              If the latter is the case now you will have to inherit either the errai-ioc or errai-cdi GWT module. You then no longer need the manual bootstrap logic described here: https://developer.jboss.org/thread/254203

               

              Cheers,

              Christian

              • 4. Re: DataBinding Injection
                Juan Calderón Newbie

                Hello Christian,

                 

                Yes, I guess I have to include "on demand" more Errai modules.

                 

                For many months Errai caught my attention but I was hesitant to include it in my development in order to avoid another layer, framework, etc; however, I'm finding that it is easy, stable and others advantages.

                 

                Thanks for your help.

                 

                Juan