flex前後台クラスの転送
フロントのas類:最も重要なのはcomを加えることです.system.domain.FlowTypeは、フロントのクラスとバックグラウンドのクラスに対応します.
フロントのコード:
バックグラウンドに対応するクラス:
バックグラウンドとフロントのインタラクティブクラス:
プロファイル:
package
{
/**
* :
* :2012-12-26 10:09:29
*/
[ Bindable]
[ RemoteClass( alias= "com.system.domain.FlowType")]
public class FlowType
{
public function FlowType()
{
}
private var _pkId:int;
private var _flowId:int;
private var _typeId:int;
public function get typeId():int
{
return _typeId;
}
public function set typeId(value:int):void
{
_typeId = value;
}
public function get flowId():int
{
return _flowId;
}
public function set flowId(value:int):void
{
_flowId = value;
}
public function get pkId():int
{
return _pkId;
}
public function set pkId(value:int):void
{
_pkId = value;
}
}
}
フロントのコード:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
creationComplete="application1_creationCompleteHandler(event)"
minWidth="955" minHeight="600">
<s:layout>
<s:BasicLayout/>
</s:layout>
<fx:Declarations>
<mx:RemoteObject id="workflowRO" destination="workflowActionDest" fault="faultHandler(event)"/>
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.events.FlexEvent;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
[ Bindable]
public var flowtypelist:ArrayCollection;
private function faultHandler(event:FaultEvent):void {
Alert.show(event.toString(), 'FaultHandlerError' );
}
protected function application1_creationCompleteHandler(event:FlexEvent):void
{
workflowRO.addEventListener(ResultEvent.RESULT,findflowTypereturn);
workflowRO.findFlowTypes();
}
private function findflowTypereturn(event:ResultEvent):void
{
workflowRO.removeEventListener(ResultEvent.RESULT,findflowTypereturn);
flowtypelist=event.result as ArrayCollection ;
trace(flowtypelist.getItemAt(0));
var ft:FlowType=flowtypelist.getItemAt(0) as FlowType;
trace(ft.flowId);
}
protected function button1_clickHandler(event:MouseEvent):void
{
var ft:FlowType= dg.selectedItem as FlowType;
Alert.show(ft.flowId.toString());
ft.flowId=1000;
workflowRO.addEventListener(ResultEvent.RESULT,chargereturn);
workflowRO.saveFlowTypes(ft);
}
private function chargereturn(event:ResultEvent):void
{
workflowRO.removeEventListener(ResultEvent.RESULT,chargereturn);
}
]]>
</fx:Script>
<s:VGroup>
<s:Button label=" " click="button1_clickHandler(event)"/>
<mx:DataGrid id="dg" width="500" height="600" dataProvider="{flowtypelist}">
<mx:columns>
<mx:DataGridColumn dataField="flowId" headerText="flowId"/>
<mx:DataGridColumn dataField="pkId" width="100" headerText="pkId"/>
<mx:DataGridColumn dataField="typeId" headerText="typeId"/>
</mx:columns>
</mx:DataGrid>
</s:VGroup>
</s:Application>
バックグラウンドに対応するクラス:
ackage com.system.domain;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table (name = "flow_type")
public class FlowType implements Serializable {
private Integer pkId;
private Integer flowId;
private Integer typeId;
// empty Constructor
public FlowType(){
super();
}
// full Constructor
public FlowType(Integer pkId , Integer flowId , Integer typeId){
super();
this.pkId = pkId;
this.flowId = flowId;
this.typeId = typeId;
}
// auto Constructor
public FlowType(Integer flowId , Integer typeId){
super();
this.flowId = flowId;
this.typeId = typeId;
}
@Id
@GeneratedValue
@Column(name = "pk_id")
public Integer getPkId() {
return pkId ;
}
public void setPkId( Integer pkId ) {
this.pkId = pkId;
}
@Column(name = "flow_id")
public Integer getFlowId() {
return flowId ;
}
public void setFlowId( Integer flowId ) {
this.flowId = flowId;
}
@Column(name = "type_id")
public Integer getTypeId() {
return typeId ;
}
public void setTypeId( Integer typeId ) {
this.typeId = typeId;
}
}
バックグラウンドとフロントのインタラクティブクラス:
package com.system.action;
import java.util.List;
import javax.annotation.Resource;
import com.system.domain.FlowType;
import com.system.service.FlowTypeService;
public class WorkflowAction {
private FlowTypeService flowTypeService;
public FlowTypeService getFlowTypeService() {
return flowTypeService;
}
@Resource
public void setFlowTypeService(FlowTypeService flowTypeService) {
this. flowTypeService = flowTypeService;
}
public List<FlowType> findFlowTypes()
{
return flowTypeService.findFlowTypes();
}
public void saveFlowTypes(FlowType ty)
{
System. out.println(ty.getFlowId());
System. out.println(ty.getPkId());
}
}
プロファイル:
<bean id="workflowActionDest" class="com.system.action.WorkflowAction">
<flex:remoting-destination />
</bean>