Monday, September 27, 2010

Java-Flex Demo using Blaze-ds in eclipse

  Install eclipse GANYMEDE
Install flex plug-in for eclipse
Install tomcat
Download Blaze-ds

Steps: 1 Create flex-java project

open eclipse
file->create flex project
Give project name "FlexJavaDemo"
Choose Application server type: "J2EE"
Replace name of the javasource folder: "javaSource"
Click on next button

Step: 2 Configure J2EE Server

Target runtime: "Apache Tomcat v6.0"
Context root: "FlexJavaDemo"
Content folder: "WebContent"
Flex War file: browse file from your pc "blazeds.war" (from blaze-ds folder)
click on next buton

Step: 3 Create a Flex project

Main source folder: "flexSource"
Main application file: "FlexJavaDemo.mxml"
Output folder URL: http://localhost:8080/FlexJavaDemo
Click on finish button

Step: 4 Create a login form in the flex main application file






import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;

private function loginClickHandler():void
{
remoteObject.printName(un.text,p.text);
}
private function resultHandler(evt:ResultEvent):void
{
Alert.show("Done");
}

private function faultHandler(evt:FaultEvent):void
{
Alert.show(evt.fault +"");
}
]]>














result="resultHandler(event)"
fault="faultHandler(event)">



Step:5


open file "remoting-config.xml" (/FlexJavaDemo/WebContent/WEB-INF/flex/remoting-config.xml")
Add the following code



services.myJavaFile


Note: we define "destination1" with the remoteobject tag inside the flex application(see in step: 4).

Step: 6

Create a folder inside the "javaSource" folder and named "services"
create a java file inside "services" folder and named "myJavaFile.java"

Note: we define this path(services.myJavaFile) inside the remoting-config.xml (see in Step: 5)

Step: 7

create a function inside a java file(myJavaFile.java)
public void printName(String userName, String password)
{
System.out.println("spring Service ------ "+userName +" "+password);
}

Note: We define this function name in flex application and passed username and password (see in step: 4).

Step: 8 Run the application

right click on the application
click on "run as"
Select "run on server"
add app into the server
enter username and password and click on login button.......
You will get a alert and check the username and password on the console

--
Regards
Rohit Bhatia

No comments:

Post a Comment