GWT Editors and GAE Datastore
Asked Answered
T

2

7

GWT has an Editor Framework, which, after a cursory inspection, looks an awful lot like how Spring MVC/Forms handles data binding between backend data objects and frontend UI components.

I am writing my first GWT/GAE application and was wondering if there is any way to use this Editor Framework in conjunction with GAE's JDO/Atomic library, which is the API you code against to O/R map between your app and the underlying datastore.

Are these two frameworks complimentary or are they mutually exclusive? If they can work together, can someone please provide a small code sample of how I could use them to populate, say, an HTML <select> box with a list of names, or something else basic-yet-practical.

I would imagine this might involve a Person POJO representing a person (and having a String name property), perhaps some kind of PersonDAO that uses JDO/Atomic to CRUD Person instances to/from the Datastore, and then some kind of Editor<Person> that can map Person instances to frontend <select>s.

If I can see a working example, I think it will all come together for me. And, if these are exclusive of one another and can't be used together, a solid explanation of why would be enormously appreciated! Thanks in advance!

Tael answered 21/10, 2012 at 0:48 Comment(3)
You didn't mention Objectify, but this blog post on integrating it with the Editor framework is excellent: turbomanage.wordpress.com/2011/03/25/…Callow
Ahh, so it looks like Objectify is sort of a wrapper to JDO/Atomic? Sort of like how Hibernate wraps JDBC? Thanks @ben_w!Tael
Objectify is nothing to do with JDO, it is an alternative to. No idea what is this "Atomic" you refer to.Dinitrobenzene
R
1

I hope this helps, this is some sample code that stores data in GAE data store, a simple query to get data out and populate a GWT dropdown with the contents.

Here is a JDO ORM that persists to the app engine data store:

https://github.com/bsautner/com.nimbits/blob/master/nimbits-tds/src/com/nimbits/server/orm/EntityStore.java

Here is an example of querying the data store for a list of objects

@Override
    public List<Entity> getEntityByName(final User user, final String name) 
{
        final PersistenceManager pm = pmf.getPersistenceManager();

        try {
            final Query q1 = pm.newQuery(EntityStore.Class);
            final List<Entity> c;

                q1.setFilter("name==b");
                q1.declareParameters("String b");
                q1.setRange(0, 1);
                c = (List<Entity>) q1.execute(name);

            if (c.isEmpty()) {
                return Collections.emptyList();
            } else {

                final Entity result = c.get(0);
                return createModel(user, result);

            }

        } finally {
            pm.close();
        }
    }

Here is a GWT (GXT) based combo box that populates with POJO's created from the ORM Model

https://github.com/bsautner/com.nimbits/blob/master/nimbits-tds/src/com/nimbits/client/ui/controls/EntityCombo.java

Rollback answered 31/10, 2012 at 20:52 Comment(0)
T
0

In the age of IE6 and HTML4 there was no way to write web apps as cool as GMail. That's why GWT was introduced and the goal was achieved: GMail was able to work in any browser.

In our days it looks like GWT lost leadership. jQuery became more popular because it uses hardware acceleration and works much faster... However it's still early to forget about GWT.

If you want to use Editor framework and JDO, than we ned to highlight that there is a bottle neck between them: GWT RPC. RPC serializes and deserializes POJOs every time and you have very limited ways to customize this serialization/deserialization.

This disadvantage of GWT RPC forces most of developers to maintain two identical hierarchies of POJOs: one for JDO/Hibernate and the second one for GWT. Usually bosses approve this solution because it is faster and easier than hacking around every RPC call to make it work. And in most real world projects I've seen there are two hierarchies...

On the other hand jQuery does not require do define any POJOs at all. Obviously it is a reason of difference in speed of development.

I'm sorry that I have not provided any answer. I hope my thoughts will be useful even if it just sais that you are in the blind alley. And I have seen several times that very experienced architects decided to use GWT and got to this blind alley as well. And now they pay for this mistake by spending time and money on writing two identical POJO hierarchies.

Telluride answered 31/10, 2012 at 21:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.