简体   繁体   中英

Why an object, created in client side, is not accessible from server side in GWT development mode?

I am running my GWT application in development mode. In my client side code (Classes that implements Entrypoint), I have created one object and assigned it to a static variable of another class (Suppose Class A).

Now, expectedly I can access the object by he reference of the static variable of class A from anywhere from the client side but can't access it from the server side code. Can anybody explain me why I can't access the object the same way I accessed it from client side code as both the client and server running within the same session scope on the same JVM in development mode.

Your client side code and server are not running inside one JVM, even in a dev mode. As you know, GWT client code is compiled into Javascript code. So updating some static field is eventually compiled into updating some property of Javascript object. In can not be accessed by Server side code for obvious reasons.

Dev mode in GWT is smart enough and not allows to mix Server and Client static variables to avoid confusion after deploying compiled version to your server.

You can not access client side classes directly from server side classes and vice versa.

If you want to share some thing between client and server then use shared package but still its for specific purpose such as constants, validators, utilities, DTO (Data Transfer Object) etc.

Do not use any GWT UI specific code in shared classes. Shared package is also visible to server and there is no meaning of your customized widgets.

Read here about GWT MVP atchitecture

Read more here about GWT Architectural Perspectives


Create your objects in shared package to communicate between client and server.

One more thing any changes made at client side will not reflect at server side whether it is stored in shared classes or not. You have to pass the value to the server via GWT RPC calls.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM