Saturday, March 14, 2009

Part Three Getting a sample flex app to work

Well prior to all this some googling had brought me to Christophe Coenraets great page on getting LCDS to work with a Flex application. He was nice enough to write an AIR based contact management application that uses LCDS to connect to the sample database. He includes all his source code, a compiled version of the application, as well as the server side code and compiled java classes. I highly recommend reading through all of this as it helped me understand how all this works. Check it out here. Now download all the project files, and install the air application. We'll use that as our litmus test to whether this works or not. Since I'm using JBoss my setup was a bit different than his. I don't have any of the directories he's talking about and just dumping the files into the deploy directory doesn't work. This brings me to the point of actually learning what a .war file is. I'm sure there's a complex explination but it turns out it's just a zipped up collection of files. In there are the java classes, some configuration xml files, you name it. JBoss seems to like to use those so that's what we'll have to do. Now since you've been following along you have an lcds-samples.war file in your deploy directory. This part took a while for me to understand, maybe I was just slow that day. What the example wants you to do is take his files and put them in the classes directory. But where is that directory? Try searching for it you won't find it. The ah ha moment for me was when I realized that it was "inside" the lcds-samples.war file. Maybe that's obvious to some people but not to me. So how to we get in there? It's pretty simple just unzip the .war file. Watch it thought it just expands into whatever directory you're in. What I did was create another directory called test, still under the JBoss default/deploy directory and then I moved lcds-samples.ware into test. Then I opened up another termial window and navigated to that directory. Now just type unzip lcds-samples.war and behold it creates the whole directory structure before your very eyes. You'll find the folder to put Christophe's example under WEB-INF-->flex-->classes. Just drag his lcds folder into here. But wait you're not done yet, go back up one directory level to WEB-INF-->flex. Here you'll find the data-managment-config.xml file that he and most other examples are asking you to add some description code to. If you don't add this when you run his program you'll get an error saying can't fill, and you'll see an exception on your JBoss terminal window. I don't know too much about this but it appears to be a description that tells JBoss how to handle an incoming request and what program to pass it on to. Once you've done all that you need to pack it back up into a war file. I removed the original lcds-samples.war file, you may want to move it to lcds-samples.bak. Just go up to the test directory in your terminal window and type "jar -cvf lcds-samples.war *". That should create the new lcds-samples.war file that you need. Think you're done? Not so fast, this example also needs some data. That data is put in the same sample database application that we started up before. Just take the files in his sampledb and copy them into yours. It will want to overwrite which is ok. If you compare the files you'll see his contains everything the default one does plus his example. So do that restart the database, restart jboss, and try to run his air application. If you see names and contact information appear in the application, then congratulations you got it to work. Next up is getting the flex application code to compile so I can make changes. When I figure that out I'll add it here.

No comments:

Post a Comment