`
wm1990315
  • 浏览: 4985 次
  • 性别: Icon_minigender_1
  • 来自: 上海
最近访客 更多访客>>
社区版块
存档分类
最新评论

Preview: Java Bean Support with Ext GWT

    博客分类:
  • GWT
 
阅读更多

The Ext GWT Store and Binder API work with ModelData instances. The primary goal of ModelData is to provide a type of “introspection” as GWT does not allow runtime inspection of Java objects. You can query ModelData for a list of properties it contains, and these properties can be retrieved and set using the parameter name with the get and set methods.

Although this approach works, it forces you to either implement the ModelData interface in your Java Beans or extend the Ext GWT base classes that implement the ModelData interface. What is missing is a way to use your Java Beans as is, without having to extend the Ext GWT base classes or implement an “invasive” interface.

With the 1.1 release of Ext GWT, it is possible to use any Java Beans in the Store and Binder API. This allows you to send your Java Beans from server to client using GWT RPC.

Java Bean support is provided by dynamically creating new BeanModel instances using any bean. The new type will “wrap” the bean, and all get and set calls on the model will be delegated to the underlying bean. Also, the original bean is available via the new bean model instance. The new model instances are created using a GWT Generator. Basically, the generator allows “new” types to be created at compile time using GWT.create(). The GXT generator will create a BeanModelFactory than can create new BeanModel instances from a Java Bean.

Identifying Java Beans

There are 2 ways of identifying Java Beans. The first method requires a new interface that extends BeanModelMarker and uses annotations. This method does not require the JavaBean to be modified. With the second method, your Java Bean implements the BeanModelTag interface.

BeanModellMarker Interface

The first step to enable Java Bean support is to identify the Class you would like to “adapt”. Rather than specifying the class directly, a new interface is created that extends BeanModelMarker. Then, a @BEAN annotation is added to the interface to identify the actual bean. This approach is beneficial, as it allows a single deferred binding rule to be used to identify your bean. Also, by using a marker interface, other configuration information can be specified by annotations.

public class Customer implements Serializable {
 
  private String name;
  private int age;
 
  public int getAge() {
    return age;
  }
  public void setAge(int age) {
    this.age = age;
  }
  public String getName() {
    return name;
  }
  public void setName(String name) {
    this.name = name;
  }
 
}
 
@BEAN(Customer.class)
public interface CustomerBeanModel extends BeanModelMarker {
 
}

BeanModelTag Interface

With this method, a new interface is not required as you tag the Java Bean directly. This means your beans will have a reference to a GXT interface.

public class Customer implements BeanModelTag, Serializable {
 
  private String name;
  private int age;
 
  public int getAge() {
    return age;
  }
 
  public void setAge(int age) {
    this.age = age;
  }
 
  public String getName() {
    return name;
  }
 
  public void setName(String name) {
    this.name = name;
  }
}

BeanModelLookup

BeanModelLookup is used to obtain a BeanModelFactory instance for a given bean type. You will use the BeanModelLookup singleton to obtain a BeanModelFactory for your given bean. The BeanModelFactory can be used to create new bean model instances from your bean instances.

BeanModelFactory factory = BeanModelLookup.get().getFactory(Customer.class);

With the factory, you are able to create new BeanModel instances that wrap your bean.

Customer c = new Customer();
c.setName("Darrell");
BeanModel model = factory.createModel(c);

BeanModelReader

It is common to use the GXT data loading API to retrieve remote data and populate a Store. The BeanModelReader can be used to handle creating new model instances from the beans being returned from the data proxy. With this approach, you can return any Java Beans from the RPC call. BeanModelReader will lookup the factory given the type of the objects being returned from the data proxy.

Store

When using this approach, the type of objects in the store will be the dynamically created types that were created based on the bean. These objects will extend BeanModel. BeanModel provides access to the “wrapped” bean via the getBean method.

Customer customer = (Customer)model.getBean();

Grid Example

Here is a snippet of code from the Explorer demo. It demonstrates uses a BeanModelReader with a Grid.

    // gwt service
    final ExplorerServiceAsync service = (ExplorerServiceAsync) Registry.get("service");
 
    // proxy and reader
    RpcProxy proxy = new RpcProxy() {
      @Override
      public void load(Object loadConfig, AsyncCallback callback) {
        service.getCustomers(callback);
      }
    };
    BeanModelReader reader = new BeanModelReader();
 
    // loader and store
    ListLoader loader = new BaseListLoader(proxy, reader);
    ListStore<BeanModel> store = new ListStore<BeanModel>(loader);
 
    loader.load();
 
    // column model
    List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
    columns.add(new ColumnConfig("name", "Name", 200));
    columns.add(new ColumnConfig("email", "Email", 100));
    columns.add(new ColumnConfig("age", "Age", 50));
    ColumnModel cm = new ColumnModel(columns);
 
    Grid<BeanModel> grid = new Grid<BeanModel>(store, cm);
    grid.setAutoExpandColumn("name");
    grid.setWidth(400);
    grid.setAutoHeight(true);
    grid.setBorders(true);

Summary

The new Java Bean support allows easy data integration of your existing Java Bean objects. Sending any Java Bean over the wire is possible, and Ext GWT can createbean model instances on the client.

These features will be available with the 1.1 release of Ext GWT. For those with access to SVN, the working code is in the trunk.

分享到:
评论

相关推荐

    Developing with Ext GWT Enterprise RIA Development.pdf完全版

    ### 关于《Developing with Ext GWT Enterprise RIA Development》的知识点 #### 一、概述与背景 本书《Developing with Ext GWT Enterprise RIA Development》由Grant K. Slender编写,出版时间为2009年5月。本书...

    Developing with Ext GWT Enterprise RIA Development

    Developing with Ext GWT Enterprise RIA Development

    Ext GWT 2.0 Beginner's Guide

    相比于传统的JavaScript框架,Ext GWT 通过Java语言进行开发,利用GWT编译器将Java代码转换为高性能的JavaScript,从而极大地提高了开发效率和代码质量。 #### 三、书籍内容概览 ##### 1. 构建高质量Web应用程序 ...

    面向 Java 开发人员的 Ajax: Google Web Toolkit 入门(GWT入门)

    **Java开发人员的Ajax:Google Web Toolkit (GWT) 入门** Google Web Toolkit (GWT) 是一个强大的工具,它允许Java开发人员使用熟悉的Java语言来构建高性能、跨浏览器的Ajax应用程序。GWT通过将Java代码编译为优化...

    gxt-2.2.4 EXT GWT

    gxt-2.2.4 EXT GWT Note : Ext GWT 2.X requires GWT 1.7+ or GWT 2.0+ (any build ending in "-gwt2.zip").

    gwtext编写的小系统

    GWText是一个基于Google Web Toolkit (GWT) 和EXT GWT (GXT) 框架的开源项目,用于构建富互联网应用程序(Rich Internet Applications, RIA)。这个“gwtext编写的小系统”是一个示例项目,旨在帮助初学者理解如何...

    Ext GWT 2.0, Beginner's Guide

    《Ext GWT 2.0, Beginner's Guide》是一本专为初学者设计的指南,旨在帮助读者深入了解和掌握Ext GWT 2.0这一强大的Java Web开发框架。Ext GWT,全称EXT Java Widget Toolkit,是Sencha公司开发的一个用于构建富...

    EXT-GWT(GXT) 2.2.4 JAVA API DOC chm 版

    EXT-GWT,全称为Ext GWT,是Sencha公司推出的一款基于Java的开源富互联网应用程序(Rich Internet Application,RIA)开发框架。GXT是EXT-GWT的简称,它提供了丰富的用户界面组件,允许开发者用Java代码来构建复杂的...

    Ext GWT 2.0 Beginner’s Guide

    《Ext GWT 2.0 初学者指南》适合所有级别的Java开发者,特别是那些希望将GWT和Ext GWT集成到现有项目或新项目中的开发者。无论是初学者还是有经验的开发人员,都能从本书中获得有价值的见解和实用的技巧,从而提高...

    Ext GWT 2.0: Beginner's Guide

    《Ext GWT 2.0: Beginner's Guide》是一本专为初学者设计的指南,旨在帮助读者快速掌握Ext GWT 2.0这一强大的Web应用程序开发框架。这本书结合了理论与实践,提供了丰富的示例代码和源码,使得学习过程更加直观和...

    ext gwt gxt初学教程

    GWT,由Google开发,允许开发者使用Java语言进行Web前端开发,通过编译器将Java代码转换为浏览器可识别的JavaScript代码。然而,GWT原生提供的控件集相对基础,无法满足复杂企业级应用的需求,这便是ExtGWT等第三方...

    Ext-Gwt(GWT)开发实例(整合Spring +Hibernate)

    标题 "Ext-Gwt(GWT)开发实例(整合Spring +Hibernate)" 涉及到的是一个实际项目开发的教程,其中结合了三个重要的技术框架:Google Web Toolkit (GWT),Spring 和 Hibernate。这个实例旨在展示如何在Web应用开发中...

    ext gwt的api文档

    gxt(又叫做ext gwt)是GWT的一个框架,该框架完全copy了Extjs的用户界面,本文档是gxt的api文档,并且是chm格式的

    gwt-ex t学习必备资料

    gwt ext gwt-ext gwt-ex t学习必备资料gwt ext gwt-ext gwt-ex t学习必备资料gwt ext gwt-ext gwt-ex t学习必备资料gwt ext gwt-ext gwt-ex t学习必备资料gwt ext gwt-ext gwt-ex t学习必备资料gwt ext gwt-ext gwt-...

    Gwt-Ext基础-中级-进阶

    3. **环境搭建**:如何配置Java环境,安装并设置GWT SDK,以及引入Gwt-Ext库到项目中。 4. **第一个Gwt-Ext程序**:创建一个简单的Gwt-Ext应用,了解基本的HTML host page,模块定义,以及如何在GWT应用中引入Gwt-...

    Gwt-ext学习笔记

    Gwt-ext通过提供Java封装类,让开发者可以使用Java API来操作和配置Ext JS组件,从而保持代码的整洁和一致性。 在学习Gwt-ext时,首先需要理解以下几个关键知识点: 1. **组件体系**:了解Ext JS的组件模型,包括...

    GWT简介.docx

    1. **Java编程模型**:GWT使用Java作为开发语言,使得开发者可以利用强大的Java生态系统和成熟的开发工具,如IDEA、Eclipse等,进行Web应用开发。Java代码经过编译器转换为JavaScript,提供了一种高效、便捷的开发...

Global site tag (gtag.js) - Google Analytics