flex 前后台类的传递

来源:互联网 发布:积分商城数据分析 编辑:程序博客网 时间:2024/05/22 01:51

前台的as 类:最重要的是要加com.system.domain.FlowType以便前台的类和后台的类对应。

Java代码 复制代码 收藏代码
  1. package
  2. {
  3. /**
  4. * 描述:
  5. * 创建时间:2012-12-26 上午10:09:29
  6. */
  7. [ Bindable]
  8. [ RemoteClass( alias= "com.system.domain.FlowType")]
  9. public class FlowType
  10. {
  11. public function FlowType()
  12. {
  13. }
  14. private var _pkId:int;
  15. private var _flowId:int;
  16. private var _typeId:int;
  17. public function get typeId():int
  18. {
  19. return _typeId;
  20. }
  21. public function set typeId(value:int):void
  22. {
  23. _typeId = value;
  24. }
  25. public function get flowId():int
  26. {
  27. return _flowId;
  28. }
  29. public function set flowId(value:int):void
  30. {
  31. _flowId = value;
  32. }
  33. public function get pkId():int
  34. {
  35. return _pkId;
  36. }
  37. public function set pkId(value:int):void
  38. {
  39. _pkId = value;
  40. }
  41. }
  42. }

前台的代码:

Flex代码 复制代码 收藏代码
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
  3. xmlns:s="library://ns.adobe.com/flex/spark"
  4. xmlns:mx="library://ns.adobe.com/flex/mx"
  5. creationComplete="application1_creationCompleteHandler(event)"
  6. minWidth="955" minHeight="600">
  7. <s:layout>
  8. <s:BasicLayout/>
  9. </s:layout>
  10. <fx:Declarations>
  11. <mx:RemoteObject id="workflowRO" destination="workflowActionDest" fault="faultHandler(event)"/>
  12. </fx:Declarations>
  13. <fx:Script>
  14. <![CDATA[
  15. import mx.collections.ArrayCollection;
  16. import mx.controls.Alert;
  17. import mx.events.FlexEvent;
  18. import mx.rpc.events.FaultEvent;
  19. import mx.rpc.events.ResultEvent;
  20. [ Bindable]
  21. public var flowtypelist:ArrayCollection;
  22. private function faultHandler(event:FaultEvent):void {
  23. Alert.show(event.toString(), 'FaultHandlerError' );
  24. }
  25. protected function application1_creationCompleteHandler(event:FlexEvent):void
  26. {
  27. workflowRO.addEventListener(ResultEvent.RESULT,findflowTypereturn);
  28. workflowRO.findFlowTypes();
  29. }
  30. private function findflowTypereturn(event:ResultEvent):void
  31. {
  32. workflowRO.removeEventListener(ResultEvent.RESULT,findflowTypereturn);
  33. flowtypelist=event.result as ArrayCollection ;
  34. trace(flowtypelist.getItemAt(0));
  35. var ft:FlowType=flowtypelist.getItemAt(0) as FlowType;
  36. trace(ft.flowId);
  37. }
  38. protected function button1_clickHandler(event:MouseEvent):void
  39. {
  40. var ft:FlowType= dg.selectedItem as FlowType;
  41. Alert.show(ft.flowId.toString());
  42. ft.flowId=1000;
  43. workflowRO.addEventListener(ResultEvent.RESULT,chargereturn);
  44. workflowRO.saveFlowTypes(ft);
  45. }
  46. private function chargereturn(event:ResultEvent):void
  47. {
  48. workflowRO.removeEventListener(ResultEvent.RESULT,chargereturn);
  49. }
  50. ]]>
  51. </fx:Script>
  52. <s:VGroup>
  53. <s:Button label="添加" click="button1_clickHandler(event)"/>
  54. <mx:DataGrid id="dg" width="500" height="600" dataProvider="{flowtypelist}">
  55. <mx:columns>
  56. <mx:DataGridColumn dataField="flowId" headerText="flowId"/>
  57. <mx:DataGridColumn dataField="pkId" width="100" headerText="pkId"/>
  58. <mx:DataGridColumn dataField="typeId" headerText="typeId"/>
  59. </mx:columns>
  60. </mx:DataGrid>
  61. </s:VGroup>
  62. </s:Application>

后台对应的类:

Java代码 复制代码 收藏代码
  1. ackage com.system.domain;
  2. import java.io.Serializable;
  3. import javax.persistence.Column;
  4. import javax.persistence.Entity;
  5. import javax.persistence.GeneratedValue;
  6. import javax.persistence.Id;
  7. import javax.persistence.Table;
  8. @Entity
  9. @Table (name = "flow_type")
  10. public class FlowTypeimplements Serializable {
  11. private Integer pkId;
  12. private Integer flowId;
  13. private Integer typeId;
  14. // empty Constructor
  15. public FlowType(){
  16. super();
  17. }
  18. // full Constructor
  19. public FlowType(Integer pkId , Integer flowId , Integer typeId){
  20. super();
  21. this.pkId = pkId;
  22. this.flowId = flowId;
  23. this.typeId = typeId;
  24. }
  25. // auto Constructor
  26. public FlowType(Integer flowId , Integer typeId){
  27. super();
  28. this.flowId = flowId;
  29. this.typeId = typeId;
  30. }
  31. @Id
  32. @GeneratedValue
  33. @Column(name = "pk_id")
  34. public Integer getPkId() {
  35. return pkId ;
  36. }
  37. public void setPkId( Integer pkId ) {
  38. this.pkId = pkId;
  39. }
  40. @Column(name = "flow_id")
  41. public Integer getFlowId() {
  42. return flowId ;
  43. }
  44. public void setFlowId( Integer flowId ) {
  45. this.flowId = flowId;
  46. }
  47. @Column(name = "type_id")
  48. public Integer getTypeId() {
  49. return typeId ;
  50. }
  51. public void setTypeId( Integer typeId ) {
  52. this.typeId = typeId;
  53. }
原创粉丝点击