flex+spring+hibernate框架:DataGrid后台数据动态获取
?
java后台服务:SecurityAssetsService.javaimport java.util.List;import com.ponshine.SMP.dao.SecurityAssetsDAO;import com.ponshine.SMP.model.SecurityAssets;public class SecurityAssetsService {private SecurityAssetsDAO sa;public SecurityAssetsDAO getSa() {return sa;}public void setSa(SecurityAssetsDAO sa) {this.sa = sa;}public List<SecurityAssets> findAll() {List<SecurityAssets> list = null;try {System.out.print("saService findAll-----");list=sa.findAll();System.out.println("__" + list);} catch (Exception e) {e.printStackTrace();}return list;}}?remoting-config.xml 设置:
<destination id="assetsService"><properties><factory>spring</factory><source>securityAssetsService</source> <!-- 这里是spring配置的bean名称 --></properties></destination>?spring里的配置:
<bean id="securityAssetsService" ref="SecurityAssetsDAO"></property></bean>?Flex端代码:
<?xml version="1.0" encoding="utf-8"?><s:BorderContainer xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" width="100%" height="100%"><fx:Script><![CDATA[import mx.collections.ArrayCollection;import mx.controls.Alert;import mx.rpc.events.FaultEvent;import mx.rpc.events.ResultEvent; public var sa:ArrayCollection=new ArrayCollection();protected function showDataGrid():void{// TODO Auto-generated method stubasService.findAll();}protected function assetsService_resultHandler(event:ResultEvent):void{var arr = event.result;assetsdg.dataProvider = arr;//得到返回值Alert.show("get data successfully");}protected function asService_faultHandler(event:FaultEvent):void{// TODO Auto-generated method stubAlert.show(event.target+"");}]]></fx:Script><fx:Declarations><!-- Place non-visual elements (e.g., services, value objects) here --><s:RemoteObject id="asService" destination="assetsService" result="assetsService_resultHandler(event)" fault="asService_faultHandler(event)"></s:RemoteObject></fx:Declarations><mx:Panel width="99%" height="100%" layout="absolute" paddingBottom="10" paddingLeft="10" paddingRight="10" paddingTop="10" title="资产详细信息"><s:VGroup width="100%" height="100%" horizontalAlign="center"><s:HGroup width="98%" height="25" verticalAlign="bottom"><s:Label width="66" fontSize="12" text="资产列表" verticalAlign="middle"/></s:HGroup><mx:HRule width="98%" height="20"/><s:HGroup width="98%" height="30" verticalAlign="top"><s:TextInput /><s:Button label="搜索" click="showDataGrid()" /><s:HGroup width="98%" height="100%" horizontalAlign="right" textAlign="left" verticalAlign="top"><s:Button label="刷新"/><s:Button label="提交到数据库"/><s:Button label="修改"/><s:Button label="新增"/><s:Button label="删除"/></s:HGroup></s:HGroup><s:DataGrid width="98%" height="500" requestedRowCount="14" id="assetsdg"><s:columns><s:ArrayList><s:GridColumn headerText="资产ID" dataField="assetsId"></s:GridColumn><s:GridColumn headerText="资产名称" dataField="assetsName"></s:GridColumn><s:GridColumn headerText="归属业务系统" dataField="businessSystem"></s:GridColumn><s:GridColumn headerText="管理IP地址" dataField="ip"></s:GridColumn><s:GridColumn headerText="状态" dataField="status"></s:GridColumn><s:GridColumn headerText="安全域" dataField="securityArea"></s:GridColumn><s:GridColumn headerText="操作系统版本" dataField="osVersion"></s:GridColumn><s:GridColumn headerText="维护部门" dataField="maintenanceDepartment"></s:GridColumn><s:GridColumn headerText="责任人" dataField="competent"></s:GridColumn><s:GridColumn headerText="归属地域" dataField="area"></s:GridColumn><s:GridColumn headerText="资产型号" dataField="model"></s:GridColumn><s:GridColumn headerText="是否关键资产" dataField="important"></s:GridColumn><s:GridColumn headerText="生产厂家" dataField="factory"></s:GridColumn><s:GridColumn headerText="设备类型" dataField="equipmentType"></s:GridColumn></s:ArrayList></s:columns></s:DataGrid></s:VGroup></mx:Panel></s:BorderContainer>?