0

I have Utility class as below.

class Utility{
  @Inject
  @Named("endpoint")
  private String endpoint; //generated only getter
}

I am configuring value for endpoint in the as below.

public class ConfigModule extends AbstractModule {
  @Override
  protected void configure() {
    bindConstant().annotatedWith(Names.named("endpoint"))
    .to("Endpoint URL");
  }
}

In my GWT class I am trying to get this value.

public class MyUIPanel extends Composite {
  @Override
  protected void onLoad() {
    Window.Location.assign(new Utility().getEndpoint());
  }
}

UI loaded properly with error coming up in browser console saying You are executing Names.named() in GWT code. GWT does not emulate enough of Java that will work.

Also tried to inject Utility class in MyUIPanel class using guice but getting below error at the time of building war Binding requested for constant key Key[type=java.lang.String, annotation=@com.google.inject.name.Named(value=CognitoEndpoint)] but no explicit binding was found.

Harsh Kanakhara
  • 909
  • 4
  • 13
  • 38

1 Answers1

0

Found out Guice cannot be used on client side.

To fetch static values inside our GWT Client Code, we can bind those values inside class extending AbstractGinModule class.

To fetch dynamic values from properties files, write logic on server side and get values on client side using GWT RPC.

Harsh Kanakhara
  • 909
  • 4
  • 13
  • 38
  • I would suggest to not use GIN, as it is no longer under active development and is not J2CL compatible. – El Hoss Nov 07 '22 at 09:13
  • I am not sure. I am new to GWT. I recently joined the project and found out GIN is already implemented and I am not allowed to change it. – Harsh Kanakhara Nov 07 '22 at 12:22