Flamingo 为 Flex + Seam提供了部分组件供使用
然后是实体类Person的代码:
将swf文件编译后,放到有Person组件的Seam 项目中运行,就可以对该字段进行验证。
主要的有Validator的Seam AMF版本 EntityValidator, CallSet 的 SeamCallSet和 SeamCall 和 Binding组件的 BindService.
1、EntityValidator
该组件提供表单字段的验证功能,可以使用hibernate validator annotation对实体类组件进行验证
示例:
validation.mxml:
- <?xml version="1.0" encoding="utf-8"?>
- <!--
- ~ Copyright (C) 2008 Exadel, Inc.
- ~
- ~ The GNU Lesser General Public License, Version 3
- -->
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
- xmlns:flamingo="com.exadel.flamingo.flex.components.flamingo.*">
- <!--
- Note:
- destination - name of component on server or name of entity,
- provided - in InputText for educational reason. Can be set dynamically. In this case, it points to "person"
- validationTarget - property of target object this is what we are validating (text box)
- source - this is a text box we are validating
- property - name of property of visual component that is being validated
- required - check for blank
- Validator triggers when source conponent loses focus. This can be customized:
- event = ...
- -->
- <flamingo:EntityValidator id="validator"
- destination="{destination.text}"
- validationTarget="{target.text}"
- source="{test}"
- property="text"
- required="false"/>
- <mx:Form width="100%" >
- <mx:Label text='Valid destinatios are: "person" component, "Person" entity as well as full qualified class name'/>
- <mx:FormItem label="Destination:" width="100%" >
- <mx:TextInput id="destination" width="100%" text="person" />
- </mx:FormItem>
- <mx:FormItem label="Validation target:" width="100%" >
- <mx:TextInput id="target" width="100%" text="lastName" />
- </mx:FormItem>
- <mx:FormItem label="Input value:" width="100%" >
- <mx:TextInput id="test" width="100%" />
- </mx:FormItem>
- <mx:FormItem>
- <mx:Button label="Validate" click="validator.validate()" />
- </mx:FormItem>
- </mx:Form>
- </mx:Application>
- /*
- * Copyright (C) 2008 Exadel, Inc.
- *
- * The GNU Lesser General Public License, Version 3
- */
- package com.exadel.flamingo.flex.samples;
- import javax.persistence.Entity;
- import org.hibernate.validator.Length;
- import org.jboss.seam.annotations.Name;
- @Name("person")
- @Entity(name="Person")
- public class Person{
- private String lastName;
- /**
- * @return the lastName
- */
- @Length(min=3, max=40)
- public String getLastName() {
- return lastName;
- }
- /**
- * @param lastName the lastName to set
- */
- public void setLastName(String lastName) {
- this.lastName = lastName;
- }
- }