简体   繁体   English

GWT编辑器和GAE数据存储区

[英]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. GWT有一个编辑器框架 ,经过粗略的检查,看起来非常像Spring MVC / Forms如何处理后端数据对象和前端UI组件之间的数据绑定。

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. 我正在编写我的第一个GWT / GAE应用程序,并想知道是否有任何方法可以将此编辑框架 GAE的JDO / Atomic库结合使用 ,这是您编写的应用程序与基础数据存储区之间的O / R映射的API 。

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. 如果他们可以一起工作,有人可以提供一个小代码示例,说明如何使用它们填充,例如,带有名单列表的HTML <select>框,或其他基本但实用的东西。

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. 我想这可能涉及一个Person POJO代表一个人(并具有一个String name属性),也许某种PersonDAO使用JDO / Atomic到CRUD Person实例到/从数据存储区,然后某种Editor<Person>可以将Person实例映射到前端<select>

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! 提前致谢!

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. 我希望这会有所帮助,这是一些将数据存储在GAE数据存储中的示例代码,一个简单的查询来获取数据并使用内容填充GWT下拉列表。

Here is a JDO ORM that persists to the app engine data store: 这是一个持久存储到app引擎数据存储的JDO ORM:

https://github.com/bsautner/com.nimbits/blob/master/nimbits-tds/src/com/nimbits/server/orm/EntityStore.java 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 这是一个基于GWT(GXT)的组合框,填充了从ORM模型创建的POJO

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

In the age of IE6 and HTML4 there was no way to write web apps as cool as GMail. 在IE6和HTML4时代,没有办法像GMail那样编写酷炫的网络应用程序。 That's why GWT was introduced and the goal was achieved: GMail was able to work in any browser. 这就是为什么推出GWT并实现目标的原因:GMail能够在任何浏览器中工作。

In our days it looks like GWT lost leadership. 在我们的日子里,看起来GWT失去了领导力。 jQuery became more popular because it uses hardware acceleration and works much faster... However it's still early to forget about GWT. jQuery变得更受欢迎,因为它使用硬件加速并且工作得更快......但是忘记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. 如果你想使用编辑器框架和JDO,我们需要强调它们之间存在瓶颈:GWT RPC。 RPC serializes and deserializes POJOs every time and you have very limited ways to customize this serialization/deserialization. RPC每次都会对POJO进行序列化和反序列化,并且您可以通过非常有限的方式来自定义此序列化/反序列化。

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. GWT RPC的这个缺点迫使大多数开发人员维护两个相同的POJO层次结构:一个用于JDO / Hibernate,另一个用于GWT。 Usually bosses approve this solution because it is faster and easier than hacking around every RPC call to make it work. 通常老板会批准这个解决方案,因为它比黑客攻击每个RPC调用更快更容易。 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. 另一方面,jQuery根本不需要定义任何POJO。 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. 而且我已经多次看到非常有经验的建筑师决定使用GWT并进入这个死胡同。 And now they pay for this mistake by spending time and money on writing two identical POJO hierarchies. 而现在他们花费时间和金钱来编写两个相同的POJO层次结构来为这个错误付出代价。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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