main.mxml 3.08 KB
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" preinitialize="Ejb.getInstance().initApplication()" creationComplete="init();" layout="absolute">
	<mx:Text id="teksti" text="Foobar123"></mx:Text>
	<mx:Script>
	<![CDATA[
	 import org.granite.tide.ejb.Ejb;
     import org.granite.tide.ejb.Context;
     import org.granite.tide.ejb.Identity;
     import org.granite.tide.events.TideUIEvent;
     import org.granite.tide.service.DefaultServiceInitializer;
     import org.granite.tide.data.events.TideDataConflictsEvent;
	 import org.granite.tide.data.Conflicts;
 	 import mx.events.CloseEvent;
 	 import org.granite.tide.events.TideResultEvent;
 	 import org.granite.tide.events.TideFaultEvent;
 	 import mx.controls.Label;
 	 import mx.controls.Text;
 	 import fi.insomnia.bortal.beans.EventBean;
 	 
     import mx.controls.Alert;      
	//Ejb.getInstance().addComponentWithFactory("serviceInitializer", DefaultServiceInitializer, 
	// { contextRoot: "/graniteds-tide-ejb3" });
    //  Ejb.getInstance().addModule(AddressBookModule);
            
	private var tideContext:Context = Ejb.getInstance().getEjbContext();
	private var text1:Label; 
    
    private function init():void {
		identity.isLoggedIn();
		text1 = new Label();
		text1.x = 50;
		text1.y = 80;
		text1.text = "Flashparam 3 Map: "+ parameters.param1 ;//+ " Username: " + identity.username + " LoggedIn: " + identity.isLoggedIn();
		this.addChild(text1);
		tideContext.flashMapBean.getMapBackground(1,1, eventhandler,helloFault);
		
	  //  Ejb.getInstance().getEjbContext().addEventListener(TideDataConflictsEvent.DATA_CONFLICTS, conflictsHandler);
	
	}
	
	 private function eventhandler(event:TideResultEvent):void {
       var text2:Label = new Label();
		text2.x = 50;
		text2.y = 100;
		text2.text = "Got result3!!";
		this.addChild(text2);
    

       var text3:Label = new Label();
		text3.x = 50;
		text3.y = 150;
		
		Alert.show(event.result.toString());
		var txt3:String = "null";
		if(event.result != null)
		{
			txt3 = event.result.name;
		}
		text3.text = txt3;
		this.addChild(text3);

        }
        
        private function helloFault(event:TideFaultEvent):void {
		    var text2:Text = new Text();
			text2.x = 50;
			text2.y = 100;
			text2.text = event.fault.toString();
			this.addChild(text2);
}
        
			private var _conflicts:Conflicts;
            
            private function conflictsHandler(event:TideDataConflictsEvent):void {
            	_conflicts = event.conflicts;
            	Alert.show("Someone else has modified the person you are currently working on.\nDo you want to keep your modifications ?", 
            		"Modification conflict", Alert.YES | Alert.NO, null, conflictsCloseHandler);
            }
            
            private function conflictsCloseHandler(event:CloseEvent):void {
            	if (event.detail == Alert.YES)
            		_conflicts.acceptAllClient();
            	else
            		_conflicts.acceptAllServer();
            }
                        
	 [Bindable] [In]
	 public var identity:Identity;
            
         
	]]>
	</mx:Script>
</mx:Application>