Feeds:
Posts
Comments

Archive for the ‘Flex’ Category

I have been coding a lot in Flex Builder for the past couple of days. I have left the server side alone for a while and designing the client end now. Flex Builder saves a lot of time even when you are not using the drag and drop GUI builder. Have learned quite a few interesting things about Actions script during this period. Most notable of them are perhaps these two – Closure and Dynamic class. With closure, you can pass a method as an argument to another method and with dynamic class, well you can add properties to that class at runtime! I am hoping I will be able to utilize this dynamic nature into good use. Some of my other resent findings are –

  • The tags inside the mxml file can implement an Interface. While this is natural since a tag always refers to a class, at first I found it really interesting.
  • There is a nice flash debugger plugin that lets you debug your code.
  • To override a method, you have to mention override keyword in the method definition.
  • Setter getter methods – you write function set methodName() or function get methodName() to define setter and getter methods That was really new to me! 🙂

I found the Action script reference PDF really useful for learning the bits and pieces of Action script. However I am having real difficulty in adjusting to some of the syntaxes, specially while declaring a variable. I keep on doing it using the Java way and the compiler keeps on reminding me! 🙂

Thats it for today, hopefully more will come soon..

Read Full Post »

Step two in Flex

Yet another busy day with Flex. Started the day with the intention of concentrating full time in Flex and still it wasn’t until 8 PM that I did what I wanted to do! Nevertheless, at least I have achieved my target before going home for the weekend. 🙂

After my successful integration of BlazeDS with our Spring application, this time I tried to go further. Wanted to fetch live data from database and show them in Flex data grid. First I created an action script object equivalent to my Java Object and tried to access its properties in data grid. I learnt that data grid accesses properties directly, not using getter methods, so had to change my class properties to public. I have to study action script further to find out if its really the convention.

Anyway, then I remembered, since I am using action script object from my mxml file, I will have to tell the compiler about the class when I compile it using Ant. After a lot of hassle, turns out ant tasks that adobe provides are for Flex 2 and the command parameters mentioned in the document for mxmlc doesn’t work with ant tasks! To be sure, I ran the mxmlc command manually and it worked. So now I replace the ant task for compiling with this –

<target name=”compileflex”>
<exec command=”${FLEX_HOME}/bin/mxmlc
${web.dir}/mxml/main.mxml
-source-path ${web.dir}/flexsrc
-services ${web.dir}/WEB-INF/flex/services-config.xml
-context-root /ma
-output ${build.dir}/main.swf”>
</exec>
</target>

This ant target executes the mxmlc command directly with the necessary parameters. Before reaching at this point though, I had to fight through Spring+Hibernate issues in my Dao class. The new Dao class I created couldn’t get hibernate session and had to replaced it with Spring’s jdbc template. Most probably the hibernate issue was related to OpenSessionInViewInterceptor, I will investigate it later. For now, I am really relieved and happy to see my data grid getting filled with data from server. 🙂

Read Full Post »

Just finished configuring BlazeDS with Spring! 🙂

We have been thinking to include Flex in our J2EE application for a few months now. We believe integrating Flex as a client end application will vastly improve user experience and also improve on the code separation if we can design properly. BlazeDS is a server-based Java remoting and web messaging technology that enables developers to easily connect to back-end distributed data and push data in real-time to Flex applications. Both BlazeDS and Flex are open source products from Adobe.

After running the samples provided with BlazeDS download, I decided to have a go at it by trying to integrate it with Spring. Unfortunately I could not find any straight forward tutorial that could have guided me step by step. The closest I got was this tutorial that talks about integration of Spring with Adobe LiveCycle Data Service. Although I had to customize in few places, the tutorial was really helpful for my purpose.

BlazeDS download comes with a configured tomcat ready to run, which is pretty cool by the way! 🙂 Anyway, I chose to integrate Spring in the already deployed blazeds application under {blazeds}/tomcat/webapps. I followed all the steps of Example 1 in that tutorial considering my context root is {blazeds}/tomcat/webapps/blazeds. For example, when it asked me to copy jar files of Spring, I copied them to {blazeds}/tomcat/webapps/blazeds/WEB-INF/lib directory.

When it was time to run the application, as mentioned in Step 4, that didn’t work. The step asks to directly invoke the mxml file and assumes the Data Services application will compile it. I don’t think BlazeDS was configured for that feature yet. Therefore I had to take the help of Flex Builder 3 to compile the mxml file. I took the help of this tutorial to configure and create a J2EE project in Flex Builder. I followed all the 14 steps mentioned at the bottom of the page to create the project. I had to start my tomcat server to successfully validate the project configuration. Once that was done, rest was a piece of cake! The run button in Flex Builder automatically deploys the compiled swf file and opens it in browser.

Once my initial experiment was successful, I decided to create a formal project where I can work and use Ant to build and deploy my work. This is where things started to get rough! More on that later. So my first task was to write an Ant script that would deploy the necessary files in web server so that BlazeDS is deployed along with my project. I took the help of this nice and simple page to quickly get started with Ant. Then I had to install and configure Flex Ant Tasks and use it inside my build.xml to compile the mxml files. Once my script was ready, I thought I was done. But alas! the application was not working anymore. Remoting from my swf failed, it could not connect to the Spring service bean. After couple of hours of hair pulling time, I finally figured that the only difference between my current work and previous work (which ran successfully) is the compiled swf. Since we have to show the data service while creating a data service project, the Flex Builder must be doing something while compiling that my simple compile command was not doing. Once the problem was found, I looked into the compile command (mxmlc) in detail and found that I had to add -services and -context-root parameters to my mxmlc command. -services points to the services-config.xml file while context-root is the name of the context root, in my case – /blazeds. Then I used another build in ant task named html-wrapper that creates an html file for the corresponding swf, which makes it easier to view when deployed in web server. My Ant tasks now looks like this –

<target name=”compileflex”>
<mxmlc
file=”${web.dir}/mxml/main.mxml”
output=”${build.dir}/main.swf”
services=”${web.dir}/WEB-INF/flex/services-config.xml”
context-root=”/blazeds”
keep-generated-actionscript=”true”>
</mxmlc>
</target>

<target name=”wrapper” depends=”compileflex”>
<html-wrapper
title=”Welcome to My Flex App”
height=”300″
width=”400″
bgcolor=”red”
application=”app”
swf=”main”
version-major=”9″
version-minor=”0″
version-revision=”0″
history=”true”
template=”express-installation”
output=”${build.dir}”/>
</target>

Flex is cool to work with and I can’t wait to dive in deeper! Next stop is to find out how BlazeDS handles authentication and how can I get access to HttpSession.

Read Full Post »