Is it Safe for a Class in Server package to access a method in Client package in GWT?

StackOverflow https://stackoverflow.com/questions/22839955

  •  27-06-2023
  •  | 
  •  

Question

Ok, I am uisng GWTP, it got Client, Server & Shared package.

I have a Util class in client.

my.client.Util.java{
  public static String method1();
  //more methods here
}

In server i have

my.server.GetDataActionHandler{
    ///Should I do like this
    String s=my.client.Util.method1();
}

Is it safe to do that or I should put Util into shared package, like this

my.shared.Util.java{
  public static String method1();
  //more methods here
}

What is the different if we put a Util in shared package? is it safer or any other good reasons?

Was it helpful?

Solution

client is as safe as shared, these are just names and conventions.

By placing your class in client though, you lose the indication that you're using it also on the server side, where client-specific code won't run.

By placing it in shared, you're signaling to yourself that you should make sure the code your put in the class can effectively be used in both the client and the server.

OTHER TIPS

Read here about GWT MVP atchitecture

Read more here about GWT Architectural Perspectives

Accessing client side code from server side will become your code tightly coupled. Shared package is used for this purpose but still its not for any UI specific code. Shared packages is used to define some DTO (Data Transfer Object) and Utility classes.

There is no meaning of accessing any GWT UI specific utility classes at server side.

Try to decouple your code in such way if in future you want to use your server side classes for Swing application or any other web application other than GWT then you can easily incorporate it. Think about it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top