GWT using entities from EJB
i got maybe a stupid issue on using entity classes on GWT pages. It is said that to show some class on GWT pages, this class must be defined within package of GWT client app. E.g. GWT application under com.foo.clinet can use only classes defined in this package and its subpackages to be shown in the components (like GWT grids, labels...)
But what if you got some other project where you have defined those entites, typically EJB (imagine structure web project, ejb project). You are able to recieve those entites via RPC service but then you cannot use them in the components (simple adding jar of this project wont help). The first possibility is to transform them into some other value object with more or less same attributes but defined in this web project. But this is code duplication whi开发者_如何学Goch is never nice because simply when you change entity, you have to change correspoding view value object. There are surely few options how to do such things automatically (e.g. via reflection which is sadly slow...).
So the question is, is there some typical elegant solution or design pattern how to solve this without code duplication? Thanks a lot
Put your EJBs in a separate package/directory (e.g. com.example.common) and then add source declaration to your GWT module descriptor (xyz.gwt.xml):
<source path="common"/> //relative to your xyz.gwt.xml location
GWT compiler will then also compile EJBs and they will be seen by your other GWT code.
Create "fake" EJB annotation classes using super-sourcing. This is a common technique to replace classes with a GWT version. Described here: http://fredsa.allen-sauer.com/2009/04/1st-look-at-app-engine-using-jdo.html
I maybe found solution but im not sure if it is right one. I will specify my problem a bit more precise. I got this structure.
/MyApp/Ejb-module/x/y/z/MyClass.java
/MyApp/Web-module/x/y/MyApp.gwt.xml
and want to include MyClass.java
to GWT compiler WITHOUT need to move it anywhere.
I just defined that /MyApp/Ejb-module
build will include also *.java
files and then in /MyApp/Web-module/a/b
I addded Inclusion.gwt.xml where I put
<module>
<source path="z" />
</module>
and updated MyApp.gwt.xml
with
<inherits name="x.y.Inclusion"/>
精彩评论