Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GWT Editors and GAE Datastore

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!

like image 988
Bantha Fodder Avatar asked Oct 21 '12 00:10

Bantha Fodder


1 Answers

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

like image 79
bsautner Avatar answered Sep 17 '22 18:09

bsautner