grails flex 例子

一个结合 flex-plugin 的例子展示

具体操作步骤
1)安装 flex plugin

2)创建一个domian Product  和service
class Product {
    String name
    String description
    String image
    String category
    Double price
    Integer qtyInStock
}




class ProductService {

    static expose = ['flex-remoting']

    def getProducts() {
        return Product.list();
    }

    def update(Product product) {
        def p = Product.get(product.id)
        if (product) {
            p.properties = product.properties
            p.save()


        }
    }
   

}


3)在web-app目录下,新建下面3个文件
main.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*" layout="horizontal"
	creationComplete="srv.getProducts()">
	
	<mx:RemoteObject id="srv" destination="productService"/>
	
	<mx:Panel title="Catalog" width="100%" height="100%">
		<mx:DataGrid id="list" dataProvider="{srv.getProducts.lastResult}" width="100%" height="100%"/> 
	</mx:Panel>
	
	<ProductForm product="{Product(list.selectedItem)}"/>
	
</mx:Application>


ProductForm
<?xml version="1.0" encoding="utf-8"?>
<mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*"
	title="Details" width="100%" height="100%">
	
	<Product id="product"
		name="{productName.text}"
		category="{category.text}"
		price="{Number(price.text)}"
		image="{image.text}"
		description="{description.text}"/>

	<mx:RemoteObject id="srv" destination="productService"/>

	<mx:Form width="100%">
	
		<mx:FormItem label="姓名">
			<mx:TextInput id="productName" text="{product.name}"/>
		</mx:FormItem>
	
		<mx:FormItem label="Category">
			<mx:TextInput id="category" text="{product.category}"/>
		</mx:FormItem>
		
		<mx:FormItem label="Image">
			<mx:TextInput id="image" text="{product.image}"/>
		</mx:FormItem>
		
		<mx:FormItem label="Price">
			<mx:TextInput id="price" text="{product.price}"/>
		</mx:FormItem>


        <mx:FormItem label="Description" width="100%">
			<mx:TextArea id="description" text="{product.description}" width="100%" height="100"/>
		</mx:FormItem>
		
	</mx:Form>

	<mx:ControlBar>
		<mx:Button label="更新" click="srv.update(product);"/>
	
	</mx:ControlBar>

</mx:Panel>


Product.as
package
{
	[Bindable]
	[RemoteClass(alias="Product")]
	public class Product
	{
		public function Product()
		{
		}

		public var id:int;

		public var name:String;

		public var description:String;

		public var image:String;

		public var category:String;

		public var price:Number;

		public var qtyInStock:int;

	}
}



4)直接运行程序
如下图


你可能感兴趣的:(xml,Flex,Flash,vb,grails)