Wednesday, November 29, 2006

What did we learn today kinder - Flex!

Well here we go again - nothing like midnightish programming. Today in webdev, we watched an Adobe Flex presentation on Flex Data Services. It had some really promising ideas (webcasts/chat rooms/games potentially). I had not had a chance to dive into Flex development yet so I thought this would be a good opportunity to kill two birds with one stone - learning Flex and integrating Flex with its Data Services.

As with any new language that you learn you have to start with the equivalent "Hello World" app which I did. It simply consisted of:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
   <mx:Panel title="My Application" width="200" height="300">
      <mx:Label text="Welcome to Flex!" mouseDownEffect="WipeRight" />
   </mx:Panel>
</mx:Application>

After saving and running the app within the bundled Flex Builder Application it worked! Ok this is super (thanks for asking)! Well I'm in a groove now so I then moved on to "How to pull in an RSS feed with Flex" I followed along with the handy dandy tutorial that came with Flex Builder and it worked perfectly (Good job Macrobe).

Well this looks like a double win for me, time to do some real testing - Data Services. First off I installed the Flex Data Services with the embedded JRUN J2EE server installed (I have ColdFusion MX, but for simplicity I chose to do it with the embedded version. So far so good. I installed it and ran the "Start Integrated Flex Server" icon; allowed it access within ZoneAlarm; hit the web page: http://127.0.0.1:8700/ and viola!! a web page shows up. I tinkered with the sample apps and they are very interesting. In general this gives me a NetMeeting-esque feeling. NM was desinged for sharing a whiteboard, computer space etc with multiple users. This was back in the 90s and now we are accomplishing this with Flash. Java had stuff like this back in the 90s as well with RMI.

[inserting wild tangent here]
My first experience with RMI was with a guy named Harry Baya. Back then in the Computer Center of Hofstra University we held a web page contest every year showcasing new technologies. At the time flash was in version 4 so you can imagine all of the timeline based movies :-) Harry decided to work on a game in Java using RMI (Remote Method Invocation). His game was almost like a Monopoly type board game where different users would control different pawns. Unfortunately the game never really panned out, but he did get the RMI stuff working and multiple users could connect with a java applet to his central server and move pieces around. It was really mind blowing at the time. After that Shockwave came out with their version of an xml socket server which is still used today with many multiplayer games. And now back to the topic at hand - Flex Data Services
[/inserting wild tangent here]

So far so good, I can run the sample applications, but can I build my own? To quote Bob the Builder, "Yes We Can!" (well I only found that out after about a half hour of trying). So here we go:

First off, it helps to RTFM. I started with: Macrobe's Note's example. It seemed like a good place to start.

Here's a little Flex Builder info that I ran into - When you configure your project to use Data Services, it asks you for the WEB-INF/flex root folder. If you are working on the samples web app, you would specify the web root of:
C:\fds2\jrun4\servers\default\samples

And a url of:
http://localhost:8700/samples

Oh one more thing - by default JRUN runs off of port 8700 with this version. Now keep in mind that Flex Builder will create a folder with the project name that you choose. So in the documentation if you want to put this into the "DSLessons" folder as per the instructions, make your project name that.

I went through page by page looking at the code and copying it into my Flex Builder. I built an application called "lesson1" as per the instructions in Flex Builder (if I truly followed the instructions I would have used DSLessons, but you know I'm a bad ass). After that the directions said to add the "destination id" to the data-management-config.xml and had no problems in the sample area (especially since it was already there for me!). After putting all the code into Flex Builder and compiling and opening two browsers, Viola, it worked! Here is my sample code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="100%" height="100%" creationComplete="initApp();">
   <mx:Script>
   <![CDATA[
   /* IMPORT STATEMENTS */
      import mx.data.DataService;
      import mx.data.events.*;
      import mx.rpc.AsyncToken;
      import mx.rpc.events.*;
      import mx.messaging.events.*;
      import mx.utils.ObjectProxy;
      /* GLOBAL VARS */
      public var noteObj:Object = new Object();
      public var getToken:AsyncToken;
      private var ds:DataService;
      [Bindable]
      public var noteProxy:ObjectProxy;
      
      public function initApp():void {
         ds = new DataService("notes");
         ds.addEventListener(ResultEvent.RESULT, resultHandler);
         ds.autoCommit = false;
         noteObj.noteId = 1;
         noteObj.noteText = "Type your notes here and share them with other clients!";
         getToken = ds.getItem(noteObj, noteObj);
      }
      
      public function resultHandler(event:ResultEvent):void {
         if (event.token == getToken)
            noteProxy = ObjectProxy(event.result);
      }
      
   ]]>
   </mx:Script>
   <mx:Binding source="log.text" destination="noteProxy.noteText"/>
   <mx:TextArea id="log" width="549" height="216" text="{noteProxy.noteText}" x="27" y="24"/>
   <mx:Button x="269" y="265" label="Button" click="ds.commit();"/>   
</mx:Application>


UPDATE 1/6/2007!
Click here for the project files - including mxml

Tuesday, November 21, 2006

Java CFX and Jar Hell

While this topic may not come up all that often, it came up recently for me. I started to play around with building Java CFX tags for ColdFusion to add in some functionality. While I could have just invoked the java code within CF, I chose to try learning how to build a CFX tag. So first off I went with the absolute basic - the Hello World Application:
import com.allaire.cfx.*;
public class HelloWorld implements CustomTag
{
   public void processRequest(Request request, Response response) throws Exception
   {
      response.write("Hello World");
   }
}

Now comes the compiling part. This was a little tricky, but the only key to this is knowing that you have to include the classpath to your cfx.jar file in order for it to compile properly. The following example assumes javac is in your path and you are in the same directory as HelloWorld.java:
javac HelloWorld.java -classpath "C:\JRun4\servers\cfusion\cfusion-ear\cfusion-war\WEB-INF\lib\cfx.jar"

Once that compiles properly put it in the "C:\JRun4\servers\cfusion\cfusion-ear\cfusion-war\WEB-INF\ classes" folder.

Now register it within the CF Administrator by going to the Extensions -> CFX left navigation and choose "Register Java CFX". Then make the tag name CFX_HelloWorld and make the Class name "HelloWorld" (sans quotes and Case Sensitive based on the name of your class file you just compiled)

To call this on a .cfm page use:
<cfx_HelloWorld/>

(not case sensitive). That's it!!! However I started to think - hmmm applications can have more than one class file, so normally I would just jar the files. Simple enough in theory. HOWEVER, after spending several hours trying to get a JAR to work by putting it in various areas (classes folder etc and even adding it to the JRun classpath) I had to resort to asking for Macrobe (it's hard to get away from Macromedia and calling them Adobe) help through their support line. They were very helpful and in one simple e-mail they said that all you have to do to get a jar to work is put the jar in "C:\JRun4\servers\cfusion\cfusion-ear\cfusion-war\WEB-INF\lib" and restart the server. Registration within the cfadmin is the same for the class. For my simple example I took the same HelloWorld class file and jar'd it. Then I named the jar the same as the class file and put it in the lib folder. After a restart, it worked! Whew - I wish I knew that many hours ago. Just for a little background - I was using CFMX 7.0.2 with JRun 4 with the JDK 1.4.2_12 (the version of the Java SDK should match the JVM version of your ColdFusion Server)

Hopefully my little walk around the park will help someone else out since Google didn't seem to help this time. Good Luck!

Wednesday, November 15, 2006

Traffic Rant and Introducing kHTTP!

Well it has been a few days since I last posted and I first want to start off with a little non technical rant about NY/NJ roadways. PEOPLE NEED TO LEARN HOW TO DRIVE IN THE RAIN!!!

Ok enough said about that, on to bigger and better things!!! A while ago I was learning some VB using Visual Studio .NET (btw an excellent IDE imo - one of my favorite features is the tag insight which includes your own custom functions). I wanted to learn more about how to develop a command line application for doing HTTP calls. This originally came about because of my work at Hofstra University. We use this job scheduling software called AppWorx which unfortunately can't make a simple HTTP request, but can execute any other program under the sun. Well I figured - how hard could this be to write a command line program that will make a request to get a page. Turns out it wasn't that bad in VB. Click the link below to download my program khttp.exe (win only). Type khttp.exe -help for usage. This little program will return information like the headers/page content/date modified etc. For a quick demo try:

khttp.exe -a "http://www.google.com"


Let me know what you think, and if you do happen to like it or use it somewhere drop me a message I would be very interested in hearing how it is used.

Click here to download khttp.zip

(the usual rules about downloading strange applications applies - always check for viruses - if this blows up your machine it is not my fault - blah blah).

Tuesday, November 07, 2006

And here we are!

Well long after blogging has started I have been coerced into starting a blog too. Brian has built quite the following with his blog: WebDev Central, and who am I not to jump in and let my $.02 be heard too! I hope to discuss varying topics from programming, to anything that is really cool that we found on the internet.

As my first order of geekdom, I highly recommend the Daily Buzz from CNET. This is a podcast of 3 CNET editors who discuss up to date topics that affect current technology. Their shows of indefinite length generally run about 25 minutes.

As my second order of geekdom, I want to talk about something new from Microsoft - Live Maps (maps.live.com). This is Microsoft's version of Google maps and I have to say that while they put their best foot forward they fell a little short. Google maps is very streamlined and works well in modern browsers.

I tried Live in Firefox 2.0 and it functions, but you lose out on 'cool' functionality. What is cool you may ask - well if you use IE 6+ and download their ActiveX image enhancer, you can now look at a few select cities in a new way - from a horizon view to a complete top down AND it is 3d meaning the actual buildings have height to them. At first I thought this was great eye candy and would eventually save the world, but then the geek in me started to realize that this must have been a massive undertaking to get all of the buildings in 3d like that for the entire city. I quickly got bored of this candy and then I decided to see what happens when you look around.

First I checked out the Hofstra University area and for some reason that area was in greyscale in this view. If I try it in 2d version with the topigraphical turned on, it looks ok, but in the super 3d it looks like crap. Ok well it is basically a beta and it is Microsoft so I chalked it up to business as usual. So then I went looking around Las Vegas. The buildings are really cool, but what did I see off to the distance in the northwest quadrant, but a freaking car advertisement!!! No one would have ever believed me if I hadn't taken a screen shot. Well lucky you, you get to see it too. All I have to say to Microsoft is:

LAME