`

smartGWT dome form Validator

GWT 
阅读更多
表单验证
/* 
 * Smart GWT (GWT for SmartClient) 
 * Copyright 2008 and beyond, Isomorphic Software, Inc. 
 * 
 * Smart GWT is free software; you can redistribute it and/or modify it 
 * under the terms of the GNU Lesser General Public License version 3 
 * as published by the Free Software Foundation.  Smart GWT is also 
 * available under typical commercial license terms - see 
 * http://smartclient.com/license 
 * 
 * This software is distributed in the hope that it will be useful, 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
 * Lesser General Public License for more details. 
 */  
  
import com.smartgwt.client.data.DataSource;  
import com.smartgwt.client.data.fields.DataSourcePasswordField;  
import com.smartgwt.client.data.fields.DataSourceTextField;  
import com.smartgwt.client.widgets.Canvas;  
import com.smartgwt.client.widgets.form.DynamicForm;  
import com.smartgwt.client.widgets.form.fields.ButtonItem;  
import com.smartgwt.client.widgets.form.fields.CheckboxItem;  
import com.smartgwt.client.widgets.form.fields.HeaderItem;  
import com.smartgwt.client.widgets.form.fields.PasswordItem;  
import com.smartgwt.client.widgets.form.fields.events.ClickEvent;  
import com.smartgwt.client.widgets.form.fields.events.ClickHandler;  
import com.smartgwt.client.widgets.form.validator.MatchesFieldValidator;  
import com.smartgwt.client.widgets.form.validator.RegExpValidator;  
  
public class FormDataBindingSample implements EntryPoint {  
  
    public void onModuleLoad() {  
  
        DataSource dataSource = new DataSource();  
  
        DataSourceTextField firstNameField = new DataSourceTextField("firstName", "First Name", 50, true);  
        DataSourceTextField lastNameField = new DataSourceTextField("lastName", "Last Name", 50, true);  
        DataSourceTextField emailField = new DataSourceTextField("email", "Email", 100, true);  
  
        RegExpValidator emailValidator = new RegExpValidator();  
        emailValidator.setErrorMessage("Invalid email address");  
        emailValidator.setExpression("^([a-zA-Z0-9_.\\-+])+@(([a-zA-Z0-9\\-])+\\.)+[a-zA-Z0-9]{2,4}$");  
          
        emailField.setValidators(emailValidator);  
  
        DataSourcePasswordField passwordField = new DataSourcePasswordField("password", "Password", 20, true);  
  
        dataSource.setFields(firstNameField, lastNameField, emailField, passwordField);  
  
        final DynamicForm form = new DynamicForm();  
        form.setDataSource(dataSource);  
        form.setUseAllDataSourceFields(true);  
  
        HeaderItem header = new HeaderItem();  
        header.setDefaultValue("Registration Form");  
  
        PasswordItem passwordItem = new PasswordItem();  
        passwordItem.setName("password");  
  
        PasswordItem passwordItem2 = new PasswordItem();  
        passwordItem2.setName("password2");  
        passwordItem2.setTitle("Password Again");  
        passwordItem2.setRequired(true);  
        passwordItem2.setLength(20);  
  
        MatchesFieldValidator matchesValidator = new MatchesFieldValidator();  
        matchesValidator.setOtherField("password");  
        matchesValidator.setErrorMessage("Passwords do not match");          
        passwordItem2.setValidators(matchesValidator);  
  
        CheckboxItem acceptItem = new CheckboxItem();  
        acceptItem.setName("acceptTerms");  
        acceptItem.setTitle("I accept the terms of use.");  
        acceptItem.setRequired(true);  
        acceptItem.setWidth(150);  
  
        ButtonItem validateItem = new ButtonItem();  
        validateItem.setTitle("Validate");  
        validateItem.addClickHandler(new ClickHandler() {  
            public void onClick(ClickEvent event) {  
                form.validate(false);  
            }  
        });  
  
        form.setFields(header, passwordItem, passwordItem2, acceptItem, validateItem);  
          
        form.setValue("firstName", "Bob");  
        form.setValue("email", "bob@.com");  
        form.setValue("password", "sekrit");  
        form.setValue("password2", "fatfinger");      
              
        form.draw();  
    }  
  
}  
分享到:
评论

相关推荐

    smartgwt官方实例

    SmartGWT是一个强大的Java框架,用于构建富互联网应用程序(RIA)。这个官方实例是学习和理解SmartGWT功能和用法的宝贵资源,尤其适合自学者。"Showcase"通常指的是一个展示各种组件、特性和功能的集合,让我们深入...

    SmartGwt学习文档

    SmartGwt是一款强大的Java库,专门用于构建富互联网应用程序(RIA,Rich Internet Applications)。它基于Google的GWT(Google Web Toolkit)框架,并扩展了其功能,提供了丰富的UI组件和更高级的客户端性能优化。...

    SmartGWT2.0 API

    SmartGWT 2.0 API 是一款基于Google Web Toolkit (GWT) 2.0的高级组件库,它为开发者提供了丰富的用户界面组件和强大的功能,以构建高性能、交互式的Web应用程序。SmartGWT 2.0 在其前身的基础上进行了多方面的改进...

    smartgwt-1.3

    SmartGWT是一个强大的Java库,专门用于构建富互联网应用程序(RIA)。这个名为"smartgwt-1.3"的压缩包文件很可能包含了SmartGWT框架的1.3版本的源代码、库文件和其他相关资源。SmartGWT是基于Google Web Toolkit ...

    基于Maven的SmartGWT项目示例

    本示例项目“基于Maven的SmartGWT项目”就是这样的一个实践,它结合了两个强大的技术:Maven作为项目管理和构建工具,以及SmartGWT作为前端UI框架。下面我们将深入探讨这两个技术以及它们如何协同工作。 首先,...

    smartGWT开发环境搭建(完整工程)

    SmartGWT是一个强大的Java框架,用于构建富互联网应用程序(RIA)。它基于Google Web Toolkit (GWT) 并扩展了其功能,提供了丰富的组件库和高级的UI设计工具。本教程将详细阐述如何搭建SmartGWT的开发环境,以及如何...

    smartGWT 3.1 最新版本

    SmartGWT 3.1 是一个先进的Java框架,专门用于构建富互联网应用程序(Rich Internet Applications,简称RIA)。这个最新版本提供了丰富的功能和组件,旨在帮助开发者高效地开发出交互性强、用户体验优秀的Web应用。...

    SmartGWT 12.0

    SmartGWT 12.0 是一款强大的Java框架,专为构建富互联网应用程序(Rich Internet Applications,RIAs)而设计。这个最新版本提供了一系列增强的功能和优化,旨在提高开发效率和用户体验。SmartGWT库的核心在于它将...

    smartGWT最新zip

    SmartGWT是一个强大的Java库,专门用于构建富互联网应用程序(RIA)。它基于Google Web Toolkit (GWT) 平台,并提供了丰富的用户界面组件和优化工具,使得开发人员能够轻松创建功能丰富的、交互性强的Web应用。GWT...

    smartgwt2.4 最新发布

    SmartGWT 2.4 是一个强大的开源框架,主要用于构建企业级的富互联网应用程序(Rich Internet Applications,简称RIA)。这个框架基于Google Web Toolkit (GWT) 并且扩展了其功能,提供了丰富的组件库和高级特性,...

    smartGwt学习笔记

    在SmartGWT的学习和开发过程中,经常会遇到各种挑战和问题,比如本文提到的“分页问题GridPager”。SmartGwt是一个强大的Java库,用于构建基于Web的用户界面,它提供了丰富的组件,包括ListGrid,一个功能强大的表格...

    smartgwt5.0

    SmartGWT 是封装了 SmartClient 的 GWT API。而 SmartClient 是一个开源的企业级 Ajax 开发框架。 Google Web Toolkit 的发布,大大降低了 Java 开发人员进行 Web 开发的门槛。然而 GWT 本身提供的控件及功能相对...

    smartgwt + spring + hibernate

    SmartGWT + Spring + Hibernate 是一个常见的企业级应用开发组合,它们各自在Web应用程序开发中扮演着重要角色。SmartGWT是基于GWT(Google Web Toolkit)的一个强大的UI库,提供丰富的用户界面组件和高性能的...

    smart GWT 3.1

    SmartGWT 是封装了 SmartClient 的 GWT API。SmartGWT 有如下特色: 丰富的控件。很多较为复杂的常用界面都被包装成简单易用的控件。比如可 编辑的树形表格、查询常用的过滤器创建器和类似 Google Calendar 的日历...

    SmartGWT 入门 SmartGWT 入门

    ### SmartGWT 入门详解 #### 一、SmartGWT 概述 **SmartGWT** 是一款基于 **Google Web Toolkit (GWT)** 的高级Web应用开发框架,旨在简化企业级Web 2.0应用的开发过程。自从 **GWT** 发布以来,它吸引了大量的...

    smartGWT

    "SmartGWT"是一个强大的Java库,用于构建企业级的Web应用程序。它基于Google Web Toolkit (GWT) 并提供了一系列高级组件和功能,旨在简化开发过程,提高开发效率。SmartGWT尤其适合那些需要创建数据密集型、交互性强...

    SmartGWT 快速开发文档(Quick Start Guide)

    ### SmartGWT 快速开发文档 (Quick Start Guide) 关键知识点详解 #### 一、文档概述 **SmartGWT** 是一款强大的基于 Java 的 Web 应用前端框架,它支持构建高性能的企业级应用程序。本快速开发文档为 SmartGwtEE ...

    SmartGwt 之原生 Desktop(与gxt无关)

    《SmartGwt 原生 Desktop 深度解析》 SmartGwt 是一款基于 Java 的开源库,它为开发人员提供了丰富的组件和工具,用于构建高性能、富交互式的 Web 应用程序。在 SmartGwt 中,原生的 Desktop 功能是一个强大的特性...

    smartgwt最新版本GWT的DEMO

    1. **组件使用**:SmartGWT中的组件如Grid(表格)、Form(表单)、Tree(树形结构)、Dialog(对话框)等,都有详细的示例展示。开发者可以通过这些例子了解如何创建、配置和操作这些组件。 2. **数据绑定**:...

    smartgwt-2.0API.CHM

    smartgwt-2.0API.CHM 2009年12月18日 ... SmartGWT 2.0发布下载了

Global site tag (gtag.js) - Google Analytics