×
关于

Vaadin Web 开发教程

概述安装开发环境Vaadin 应用程序框架介绍开始编写 Web 应用Vaadin Web 应用的基本组成部分使用资源UI 组件概述UI 组件-LabelUI 組件-LinkUI 組件-TextFieldUI 組件-TextAreaUI 組件-PasswordFieldUI 組件-RichTextAreaUI 組件-ButtonUI 組件-CheckboxUI 组件-Select 组件UI 组件-Table 组件UI 组件-Tree 组件UI 组件-MenuBar 组件UI 组件-Embedded 组件UI 组件-Upload 组件UI 组件-Form 组件UI 组件-ProgressIndicator 组件UI 组件-Slider 组件UI 组件-LoginForm 组件UI 组件-自定义组件UI 布局-概述UI 布局-VerticalLayout 和 HorizontalLayout 布局UI 布局-GridLayout 布局UI 布局-FormLayout 布局UI 布局-PanelUI 布局-HorizontalSplitPanel 和 VerticalSplitPanel 布局UI 布局-TabSheet 布局UI 布局-Accordion 布局UI 布局-AbsoluteLayout 布局可視化界面編輯插件使用主题-概述使用主题-创建和应用新主题数据绑定-概述数据绑定-Property 接口使用 Item 介面管理一組 Property使用 Container 介面管理一組 ItemSQLContainer 概述开始使用 SQLContainerSQLContainer-过滤及排序SQLContainer-编辑SQLContainer-引用其它 SQLContainerSQLContainer-使用 FreeformQuery

SQLContainer-编辑


和普通 Container 修改其中 Item 项类似,SQLContainer 可以使用类似的方法来编辑其中的Item。RowItem 的 ColumnProperties 会自动通知 SQLContainer 关于数据的变化并应用到数据库。

添加 Item

向 SQLContainer 中添加一项是通过方法 addItem()来完成的。这个方法将创建一个新的 Item,新创建的 Item 可以在内存中缓存或直接添加到数据库中。这取决于 SQLContainer 的 auto commit 模式。 实际也只能通过 addItem() 方法向 SQLContainer 中添加记录,其它由 Container 定义的方法SQLContainer 并不支持:

public boolean addContainerProperty(Object propertyId,
                                    Class<?> type,
                                    Object defaultValue)
public boolean removeContainerProperty(Object propertyId)
public Item addItem(Object itemId)
public Object addItemAt(int index)
public Item addItemAt(int index, Object newItemId)
public Object addItemAfter(Object previousItemId)
public Item addItemAfter(Object previousItemId, Object newItemId)

此外 RowItem 不支持的 Item 方法有:

public boolean addItemProperty(Object id, Property property)
public boolean removeItemProperty(Object id)

下面的例子向 Customer 表中添加一个记录 James ,Shen, Tribute Street, Perth

void addCustomer(SQLContainer sqlContainer){

    sqlContainer.setAutoCommit(false);
    TemporaryRowId rowId=(TemporaryRowId)sqlContainer.addItem();
    if(rowId!=null){
        RowItem rowItem=(RowItem)sqlContainer.getItem(rowId);
        ColumnProperty firstName=(ColumnProperty)rowItem.getItemProperty("FIRSTNAME");
        firstName.setValue("James");
        ColumnProperty lastName=(ColumnProperty)rowItem.getItemProperty("LASTNAME");
        lastName.setValue("Shen");
        ColumnProperty street=(ColumnProperty)rowItem.getItemProperty("STREET");
        street.setValue("Tribute Steet");
        ColumnProperty city=(ColumnProperty)rowItem.getItemProperty("CITY");
        city.setValue("Perth");
        ColumnProperty Id=(ColumnProperty)rowItem.getItemProperty("ID");
        Id.setValue(50);
        rowItem.commit();

    }
}

整体感觉使用 SQLContainer 编辑数据并不十分方便,还不如直接使用 SQL 语句或是使用hibernate.来的方便。

Tags: Java EE, Vaadin, Web


分类导航

关注微信下载离线手册

bootwiki移动版 bootwiki
(群号:472910771)