<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-5712470018526280356</id><updated>2012-01-26T05:21:32.339-08:00</updated><category term='yahoo'/><category term='url'/><category term='Microphone'/><category term='javascript'/><category term='flex 3'/><category term='encoding'/><category term='inline item editor'/><category term='flex3'/><category term='transparent'/><category term='jboss 4.2.3'/><category term='DataGrid'/><category term='Adobe LiveCycle DS'/><category term='tomcat'/><category term='event'/><category term='DisplayObject'/><category term='red5'/><category term='systemChrome'/><category term='struts2+flex'/><category term='concatenate'/><category term='struts 2.1'/><category term='EJB'/><category term='number of http requests'/><category term='css'/><category term='Parallel'/><category term='FileUploadInterceptor'/><category term='horizontalCenter'/><category term='js'/><category term='Camera'/><category term='BlazeDS'/><category term='HttpService'/><category term='event listener'/><category term='Move'/><category term='TimerEvent'/><category term='WindowedApplication'/><category term='item editor'/><category term='actionscript'/><category term='struts 2'/><category term='Adobe Air'/><category term='hierarchical action'/><category term='ArrayCollection'/><category term='ant'/><category term='absolute'/><category term='component lifecycle'/><category term='FileReference'/><category term='UTF-8'/><category term='Web Services'/><category term='yslow'/><category term='verticalCenter'/><category term='EJB 3'/><category term='constraint'/><category term='flex'/><category term='seo'/><category term='struts+flex'/><category term='yui compressor'/><category term='Tween'/><category term='creation policy'/><category term='Timer'/><category term='SortField'/><category term='blendMode'/><category term='adobe flex'/><category term='minify'/><category term='Resize'/><category term='jboss'/><category term='file upload'/><category term='autoLayout'/><category term='netconnection'/><category term='Sequence'/><category term='netstream'/><category term='AMF'/><title type='text'>Armindo Cachada's Blog: Struts 2, Adobe Flex and ATG</title><subtitle type='html'>In this blog I talk about Struts 2, Adobe Flex, JBOSS, ATG and other technologies.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://simplyolaf.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5712470018526280356/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://simplyolaf.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Armindo Cachada</name><uri>http://www.blogger.com/profile/17668696197506133653</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>22</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5712470018526280356.post-1061706957902499162</id><published>2009-08-03T13:24:00.000-07:00</published><updated>2009-09-05T10:05:05.262-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='transparent'/><category scheme='http://www.blogger.com/atom/ns#' term='WindowedApplication'/><category scheme='http://www.blogger.com/atom/ns#' term='systemChrome'/><category scheme='http://www.blogger.com/atom/ns#' term='Adobe Air'/><title type='text'>Creating your first Adobe Air Application</title><content type='html'>Adobe Air is a great extension to the Adobe Flex framework that allows almost anyone to create rich internet applications for the desktop. With Adobe Air the same applications will run on Microsoft Windows, Mac OS X and Linux with pretty much no operating system dependent code. There are some exceptions though but that we will discuss later.&lt;br /&gt;&lt;br /&gt;This tutorial is the first part of a tutorial series on how to build a File Manager using Adobe Air's out of the box components. This file manager will have Drag &amp; Drop capabilities, within the file manager itself, to copy or move files between directories. It will have native drag &amp; drop capabilities to copy files from the desktop directly to the file manager. Or the other way around. Finally we will also add a navigational menu to the file manager to demonstrate some more useful out of the box Adobe Air components.&lt;br /&gt;&lt;br /&gt;But before we go into all that let's create our first "Hello World" Adobe Air application.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Step 1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Create a new project in Flex Builder but this time select the radio button that says 'Desktop Application'&lt;br /&gt;&lt;br /&gt;Depending on how you named your project you will see two files in your project. For example if you named it &lt;b&gt;AirFileManager&lt;/b&gt; you will see an &lt;b&gt;AirFileManager.mxml&lt;/b&gt; file and a &lt;b&gt;AirFileManager-app.xml&lt;/b&gt;. The mxml file is the file where you will put the initial code. &lt;br /&gt;Notice the &lt;b&gt;WindowedApplication&lt;/b&gt; top level node that is created. This is the Adobe Air equivalent of the &lt;b&gt;Application&lt;/b&gt; component in Flex. The main difference being that a &lt;b&gt;WindowedApplication&lt;/b&gt; is not restricted to run in a browser, it runs on a desktop, and provides some extra features.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;AirFileManager-app.xml&lt;/b&gt; file is an application descriptor file where you will configure certain parameters related to your Adobe Air Application. Parameters like transparency, system chrome, name, filename, copyright, window initial size and icon will be configured in this file. &lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Step 2&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Add the following code:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;&amp;lt;mx:WindowedApplication xmlns:mx=&amp;quot;http://www.adobe.com/2006/mxml&amp;quot; layout=&amp;quot;absolute&amp;quot;&amp;gt;&lt;br /&gt; &amp;lt;mx:Button label=&amp;quot;Click me&amp;quot; click=&amp;quot;mx.controls.Alert.show('I have just created my first Adobe Air App!')&amp;quot;/&amp;gt; &lt;br /&gt;&amp;lt;/mx:WindowedApplication&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Step 3&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Execute the Air app by clicking on the run method.&lt;br /&gt;&lt;br /&gt;Congratulations! You have just created &amp; executed your first Adobe Air app. But don't go out to celebrate yet... that was just to break the ice.&lt;br /&gt;&lt;br /&gt;Let's make some modifications to the application descriptor. &lt;br /&gt;Notice the &lt;b&gt;systemChrome&lt;/b&gt; and &lt;b&gt;transparency&lt;/b&gt; property. The &lt;b&gt;systemChrome&lt;/b&gt; property tells Adobe Air whether to use the operating system native chrome or not. The &lt;b&gt;transparency&lt;/b&gt; property is used to determine if the application window will be transparent or opaque. Note however that transparency is only supported if you set the &lt;b&gt;systemChrome&lt;/b&gt; to &lt;b&gt;none&lt;/b&gt;. If you set &lt;b&gt;systemChrome&lt;/b&gt; to &lt;b&gt;standard&lt;/b&gt; the operating system chrome is used and therefore Adobe Air can't support transparency as it is outside its control.&lt;br /&gt;Note that the default value for the &lt;b&gt;systemChrome&lt;/b&gt; is &lt;b&gt;standard&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;To test this feature add a &lt;b&gt;backgroundAlpha&lt;/b&gt; of &lt;b&gt;0.5&lt;/b&gt; to the &lt;b&gt;WindowedApplication&lt;/b&gt; component.&lt;br /&gt;And modify AirFileManager-app.xml to:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;&lt;br /&gt;&amp;lt;application xmlns=&amp;quot;http://ns.adobe.com/air/application/1.5&amp;quot;&amp;gt;&lt;br /&gt; &amp;lt;!-- The application identifier string, unique to this application. Required. --&amp;gt;&lt;br /&gt; &amp;lt;id&amp;gt;AirFileManager&amp;lt;/id&amp;gt;&lt;br /&gt;&lt;br /&gt; &amp;lt;!-- Used as the filename for the application. Required. --&amp;gt;&lt;br /&gt; &amp;lt;filename&amp;gt;AirFileManager&amp;lt;/filename&amp;gt;&lt;br /&gt;&lt;br /&gt; &amp;lt;!-- The name that is displayed in the AIR application installer. &lt;br /&gt;      May have multiple values for each language. See samples or xsd schema file. Optional. --&amp;gt;&lt;br /&gt; &amp;lt;name&amp;gt;AirFileManager&amp;lt;/name&amp;gt;&lt;br /&gt;&lt;br /&gt; &amp;lt;!-- An application version designator (such as &amp;quot;v1&amp;quot;, &amp;quot;2.5&amp;quot;, or &amp;quot;Alpha 1&amp;quot;). Required. --&amp;gt;&lt;br /&gt; &amp;lt;version&amp;gt;v1&amp;lt;/version&amp;gt;&lt;br /&gt;&lt;br /&gt; &amp;lt;!-- Settings for the application's initial window. Required. --&amp;gt;&lt;br /&gt; &amp;lt;initialWindow&amp;gt;&lt;br /&gt;  &amp;lt;content&amp;gt;[This value will be overwritten by Flex Builder in the output app.xml]&amp;lt;/content&amp;gt;&lt;br /&gt;  &amp;lt;systemChrome&amp;gt;none&amp;lt;/systemChrome&amp;gt;&lt;br /&gt;               &amp;lt;transparent&amp;gt;true&amp;lt;/transparent&amp;gt;&lt;br /&gt; &amp;lt;/initialWindow&amp;gt;&lt;br /&gt;&amp;lt;/application&amp;gt;&lt;/pre&gt;&lt;br /&gt;Run the Adobe Air application and see the difference in the application window. It should look transparent now.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Deploying Adobe Air Applications&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Now that you have created your first Adobe Air application, you should package it into an AIR file. If you are using Flex Builder:&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;Right click your project folder and select &lt;b&gt;Export&lt;/b&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;In the next screen choose &lt;b&gt;Release Build&lt;/b&gt; and click &lt;b&gt;Next&lt;/b&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;If you want to include the source code with your release click on &lt;b&gt;Enable View Source&lt;/b&gt; and then click &lt;b&gt;Next&lt;/b&gt;.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;In this screen you are asked for a digital certificate to include with your Adobe Air application. You can either specify a digital signature provided by a third party like Verisign or Thawte. If you don't have one then click &lt;b&gt;Create&lt;/b&gt; to create your own self-signed digital certificate. Although you can can create your own digital certificate, it is not the best option as it doesn't provide assurance to the users that your application is safe or that it hasn't been tampered.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Type your digital certificate password and click next&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Select the files you want to include in your package and then click finish.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Your AIR installation package should have been created in the same directory as your project. Use this file to distribute your application.&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;That will be all for now. In the next part of this tutorial we will start adding the file manager components with which we will create a simple but yet powerful file manager in &lt;b&gt;Adobe Air&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.spltech.co.uk/blog/adobe-air/creating-a-file-manager-in-adobe-flex"&gt;Click here to read the next part of this tutorial&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5712470018526280356-1061706957902499162?l=simplyolaf.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://simplyolaf.blogspot.com/feeds/1061706957902499162/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5712470018526280356&amp;postID=1061706957902499162' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5712470018526280356/posts/default/1061706957902499162'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5712470018526280356/posts/default/1061706957902499162'/><link rel='alternate' type='text/html' href='http://simplyolaf.blogspot.com/2009/08/creating-your-first-adobe-air.html' title='Creating your first Adobe Air Application'/><author><name>Armindo Cachada</name><uri>http://www.blogger.com/profile/17668696197506133653</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5712470018526280356.post-8123090361190898191</id><published>2009-07-30T04:53:00.000-07:00</published><updated>2009-07-30T06:15:49.841-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='DisplayObject'/><category scheme='http://www.blogger.com/atom/ns#' term='adobe flex'/><category scheme='http://www.blogger.com/atom/ns#' term='blendMode'/><title type='text'>Adobe Flex: The DisplayObject Blend Mode</title><content type='html'>The blend mode controls what happens when one display object is on top of another. The default setting in Adobe Flex is that the pixels of a display object override those that are displayed in the background. However you can change this behavior by modifying the &lt;b&gt;blendMode&lt;/b&gt; setting. Read the language reference entry for &lt;a href="http://livedocs.adobe.com/flex/3/langref/flash/display/DisplayObject.html"&gt;DisplayObject&lt;/a&gt;. There you will find a detailed description of each blend mode.&lt;br /&gt;In a nutshell the different blend modes available are:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;BlendMode.NORMAL&lt;/li&gt;&lt;br /&gt;&lt;li&gt;BlendMode.LAYER&lt;/li&gt;&lt;br /&gt;&lt;li&gt;BlendMode.MULTIPLY&lt;/li&gt;&lt;br /&gt;&lt;li&gt;BlendMode.SCREEN&lt;/li&gt;&lt;br /&gt;&lt;li&gt;BlendMode.LIGHTEN&lt;/li&gt;&lt;br /&gt;&lt;li&gt;BlendMode.DARKEN&lt;/li&gt;&lt;br /&gt;&lt;li&gt;BlendMode.DIFFERENCE&lt;/li&gt;&lt;br /&gt;&lt;li&gt;BlendMode.DARKEN&lt;/li&gt;&lt;br /&gt;&lt;li&gt;BlendMode.OVERLAY&lt;/li&gt;&lt;br /&gt;&lt;li&gt;BlendMode.ADD&lt;/li&gt;&lt;br /&gt;&lt;li&gt;BlendMode.SUBTRACT&lt;/li&gt;&lt;br /&gt;&lt;li&gt;BlendMode.INVERT&lt;/li&gt;&lt;br /&gt;&lt;li&gt;BlendMode.ALPHA&lt;/li&gt;&lt;br /&gt;&lt;li&gt;BlendMode.ERASE&lt;/li&gt;&lt;br /&gt;&lt;li&gt;BlendMode.SHADE&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;Use the following flex code to try the different blend modes:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;&amp;lt;mx:Application xmlns:core=&amp;quot;*&amp;quot; xmlns:mx=&amp;quot;http://www.adobe.com/2006/mxml&amp;quot; layout=&amp;quot;vertical&amp;quot; height=&amp;quot;600&amp;quot; width=&amp;quot;600&amp;quot; horizontalAlign=&amp;quot;left&amp;quot;&amp;gt;&lt;br /&gt; &amp;lt;mx:ArrayCollection id=&amp;quot;blendModes&amp;quot;&amp;gt;&lt;br /&gt;  &amp;lt;mx:Array&amp;gt;&lt;br /&gt;   &amp;lt;mx:Object label=&amp;quot;Normal&amp;quot; data=&amp;quot;normal&amp;quot;/&amp;gt;&lt;br /&gt;   &amp;lt;mx:Object label=&amp;quot;Layer&amp;quot; data=&amp;quot;layer&amp;quot;/&amp;gt;&lt;br /&gt;   &amp;lt;mx:Object label=&amp;quot;Multiply&amp;quot; data=&amp;quot;multiply&amp;quot;/&amp;gt;&lt;br /&gt;   &amp;lt;mx:Object label=&amp;quot;Screen&amp;quot; data=&amp;quot;screen&amp;quot;/&amp;gt;&lt;br /&gt;   &amp;lt;mx:Object label=&amp;quot;Lighten&amp;quot; data=&amp;quot;lighten&amp;quot;/&amp;gt;&lt;br /&gt;   &amp;lt;mx:Object label=&amp;quot;Darken&amp;quot; data=&amp;quot;darken&amp;quot;/&amp;gt;&lt;br /&gt;   &amp;lt;mx:Object label=&amp;quot;Difference&amp;quot; data=&amp;quot;difference&amp;quot;/&amp;gt; &lt;br /&gt;   &amp;lt;mx:Object label=&amp;quot;Overlay&amp;quot; data=&amp;quot;overlay&amp;quot;/&amp;gt;&lt;br /&gt;   &amp;lt;mx:Object label=&amp;quot;ADD&amp;quot; data=&amp;quot;add&amp;quot;/&amp;gt;&lt;br /&gt;   &amp;lt;mx:Object label=&amp;quot;Subtract&amp;quot; data=&amp;quot;subtract&amp;quot;/&amp;gt;&lt;br /&gt;   &amp;lt;mx:Object label=&amp;quot;Invert&amp;quot; data=&amp;quot;invert&amp;quot;/&amp;gt;&lt;br /&gt;   &amp;lt;mx:Object label=&amp;quot;Alpha&amp;quot; data=&amp;quot;alpha&amp;quot;/&amp;gt;&lt;br /&gt;   &amp;lt;mx:Object label=&amp;quot;Erase&amp;quot; data=&amp;quot;erase&amp;quot;/&amp;gt;&lt;br /&gt;  &amp;lt;/mx:Array&amp;gt;&lt;br /&gt; &amp;lt;/mx:ArrayCollection&amp;gt;&lt;br /&gt; &amp;lt;mx:Canvas height=&amp;quot;200&amp;quot; width=&amp;quot;400&amp;quot;&amp;gt;&lt;br /&gt;  &amp;lt;mx:VBox height=&amp;quot;100&amp;quot; width=&amp;quot;100&amp;quot; backgroundColor=&amp;quot;{color1.selectedColor}&amp;quot; backgroundAlpha=&amp;quot;1&amp;quot; blendMode=&amp;quot;{blendMode1.selectedItem.data}&amp;quot; /&amp;gt;&lt;br /&gt;  &amp;lt;mx:VBox height=&amp;quot;100&amp;quot; width=&amp;quot;100&amp;quot; backgroundColor=&amp;quot;{color2.selectedColor}&amp;quot; backgroundAlpha=&amp;quot;1&amp;quot;  x=&amp;quot;50&amp;quot; y=&amp;quot;50&amp;quot; blendMode=&amp;quot;{blendMode2.selectedItem.data}&amp;quot;/&amp;gt;&lt;br /&gt; &amp;lt;/mx:Canvas&amp;gt;&lt;br /&gt; &amp;lt;mx:Panel title=&amp;quot;Blend Modes&amp;quot; layout=&amp;quot;horizontal&amp;quot;&amp;gt;&lt;br /&gt;  &amp;lt;mx:ComboBox id=&amp;quot;blendMode1&amp;quot; dataProvider=&amp;quot;{blendModes}&amp;quot; /&amp;gt;&lt;br /&gt;  &amp;lt;mx:ComboBox id=&amp;quot;blendMode2&amp;quot; dataProvider=&amp;quot;{blendModes}&amp;quot;/&amp;gt;&lt;br /&gt; &amp;lt;/mx:Panel&amp;gt;&lt;br /&gt; &amp;lt;mx:Panel title=&amp;quot;Colors&amp;quot;&amp;gt;&lt;br /&gt;  &amp;lt;mx:ColorPicker id=&amp;quot;color1&amp;quot;/&amp;gt;&lt;br /&gt;  &amp;lt;mx:ColorPicker id=&amp;quot;color2&amp;quot; selectedColor=&amp;quot;blue&amp;quot;/&amp;gt;&lt;br /&gt; &amp;lt;/mx:Panel&amp;gt;&lt;br /&gt;&amp;lt;/mx:Application&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Click &lt;a href="http://files.spltech.co.uk.s3.amazonaws.com/FlexExamples/FlexBlendMode.html"&gt;here&lt;/a&gt; to try the example.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5712470018526280356-8123090361190898191?l=simplyolaf.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://simplyolaf.blogspot.com/feeds/8123090361190898191/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5712470018526280356&amp;postID=8123090361190898191' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5712470018526280356/posts/default/8123090361190898191'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5712470018526280356/posts/default/8123090361190898191'/><link rel='alternate' type='text/html' href='http://simplyolaf.blogspot.com/2009/07/adobe-flex-displayobject-blend-mode.html' title='Adobe Flex: The DisplayObject Blend Mode'/><author><name>Armindo Cachada</name><uri>http://www.blogger.com/profile/17668696197506133653</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5712470018526280356.post-9034462210167139568</id><published>2009-07-24T01:14:00.000-07:00</published><updated>2009-07-24T05:25:06.010-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='EJB 3'/><category scheme='http://www.blogger.com/atom/ns#' term='EJB'/><category scheme='http://www.blogger.com/atom/ns#' term='flex 3'/><category scheme='http://www.blogger.com/atom/ns#' term='adobe flex'/><category scheme='http://www.blogger.com/atom/ns#' term='jboss'/><category scheme='http://www.blogger.com/atom/ns#' term='BlazeDS'/><title type='text'>Integrate Adobe Flex and JBOSS using BlazeDS - Part II</title><content type='html'>In the first part of this tutorial I showed you an example on how to integrate flex with JBOSS using BlazeDS. In this example we used RemoteObject in Actionscript to create a new instance of uk.co.spltech.remote.RemoteService and call the callMe() method remotely. The method returned a list of strings that we used to populate a datagrid.&lt;br /&gt;In the second part of this tutorial we will do something slightly more useful. This time we will be invoking an EJB 3.0 bean managed by the application server.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Step 1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;To be able to invoke EJB 3.0 from flex you need to download and copy &lt;a href="http://www.adobe.com/cfusion/exchange/index.cfm?event=extensionDetail&amp;extid=1089970#"&gt;FlexEJBFactory.jar&lt;/a&gt; to $JBOSS_HOME/server/default/lib. Or you can copy it to a local directory in your project separate from JBOSS e.g. example7/jbosslib and add the following line to $JBOSS_SERVER/server/default/conf/jboss-service.xml:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;classpath codebase=&amp;quot;/usr/java/eclipse/workspace/example7/jbosslib&amp;quot; archives=&amp;quot;*&amp;quot;/&amp;gt;&lt;/pre&gt;&lt;br /&gt;Previously all the BlazeDS jars were located in the WAR:WEB-INF/lib directory. But this is not going to work now because we need to see the jars within the context of the entire EAR. For that reason we need to move all those jars to to $JBOSS_SERVER/server/default/lib(or to a local directory inside your project e.g. jbosslib):&lt;br /&gt;&lt;br /&gt;flex-ejb-factory.jar&lt;br /&gt;flex-messaging-common.jar&lt;br /&gt;flex-messaging-core.jar&lt;br /&gt;flex-messaging-opt.jar&lt;br /&gt;flex-messaging-proxy.jar&lt;br /&gt;flex-messaging-remoting.jar&lt;br /&gt;backport-util-concurrent.jar&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Step 2&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Because we will be invoking EJB 3.0 components we need to change the build process so that it creates an EAR file instead of a WAR. We add the following lines to the &lt;b&gt;createjars&lt;/b&gt; target:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;jar jarfile=&amp;quot;build/example7.jar&amp;quot;&amp;gt;&lt;br /&gt; &amp;lt;fileset dir=&amp;quot;${build.classes.dir}&amp;quot;&amp;gt;&lt;br /&gt;    &amp;lt;include name=&amp;quot;uk/co/spltech/remote/*.class&amp;quot; /&amp;gt;&lt;br /&gt; &amp;lt;/fileset&amp;gt;&lt;br /&gt;       &lt;br /&gt;    &amp;lt;/jar&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;zip zipfile=&amp;quot;build/example7.ear&amp;quot;&amp;gt;&lt;br /&gt; &amp;lt;zipfileset dir=&amp;quot;build&amp;quot;&amp;gt;&lt;br /&gt;  &amp;lt;include name=&amp;quot;example7.war&amp;quot; /&amp;gt;&lt;br /&gt; &amp;lt;/zipfileset&amp;gt;&lt;br /&gt; &amp;lt;zipfileset dir=&amp;quot;${build.dir}/resources&amp;quot; prefix=&amp;quot;META-INF&amp;quot;&amp;gt;&lt;br /&gt;  &amp;lt;include name=&amp;quot;application.xml&amp;quot; /&amp;gt;&lt;br /&gt; &amp;lt;/zipfileset&amp;gt;&lt;br /&gt;       &amp;lt;zipfileset dir=&amp;quot;build&amp;quot;&amp;gt;&lt;br /&gt;  &amp;lt;include name=&amp;quot;example7.jar&amp;quot; /&amp;gt;&lt;br /&gt; &amp;lt;/zipfileset&amp;gt;&lt;br /&gt;     &amp;lt;/zip&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Step 3&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Add the new ejb3 factory to flex/services-config.xml:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;factories&amp;gt;&lt;br /&gt;     &amp;lt;factory id=&amp;quot;ejb3&amp;quot; class=&amp;quot;com.adobe.ac.ejb.EJB3Factory&amp;quot;/&amp;gt;&lt;br /&gt; &amp;lt;/factories&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Step 4&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Inside the &lt;b&gt;uk.co.spltech.remote&lt;/b&gt; package create the following classes:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;package uk.co.spltech.remote;&lt;br /&gt;&lt;br /&gt;import java.util.List;&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt; * This is an example of an interface where you can&lt;br /&gt; * declare all the methods that you want to call remotely&lt;br /&gt; * &lt;br /&gt; * @author Armindo Cachada&lt;br /&gt; *&lt;br /&gt; */&lt;br /&gt;public interface RemoteService {&lt;br /&gt; /**&lt;br /&gt;  * I am not doing anything useful except to just show that I can be invoked remotely&lt;br /&gt;  * from Adobe Flex using RemoteObject.&lt;br /&gt;  * &lt;br /&gt;  */&lt;br /&gt; public List&amp;lt;String&amp;gt; callMe();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;And the implementation of the interface:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;package uk.co.spltech.remote;&lt;br /&gt;&lt;br /&gt;import java.util.ArrayList;&lt;br /&gt;import java.util.List;&lt;br /&gt;&lt;br /&gt;import javax.ejb.Local;&lt;br /&gt;import javax.ejb.Stateless;&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt; * This remote service is called using BlazeDS/LiveCycle DS from Flex&lt;br /&gt; * &lt;br /&gt; * @author Armindo Cachada&lt;br /&gt; *&lt;br /&gt; */&lt;br /&gt;@Stateless(name = &amp;quot;remoteService&amp;quot;)&lt;br /&gt;@Local(RemoteService.class)&lt;br /&gt;public class RemoteServiceImpl implements RemoteService {&lt;br /&gt;&lt;br /&gt; &lt;br /&gt; /**&lt;br /&gt;  * I am not doing anything useful except to just show that I can be invoked remotely&lt;br /&gt;  * from Adobe Flex using RemoteObject.&lt;br /&gt;  * &lt;br /&gt;  */&lt;br /&gt; public List&amp;lt;String&amp;gt; callMe() {&lt;br /&gt;  System.out.println(&amp;quot;I was invoked!&amp;quot;);&lt;br /&gt;  List&amp;lt;String&amp;gt; result = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;  result.add(&amp;quot;Michael Jackson&amp;quot;);&lt;br /&gt;  result.add(&amp;quot;Beatles&amp;quot;);&lt;br /&gt;  result.add(&amp;quot;Tina Turner&amp;quot;);&lt;br /&gt;  return result;&lt;br /&gt; &lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Step 5&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Add the new destination to flex/remoting-config.xml:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;destination id=&amp;quot;remoteService&amp;quot; &amp;gt;&lt;br /&gt;        &amp;lt;properties&amp;gt;&lt;br /&gt;              &amp;lt;factory&amp;gt;ejb3&amp;lt;/factory&amp;gt;&lt;br /&gt;              &amp;lt;source&amp;gt;example7/remoteService/local&amp;lt;/source&amp;gt;&lt;br /&gt;              &amp;lt;scope&amp;gt;application&amp;lt;/scope&amp;gt;&lt;br /&gt;         &amp;lt;/properties&amp;gt;&lt;br /&gt;   &amp;lt;/destination&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;There are two differences in the destination declaration:&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;The &lt;b&gt;factory&lt;/b&gt; node indicates that we want to use the EJB3Factory declared in services-config.xml&lt;/li&gt;&lt;br /&gt;&lt;li&gt;The &lt;b&gt;source&lt;/b&gt; instead of referencing a class name is changed to reference an EJB3 bean via JNDI.&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Step 6&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;We are going to use the same mxml code as the one for Part I of this tutorial but we need to change the flex compiler settings:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;-services &amp;quot;/usr/java/eclipse/workspace/example7/resources/flex/services-config.xml&amp;quot; -context-root &amp;quot;/example7&amp;quot; -locale en_US&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;After you have followed all these steps you should be good to go!&lt;br /&gt;&lt;br /&gt;&lt;a href="http://files.spltech.co.uk.s3.amazonaws.com/example7.zip"&gt;Download source code for JBOSS+Adobe Flex+BlazeDS project Part II&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;To save bandwidth I didn't include all the jars needed:&lt;br /&gt;&lt;br /&gt;flex-ejb-factory.jar&lt;br /&gt;flex-messaging-common.jar&lt;br /&gt;flex-messaging-core.jar&lt;br /&gt;flex-messaging-opt.jar&lt;br /&gt;flex-messaging-proxy.jar&lt;br /&gt;flex-messaging-remoting.jar&lt;br /&gt;backport-util-concurrent.jar&lt;br /&gt; &lt;br /&gt;Copy these jars to the &lt;b&gt;jbosslib&lt;/b&gt; directory inside the project. Don't forget to change jboss-service.xml to reference this directory. Otherwise nothing will work.&lt;br /&gt;&lt;br /&gt;Good luck!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5712470018526280356-9034462210167139568?l=simplyolaf.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://simplyolaf.blogspot.com/feeds/9034462210167139568/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5712470018526280356&amp;postID=9034462210167139568' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5712470018526280356/posts/default/9034462210167139568'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5712470018526280356/posts/default/9034462210167139568'/><link rel='alternate' type='text/html' href='http://simplyolaf.blogspot.com/2009/07/integrate-adobe-flex-and-jboss-using_24.html' title='Integrate Adobe Flex and JBOSS using BlazeDS - Part II'/><author><name>Armindo Cachada</name><uri>http://www.blogger.com/profile/17668696197506133653</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5712470018526280356.post-9131857893823056086</id><published>2009-07-19T09:41:00.001-07:00</published><updated>2009-07-24T05:27:18.338-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='struts 2'/><category scheme='http://www.blogger.com/atom/ns#' term='adobe flex'/><category scheme='http://www.blogger.com/atom/ns#' term='jboss'/><category scheme='http://www.blogger.com/atom/ns#' term='BlazeDS'/><category scheme='http://www.blogger.com/atom/ns#' term='Adobe LiveCycle DS'/><title type='text'>Integrate Adobe Flex and JBOSS using BlazeDS - Part I</title><content type='html'>In this tutorial I will give you step by step instructions on how to integrate &lt;b&gt;Adobe Flex&lt;/b&gt; and &lt;b&gt;JBOSS&lt;/b&gt; using &lt;b&gt;BlazeDS&lt;/b&gt;. &lt;br /&gt;Although in this tutorial I am addressing BlazeDS, the steps in this tutorial should also apply to Adobe Flex LiveCycle Data Services. The only difference are the jars that you copy to your WEB-INF/lib directory. For those who want to integrate BlazeDS with Struts 2, the instructions in this tutorial should also be helpful. &lt;br /&gt;&lt;br /&gt;In the Java Backend:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Step 1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Download blazeds.war from http://opensource.adobe.com/wiki/display/blazeds/Downloads&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Step 2&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Unzip blazeds.war. Copy the files in WEB-INF/lib and WEB-INF/flex to your web project under the same path in your web app.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Step 3&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Edit web.xml and add the following lines:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;    &amp;lt;!-- Http Flex Session attribute and binding listener support --&amp;gt;&lt;br /&gt;    &amp;lt;listener&amp;gt;&lt;br /&gt;        &amp;lt;listener-class&amp;gt;flex.messaging.HttpFlexSession&amp;lt;/listener-class&amp;gt;&lt;br /&gt;    &amp;lt;/listener&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;!-- MessageBroker Servlet --&amp;gt;&lt;br /&gt;    &amp;lt;servlet&amp;gt;&lt;br /&gt;        &amp;lt;servlet-name&amp;gt;MessageBrokerServlet&amp;lt;/servlet-name&amp;gt;&lt;br /&gt;        &amp;lt;display-name&amp;gt;MessageBrokerServlet&amp;lt;/display-name&amp;gt;&lt;br /&gt;        &amp;lt;servlet-class&amp;gt;flex.messaging.MessageBrokerServlet&amp;lt;/servlet-class&amp;gt;&lt;br /&gt;        &amp;lt;init-param&amp;gt;&lt;br /&gt;            &amp;lt;param-name&amp;gt;services.configuration.file&amp;lt;/param-name&amp;gt;&lt;br /&gt;            &amp;lt;param-value&amp;gt;/WEB-INF/flex/services-config.xml&amp;lt;/param-value&amp;gt;&lt;br /&gt;       &amp;lt;/init-param&amp;gt;&lt;br /&gt;        &amp;lt;load-on-startup&amp;gt;1&amp;lt;/load-on-startup&amp;gt;&lt;br /&gt;    &amp;lt;/servlet&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;servlet-mapping&amp;gt;&lt;br /&gt;        &amp;lt;servlet-name&amp;gt;MessageBrokerServlet&amp;lt;/servlet-name&amp;gt;&lt;br /&gt;        &amp;lt;url-pattern&amp;gt;/messagebroker/*&amp;lt;/url-pattern&amp;gt;&lt;br /&gt;    &amp;lt;/servlet-mapping&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Step 4&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Create a simple java class with a simple method that we will invoke from Adobe Flex:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;package uk.co.spltech.remote;&lt;br /&gt;&lt;br /&gt;import java.util.ArrayList;&lt;br /&gt;import java.util.List;&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt; * This remote service is called using BlazeDS/LiveCycle DS from Flex&lt;br /&gt; * &lt;br /&gt; * @author Armindo Cachada&lt;br /&gt; *&lt;br /&gt; */&lt;br /&gt;public class RemoteService { &lt;br /&gt; /**&lt;br /&gt;  * I am not doing anything useful except to just show that I can be invoked remotely&lt;br /&gt;  * from Adobe Flex using RemoteObject.&lt;br /&gt;  * &lt;br /&gt;  */&lt;br /&gt; public List&amp;lt;String&amp;gt; callMe() {&lt;br /&gt;  System.out.println(&amp;quot;I am being invoked!&amp;quot;);&lt;br /&gt;  List&amp;lt;String&amp;gt; result = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;  result.add(&amp;quot;Michael Jackson&amp;quot;);&lt;br /&gt;  result.add(&amp;quot;Beatles&amp;quot;);&lt;br /&gt;  result.add(&amp;quot;Tina Turner&amp;quot;);&lt;br /&gt;  return result;&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Step 5&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Create a new destination in remoting-config.xml:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;destination id=&amp;quot;remoteService&amp;quot; &amp;gt;&lt;br /&gt;   &amp;lt;properties&amp;gt;&lt;br /&gt;        &amp;lt;source&amp;gt;uk.co.spltech.remote.RemoteService&amp;lt;/source&amp;gt;&lt;br /&gt;        &amp;lt;scope&amp;gt;application&amp;lt;/scope&amp;gt;&lt;br /&gt;   &amp;lt;/properties&amp;gt;&lt;br /&gt;&amp;lt;/destination&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The &lt;b&gt;source&lt;/b&gt; of the destination can be a fully qualified class name, a jndi reference or a spring bean. We will discuss that in a later post. For this example we just specify a class name.&lt;br /&gt;&lt;br /&gt;The &lt;b&gt;scope&lt;/b&gt; of the destination can be one of:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;application&lt;/b&gt; - there is only one instance of the class for the entire application(i.e. global in atg, singleton in spring)&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;b&gt;session&lt;/b&gt; - there is one instance per user session&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;b&gt;request&lt;/b&gt; - for each http request a new instance of the class is created&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;In Adobe Flex:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Step 1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Create a new project in Adobe Flex. Please make sure that the Application Server type is set to &lt;span style="font-weight:bold;"&gt;none&lt;/span&gt;. &lt;br /&gt;Why? Fair question to ask since most instructions say to do exactly the opposite. I found those instructions not really helpful in the case of JBOSS since they assume I can provide the directory containing the application after it is deployed to JBOSS. That works quite well for tomcat because it simply extracts the war file under webapps. The path is always the same. In the case of JBOSS the path to the application changes after each deployment... &lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Step 2&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The only reason Adobe Flex asks you for the path to the root folder of your web application is so that it can provide two arguments to the flex compiler:&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;services&lt;/b&gt; - The path to the Adobe flex data services configuration file&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;b&gt;context-root&lt;/b&gt; - The context root of your web application&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;After you create your web application add the following arguments to the flex compiler:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;-services "/usr/java/eclipse/workspace/example6/resources/flex/services-config.xml" -context-root "/example6"&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Step 3&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Let's create a very simple flex application that invokes the &lt;b&gt;callMe()&lt;/b&gt; method in &lt;b&gt;uk.co.spltech.remote.RemoteService&lt;/b&gt;. This method returns an &lt;b&gt;ArrayList&lt;/b&gt; with a list of items:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;&amp;lt;mx:Application xmlns:mx=&amp;quot;http://www.adobe.com/2006/mxml&amp;quot; layout=&amp;quot;vertical&amp;quot; &amp;gt;&lt;br /&gt;&amp;lt;mx:Script&amp;gt;&lt;br /&gt; &amp;lt;![CDATA[&lt;br /&gt;  import mx.collections.ArrayCollection;&lt;br /&gt;  import mx.controls.Alert;&lt;br /&gt;  import mx.rpc.events.ResultEvent;&lt;br /&gt;  import flash.utils.getQualifiedClassName;&lt;br /&gt;  &lt;br /&gt;  &lt;br /&gt;  /**&lt;br /&gt;   * Populates the data list using the results returned by callMe()&lt;br /&gt;   */&lt;br /&gt;  private function populateList(event:ResultEvent):void {&lt;br /&gt;   var result:ArrayCollection= ArrayCollection(event.result);&lt;br /&gt;   singerList.dataProvider= result;&lt;br /&gt;  }&lt;br /&gt; ]]&amp;gt;&lt;br /&gt;&amp;lt;/mx:Script&amp;gt;&lt;br /&gt; &amp;lt;mx:RemoteObject id=&amp;quot;myService&amp;quot; destination=&amp;quot;remoteService&amp;quot; result=&amp;quot;populateList(event)&amp;quot;/&amp;gt;&lt;br /&gt; &amp;lt;mx:List id=&amp;quot;singerList&amp;quot; &amp;gt;&lt;br /&gt;  &lt;br /&gt; &amp;lt;/mx:List&amp;gt;&lt;br /&gt; &amp;lt;mx:Button click=&amp;quot;myService.callMe();&amp;quot; label=&amp;quot;Call Remote Function&amp;quot;  /&amp;gt;&lt;br /&gt;&amp;lt;/mx:Application&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Step 4&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Compile the flex app and copy all the generated swf/html/js to your jboss web app.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Step 5&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Deploy the war file to JBOSS and test it under http://localhost:8080/example6&lt;br /&gt;&lt;br /&gt;If you click in the "Call Remote Function" button you should see a list of results returned by the method &lt;b&gt;callMe()&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://files.spltech.co.uk.s3.amazonaws.com/example6.zip"&gt;Download source code for JBOSS+Adobe Flex+BlazeDS project&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Note that, in order to make the zip smaller, I didn't include the BlazeDS jar files. You need to manually copy them to the lib directory before generating the war file.&lt;br /&gt;&lt;br /&gt;Click here to read &lt;a href="http://simplyolaf.blogspot.com/2009/07/integrate-adobe-flex-and-jboss-using_24.html"&gt;Part II&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5712470018526280356-9131857893823056086?l=simplyolaf.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://simplyolaf.blogspot.com/feeds/9131857893823056086/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5712470018526280356&amp;postID=9131857893823056086' title='20 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5712470018526280356/posts/default/9131857893823056086'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5712470018526280356/posts/default/9131857893823056086'/><link rel='alternate' type='text/html' href='http://simplyolaf.blogspot.com/2009/07/integrate-adobe-flex-and-jboss-using.html' title='Integrate Adobe Flex and JBOSS using BlazeDS - Part I'/><author><name>Armindo Cachada</name><uri>http://www.blogger.com/profile/17668696197506133653</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>20</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5712470018526280356.post-5427277968429342316</id><published>2009-07-13T06:48:00.000-07:00</published><updated>2009-07-13T07:22:17.879-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='constraint'/><category scheme='http://www.blogger.com/atom/ns#' term='verticalCenter'/><category scheme='http://www.blogger.com/atom/ns#' term='flex 3'/><category scheme='http://www.blogger.com/atom/ns#' term='adobe flex'/><category scheme='http://www.blogger.com/atom/ns#' term='absolute'/><category scheme='http://www.blogger.com/atom/ns#' term='horizontalCenter'/><title type='text'>Adobe Flex: How to use verticalCenter and horizontalCenter in a container with absolute layout</title><content type='html'>In this tutorial I will explain how you can use the &lt;b&gt;verticalCenter&lt;/b&gt; and &lt;b&gt;horizontalCenter&lt;/b&gt; constraints in a container with absolute layout.&lt;br /&gt;&lt;br /&gt;At this stage you probably already figured out how to use the &lt;b&gt;left&lt;/b&gt;, &lt;b&gt;right&lt;/b&gt;, &lt;b&gt;top&lt;/b&gt;, &lt;b&gt;bottom&lt;/b&gt; constraints. But what about &lt;b&gt;horizontalCenter&lt;/b&gt; and &lt;b&gt;verticalCenter&lt;/b&gt;?&lt;br /&gt;&lt;br /&gt;&lt;b&gt;horizontalCenter&lt;/b&gt; is the distance from the center of the container in the horizontal where you want your component to appear. If you give it a positive value, the component will show up in the right half of the container. If you give it a negative value the component will appear in the left half.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;mx:Canvas width=&amp;quot;500&amp;quot; height=&amp;quot;500&amp;quot;&amp;gt;&lt;br /&gt;   &amp;lt;mx:Button horizontalCenter=&amp;quot;200&amp;quot; label=&amp;quot;Right half of the container&amp;quot;/&amp;gt;&lt;br /&gt;   &amp;lt;mx:Button horizontalCenter=&amp;quot;-200&amp;quot; label=&amp;quot;Left half of the container&amp;quot;/&amp;gt;&lt;br /&gt;&amp;lt;/mx:Canvas&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;If you try to combine &lt;b&gt;horizontalCenter&lt;/b&gt; with &lt;b&gt;left&lt;/b&gt; or &lt;b&gt;right&lt;/b&gt; constraints, they will always be ignored as the &lt;b&gt;horizontalCenter&lt;/b&gt; constraint always takes precedence.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;mx:Canvas width=&amp;quot;500&amp;quot; height=&amp;quot;500&amp;quot;&amp;gt;&lt;br /&gt;   &amp;lt;mx:Button horizontalCenter=&amp;quot;200&amp;quot; left=&amp;quot;400&amp;quot; label=&amp;quot;Button 1&amp;quot;/&amp;gt;&lt;br /&gt;   &amp;lt;mx:Button horizontalCenter=&amp;quot;200&amp;quot; right=&amp;quot;200&amp;quot; label=&amp;quot;Button 2&amp;quot;/&amp;gt;&lt;br /&gt;&amp;lt;/mx:Canvas&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;In the example above the two buttons will overlap because the value of the &lt;b&gt;left&lt;/b&gt; and &lt;b&gt;right&lt;/b&gt; coordinate is ignored.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;verticalCenter&lt;/b&gt; is the distance from the center of the container in the vertical where you want your component to appear. If you give it a positive value, the component will show up in the bottom half of the container. If you give it a negative value the component will appear in the top half.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;mx:Canvas width=&amp;quot;500&amp;quot; height=&amp;quot;500&amp;quot;&amp;gt;&lt;br /&gt;   &amp;lt;mx:Button verticalCenter=&amp;quot;200&amp;quot; label=&amp;quot;Bottom half of the container&amp;quot;/&amp;gt;&lt;br /&gt;   &amp;lt;mx:Button verticalCenter=&amp;quot;-200&amp;quot; label=&amp;quot;Top half of the container&amp;quot;/&amp;gt;&lt;br /&gt;&amp;lt;/mx:Canvas&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;If you try to combine &lt;b&gt;verticalCenter&lt;/b&gt; with &lt;b&gt;top&lt;/b&gt; or &lt;b&gt;bottom&lt;/b&gt; constraints, they will always be ignored as the &lt;b&gt;verticalCenter&lt;/b&gt; constraint always takes precedence.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;mx:Canvas width=&amp;quot;500&amp;quot; height=&amp;quot;500&amp;quot;&amp;gt;&lt;br /&gt;   &amp;lt;mx:Button verticalCenter=&amp;quot;200&amp;quot; top=&amp;quot;400&amp;quot; label=&amp;quot;Button 1&amp;quot;/&amp;gt;&lt;br /&gt;   &amp;lt;mx:Button verticalCenter=&amp;quot;200&amp;quot; bottom=&amp;quot;200&amp;quot; label=&amp;quot;Button 2&amp;quot;/&amp;gt;&lt;br /&gt;&amp;lt;/mx:Canvas&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;In the example above the two buttons will overlap because the value of the &lt;b&gt;top&lt;/b&gt; and &lt;b&gt;bottom&lt;/b&gt; constraint is ignored.&lt;br /&gt;&lt;br /&gt;The code below shows possible combinations of &lt;b&gt;horizontalCenter&lt;/b&gt; and &lt;b&gt;verticalCenter&lt;/b&gt; that you can use to layout your components:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;&amp;lt;mx:Application xmlns:mx=&amp;quot;http://www.adobe.com/2006/mxml&amp;quot; layout=&amp;quot;absolute&amp;quot; height=&amp;quot;520&amp;quot; width=&amp;quot;520&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;mx:Button label=&amp;quot;Left Center&amp;quot; horizontalCenter=&amp;quot;-200&amp;quot; verticalCenter=&amp;quot;0&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;/mx:Button&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;mx:Button label=&amp;quot;Center&amp;quot; horizontalCenter=&amp;quot;0&amp;quot; verticalCenter=&amp;quot;0&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;/mx:Button&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;mx:Button label=&amp;quot;Right Center&amp;quot; horizontalCenter=&amp;quot;200&amp;quot; verticalCenter=&amp;quot;0&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;/mx:Button&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;mx:Button label=&amp;quot;Top Left&amp;quot; horizontalCenter=&amp;quot;-200&amp;quot; verticalCenter=&amp;quot;-200&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;/mx:Button&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;mx:Button label=&amp;quot;Top Center&amp;quot; horizontalCenter=&amp;quot;0&amp;quot; verticalCenter=&amp;quot;-200&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;/mx:Button&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;mx:Button label=&amp;quot;Top Right&amp;quot; horizontalCenter=&amp;quot;200&amp;quot; verticalCenter=&amp;quot;-200&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;/mx:Button&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;mx:Button label=&amp;quot;Bottom Left&amp;quot; horizontalCenter=&amp;quot;-200&amp;quot; verticalCenter=&amp;quot;200&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;/mx:Button&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;mx:Button label=&amp;quot;Bottom Center&amp;quot; horizontalCenter=&amp;quot;0&amp;quot; verticalCenter=&amp;quot;200&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;/mx:Button&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;mx:Button label=&amp;quot;Bottom Right&amp;quot; horizontalCenter=&amp;quot;200&amp;quot; verticalCenter=&amp;quot;200&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;/mx:Button&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;mx:Button label=&amp;quot;Ignored right constraint&amp;quot; right=&amp;quot;10&amp;quot; horizontalCenter=&amp;quot;-200&amp;quot; verticalCenter=&amp;quot;50&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;/mx:Button&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;mx:Button label=&amp;quot;Not ignored right constraint&amp;quot; right=&amp;quot;10&amp;quot; verticalCenter=&amp;quot;50&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;/mx:Button&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;mx:Button label=&amp;quot;Ignored top constraint&amp;quot; top=&amp;quot;10&amp;quot; horizontalCenter=&amp;quot;-200&amp;quot; verticalCenter=&amp;quot;-50&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;/mx:Button&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;mx:Button label=&amp;quot;Not Ignored top constraint&amp;quot; top=&amp;quot;10&amp;quot; horizontalCenter=&amp;quot;-200&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;/mx:Button&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/mx:Application&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;a href="http://files.spltech.co.uk.s3.amazonaws.com/FlexExamples/FlexExample13.html"&gt;Click here to try the example above&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5712470018526280356-5427277968429342316?l=simplyolaf.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://simplyolaf.blogspot.com/feeds/5427277968429342316/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5712470018526280356&amp;postID=5427277968429342316' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5712470018526280356/posts/default/5427277968429342316'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5712470018526280356/posts/default/5427277968429342316'/><link rel='alternate' type='text/html' href='http://simplyolaf.blogspot.com/2009/07/adobe-flex-how-to-use-verticalcenter.html' title='Adobe Flex: How to use verticalCenter and horizontalCenter in a container with absolute layout'/><author><name>Armindo Cachada</name><uri>http://www.blogger.com/profile/17668696197506133653</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5712470018526280356.post-3705305559900043450</id><published>2009-07-13T05:34:00.000-07:00</published><updated>2009-07-13T06:23:22.141-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tween'/><category scheme='http://www.blogger.com/atom/ns#' term='autoLayout'/><category scheme='http://www.blogger.com/atom/ns#' term='flex 3'/><category scheme='http://www.blogger.com/atom/ns#' term='Resize'/><category scheme='http://www.blogger.com/atom/ns#' term='Sequence'/><category scheme='http://www.blogger.com/atom/ns#' term='adobe flex'/><category scheme='http://www.blogger.com/atom/ns#' term='Parallel'/><category scheme='http://www.blogger.com/atom/ns#' term='Move'/><title type='text'>Adobe Flex: How to apply effects to components inside containers with automated layout</title><content type='html'>In this tutorial I will explain how to apply a tween effect to a component inside a container with automated layout. &lt;br /&gt;&lt;br /&gt;Containers like VBox, HBox, Panel(except for layout=absolute), Grid, ... automatically position items for you.&lt;br /&gt;&lt;br /&gt;Lets try to apply a &lt;b&gt;Move&lt;/b&gt; effect to a &lt;b&gt;Button&lt;/b&gt; inside a VBox:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;&amp;lt;mx:Application xmlns:mx=&amp;quot;http://www.adobe.com/2006/mxml&amp;quot; layout=&amp;quot;absolute&amp;quot; height=&amp;quot;500&amp;quot; width=&amp;quot;500&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;mx:Script&amp;gt;&lt;br /&gt; &amp;lt;![CDATA[&lt;br /&gt;     /**&lt;br /&gt;     * This method runs an effect on a button to move it&lt;br /&gt;     * to the right side.&lt;br /&gt;     * &lt;br /&gt;     */&lt;br /&gt;  public function moveButton(button:Button):void {&lt;br /&gt;   this.moveEffect.target= button;&lt;br /&gt;   this.moveEffect.play();&lt;br /&gt;  }&lt;br /&gt; ]]&amp;gt;&lt;br /&gt;&amp;lt;/mx:Script&amp;gt;&lt;br /&gt; &amp;lt;mx:VBox id=&amp;quot;box&amp;quot; clipContent=&amp;quot;false&amp;quot; backgroundAlpha=&amp;quot;1&amp;quot; backgroundColor=&amp;quot;red&amp;quot;&amp;gt;&lt;br /&gt;  &amp;lt;mx:Button id=&amp;quot;button1&amp;quot; label=&amp;quot;Button 1&amp;quot; click=&amp;quot;moveButton(button1)&amp;quot;/&amp;gt;&lt;br /&gt;  &amp;lt;mx:Button id=&amp;quot;button2&amp;quot; label=&amp;quot;Button 2&amp;quot; click=&amp;quot;moveButton(button2)&amp;quot;/&amp;gt;&lt;br /&gt;  &amp;lt;mx:Button id=&amp;quot;button3&amp;quot; label=&amp;quot;Button 3&amp;quot; click=&amp;quot;moveButton(button3)&amp;quot;/&amp;gt;&lt;br /&gt; &amp;lt;/mx:VBox&amp;gt;&lt;br /&gt;  &amp;lt;mx:Sequence id=&amp;quot;moveEffect&amp;quot;&amp;gt;&lt;br /&gt;   &amp;lt;mx:Move duration=&amp;quot;5000&amp;quot; xBy=&amp;quot;300&amp;quot; yBy=&amp;quot;300&amp;quot;/&amp;gt;&lt;br /&gt;   &amp;lt;mx:Move duration=&amp;quot;5000&amp;quot; xBy=&amp;quot;-300&amp;quot; yBy=&amp;quot;-300&amp;quot;/&amp;gt;&lt;br /&gt;  &amp;lt;/mx:Sequence&amp;gt;&lt;br /&gt;&amp;lt;/mx:Application&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;a href="http://files.spltech.co.uk.s3.amazonaws.com/FlexExamples/FlexExample10.html"&gt;Click here to run our example&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;In the example above we set &lt;b&gt;clipContent&lt;/b&gt; to &lt;b&gt;false&lt;/b&gt; to enable the button to be visible outside the &lt;b&gt;VBox&lt;/b&gt; container after it moves.&lt;br /&gt;&lt;br /&gt;To start the move effect you need to click in one of the buttons. You will then see the button you clicked move to the right bottom corner and then return to its original position. This example is not completely correct, but it works for this simple example. &lt;br /&gt;&lt;br /&gt;To understand why it might not work lets add a &lt;b&gt;Resize&lt;/b&gt; effect to the &lt;b&gt;VBox&lt;/b&gt; to go along with the button &lt;b&gt;Move&lt;/b&gt; effect:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;mx:Parallel id=&amp;quot;moveEffect&amp;quot;&amp;gt;&lt;br /&gt; &amp;lt;mx:Sequence&amp;gt;&lt;br /&gt;  &amp;lt;mx:Move duration=&amp;quot;5000&amp;quot; xBy=&amp;quot;300&amp;quot; yBy=&amp;quot;300&amp;quot;/&amp;gt;&lt;br /&gt;  &amp;lt;mx:Move duration=&amp;quot;5000&amp;quot; xBy=&amp;quot;-300&amp;quot; yBy=&amp;quot;-300&amp;quot;/&amp;gt;&lt;br /&gt; &amp;lt;/mx:Sequence&amp;gt;&lt;br /&gt; &amp;lt;mx:Sequence&amp;gt;&lt;br /&gt;  &amp;lt;mx:Resize target=&amp;quot;{box}&amp;quot; duration=&amp;quot;5000&amp;quot; heightBy=&amp;quot;300&amp;quot; widthBy=&amp;quot;300&amp;quot;/&amp;gt;&lt;br /&gt;  &amp;lt;mx:Resize target=&amp;quot;{box}&amp;quot; duration=&amp;quot;5000&amp;quot; heightBy=&amp;quot;-300&amp;quot; widthBy=&amp;quot;-300&amp;quot;/&amp;gt;&lt;br /&gt; &amp;lt;/mx:Sequence&amp;gt;&lt;br /&gt;&amp;lt;/mx:Parallel&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;At the same time that we move the button to the right bottom corner and then back to its origin, we also increase the size of the &lt;b&gt;VBox&lt;/b&gt; and then decrease it back to its original size. Note here the use of &lt;b&gt;Sequence&lt;/b&gt; and &lt;b&gt;Parallel&lt;/b&gt;. These two effects allow us to run a list of child effects in sequence or in parallel as you probably guessed.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://files.spltech.co.uk.s3.amazonaws.com/FlexExamples/FlexExample11.html"&gt;Click here to try the example above&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Did you notice anything wrong with the example above? Now the Move effect doens't work anymore. This is because every time we change the size of the VBox, Flex needs to re-position the items inside the &lt;b&gt;VBox&lt;/b&gt;. Because of this the &lt;b&gt;x&lt;/b&gt; and &lt;b&gt;y&lt;/b&gt; values of the button are re-calculated thus ruining our &lt;b&gt;Move&lt;/b&gt; effect.&lt;br /&gt;The solution to this problem is to set &lt;b&gt;autoLayout&lt;/b&gt;="false" immediately before the start of the effect:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;mx:VBox id=&amp;quot;box&amp;quot; clipContent=&amp;quot;false&amp;quot; backgroundAlpha=&amp;quot;1&amp;quot; backgroundColor=&amp;quot;red&amp;quot;&amp;gt;&lt;br /&gt; &amp;lt;mx:Button id=&amp;quot;button1&amp;quot; label=&amp;quot;Button 1&amp;quot; click=&amp;quot;moveButton(button1)&amp;quot;/&amp;gt;&lt;br /&gt; &amp;lt;mx:Button id=&amp;quot;button2&amp;quot; label=&amp;quot;Button 2&amp;quot; click=&amp;quot;moveButton(button2)&amp;quot;/&amp;gt;&lt;br /&gt; &amp;lt;mx:Button id=&amp;quot;button3&amp;quot; label=&amp;quot;Button 3&amp;quot; click=&amp;quot;moveButton(button3)&amp;quot;/&amp;gt;&lt;br /&gt;&amp;lt;/mx:VBox&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;a href="http://files.spltech.co.uk.s3.amazonaws.com/FlexExamples/FlexExample12.html"&gt;Click here to see the full working solution in action&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5712470018526280356-3705305559900043450?l=simplyolaf.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://simplyolaf.blogspot.com/feeds/3705305559900043450/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5712470018526280356&amp;postID=3705305559900043450' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5712470018526280356/posts/default/3705305559900043450'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5712470018526280356/posts/default/3705305559900043450'/><link rel='alternate' type='text/html' href='http://simplyolaf.blogspot.com/2009/07/adobe-flex-how-to-apply-effects-to.html' title='Adobe Flex: How to apply effects to components inside containers with automated layout'/><author><name>Armindo Cachada</name><uri>http://www.blogger.com/profile/17668696197506133653</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5712470018526280356.post-8163666833595830135</id><published>2009-07-09T07:06:00.000-07:00</published><updated>2009-07-11T03:13:37.522-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='netconnection'/><category scheme='http://www.blogger.com/atom/ns#' term='Microphone'/><category scheme='http://www.blogger.com/atom/ns#' term='red5'/><category scheme='http://www.blogger.com/atom/ns#' term='adobe flex'/><category scheme='http://www.blogger.com/atom/ns#' term='Camera'/><category scheme='http://www.blogger.com/atom/ns#' term='netstream'/><title type='text'>Adobe Flex: Recording a video stream with Red5</title><content type='html'>In this post I will show how simple it is to create an Adobe Flex client to record a video stream to a server running Adobe Media Server or Red5. Not only that I will also provide you with the code that you need to play the stream after you record it&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Step 1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Connect to the Adobe Media Server or Red5 using NetConnection.connect()&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;private function connect():void {&lt;br /&gt;   nc = new NetConnection();&lt;br /&gt;   nc.addEventListener(NetStatusEvent.NET_STATUS,netStatusHandler);&lt;br /&gt;   nc.connect("rtmp://localhost/vmspeak");&lt;br /&gt;  ...   &lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;In the case above we added an event listener to the &lt;b&gt;NetConnection&lt;/b&gt;. Whether we are able to connect or not the method &lt;b&gt;netStatusHandler&lt;/b&gt; is called. This method checks if the connection attempt is succcessful and enables/disables the record button based on that.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;/**&lt;br /&gt;  * When the connection is successful we can&lt;br /&gt;  * enable the record button.&lt;br /&gt;  * &lt;br /&gt; */&lt;br /&gt;private function netStatusHandler(event:NetStatusEvent):void&lt;br /&gt;{&lt;br /&gt;        trace(event.info.code);&lt;br /&gt; if(event.info.code == "NetConnection.Connect.Success")&lt;br /&gt; {&lt;br /&gt;  this.recordButton.enabled=true; &lt;br /&gt; }&lt;br /&gt; else {&lt;br /&gt;  mx.controls.Alert.show("Failed to connect!");&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Step 2&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Request access to the web camera and microphone:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;   mic =Microphone.getMicrophone();&lt;br /&gt;   mic.setUseEchoSuppression(true);&lt;br /&gt;   mic.setSilenceLevel(0);&lt;br /&gt;   cam = Camera.getCamera();&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;When executing this code Flash will show you a popup window requesting permission to access the video and microphone.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Step 3&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;To start recording you need to create a NetStream object using as argument the &lt;b&gt;NetConnection&lt;/b&gt; you created in the step before.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;  var ns:NetStream = new NetStream(nc);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Step 4&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Attach the video and the camera to the &lt;b&gt;NetStream&lt;/b&gt; and start recording.&lt;br /&gt;You can also attach the camera to a &lt;b&gt;Video&lt;/b&gt; object in order to see what the&lt;br /&gt;camera is capturing during the recording. To record a stream  one calls ns.publish("stream-name","record"). It is also possible to create a live stream, and in that case one would call ns.publish(stream-name, "live");&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;    ns.publish("test","record");&lt;br /&gt;    ns.attachAudio(mic);&lt;br /&gt;    ns.attachCamera(cam);&lt;br /&gt;    this.video.attachCamera(cam);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Step 5&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;To stop the recording just call:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;  ns.close();&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Step 6&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;To play what you have just recorded:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;private function playRecording():void {&lt;br /&gt; this.ns.play("test");&lt;br /&gt;        this.video.attachNetStream(ns);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;It looks really easy doesn't it? The hardest part is to configure the media server in the backend. &lt;br /&gt;&lt;br /&gt;&lt;a href="http://files.spltech.co.uk.s3.amazonaws.com/FlexExamples/FlexExample9.html"&gt;Source for Video recorder with Red5 example&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;P.S. Before you can try the example you need to change the rtmp url to point to your media server.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5712470018526280356-8163666833595830135?l=simplyolaf.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://simplyolaf.blogspot.com/feeds/8163666833595830135/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5712470018526280356&amp;postID=8163666833595830135' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5712470018526280356/posts/default/8163666833595830135'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5712470018526280356/posts/default/8163666833595830135'/><link rel='alternate' type='text/html' href='http://simplyolaf.blogspot.com/2009/07/adobe-flex-recording-video-stream-with.html' title='Adobe Flex: Recording a video stream with Red5'/><author><name>Armindo Cachada</name><uri>http://www.blogger.com/profile/17668696197506133653</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5712470018526280356.post-3743894862879223491</id><published>2009-07-09T06:20:00.000-07:00</published><updated>2009-07-09T06:55:24.618-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='item editor'/><category scheme='http://www.blogger.com/atom/ns#' term='DataGrid'/><category scheme='http://www.blogger.com/atom/ns#' term='adobe flex'/><category scheme='http://www.blogger.com/atom/ns#' term='SortField'/><category scheme='http://www.blogger.com/atom/ns#' term='inline item editor'/><category scheme='http://www.blogger.com/atom/ns#' term='flex3'/><title type='text'>Adobe Flex: Add a combo box to a DataGrid that re-orders its elements</title><content type='html'>Here I am posting a solution for a problem I had to solve for one of my projects. I needed to add a combo box to one of the columns in a DataGrid. Not only that, based on the value of the combo box, the elements in the DataGrid should re-order.&lt;br /&gt;To add the combo box to one of the columns we need to set that column as &lt;b&gt;editable&lt;/b&gt; and we need to add an item editor(in this case an inline item editor):&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;mx:itemEditor&amp;gt;&lt;br /&gt;    &amp;lt;mx:Component&amp;gt;&lt;br /&gt; &amp;lt;mx:ComboBox  editable=&amp;quot;false&amp;quot; dataProvider=&amp;quot;{outerDocument.sequenceNumbers}&amp;quot;&amp;gt;&lt;br /&gt;                        &lt;br /&gt; &amp;lt;/mx:ComboBox&amp;gt;&lt;br /&gt;    &amp;lt;/mx:Component&amp;gt;&lt;br /&gt;&amp;lt;/mx:itemEditor&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;To sort the data grid based on the column you need to apply a &lt;b&gt;SortField&lt;/b&gt; to the &lt;br /&gt;&lt;b&gt;ArrayCollection&lt;/b&gt; that holds the elements of the &lt;b&gt;DataGrid&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;   /**&lt;br /&gt;    * Sort list of questions by sequence&lt;br /&gt;    */&lt;br /&gt;   private function sortQuestions():void {&lt;br /&gt;    var sort:Sort= new Sort();&lt;br /&gt;       var sequence:SortField= new SortField("Sequence",false,false);&lt;br /&gt;       sort.fields=[sequence];&lt;br /&gt;       this.questions.sort=sort;&lt;br /&gt;       this.questions.refresh();&lt;br /&gt;   &lt;br /&gt;   }&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The full code:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;&amp;lt;mx:Application xmlns:mx=&amp;quot;http://www.adobe.com/2006/mxml&amp;quot; layout=&amp;quot;absolute&amp;quot; creationComplete=&amp;quot;creationComplete()&amp;quot;&amp;gt;&lt;br /&gt; &amp;lt;mx:Script&amp;gt;&lt;br /&gt;  &amp;lt;![CDATA[&lt;br /&gt;   import mx.collections.Sort;&lt;br /&gt;   import mx.collections.SortField;&lt;br /&gt;   [Bindable]&lt;br /&gt;   public var sequenceNumbers:ArrayCollection;&lt;br /&gt;   &lt;br /&gt;   /**&lt;br /&gt;    * Prepare the data&lt;br /&gt;    */&lt;br /&gt;   private function creationComplete():void {&lt;br /&gt;    this.initSequenceNumbers();&lt;br /&gt;    this.sortQuestions();&lt;br /&gt;   }&lt;br /&gt;   &lt;br /&gt;   /**&lt;br /&gt;    * Sort list of questions by sequence&lt;br /&gt;    */&lt;br /&gt;   private function sortQuestions():void {&lt;br /&gt;    var sort:Sort= new Sort();&lt;br /&gt;       var sequence:SortField= new SortField(&amp;quot;Sequence&amp;quot;,false,false);&lt;br /&gt;       sort.fields=[sequence];&lt;br /&gt;       this.questions.sort=sort;&lt;br /&gt;       this.questions.refresh();&lt;br /&gt;   &lt;br /&gt;   }&lt;br /&gt;   &lt;br /&gt;   /**&lt;br /&gt;    * We initialize the sequence numbers taking into account the number of questions&lt;br /&gt;    */ &lt;br /&gt;   private function initSequenceNumbers():void {&lt;br /&gt;    this.sequenceNumbers= new ArrayCollection();&lt;br /&gt;    for (var i:int=0; i&amp;lt;questions.length; i++ ) {&lt;br /&gt;     sequenceNumbers.addItem(i+1);&lt;br /&gt;    }&lt;br /&gt;   }&lt;br /&gt;  ]]&amp;gt;&lt;br /&gt; &amp;lt;/mx:Script&amp;gt;&lt;br /&gt;      &amp;lt;mx:DataGrid width=&amp;quot;300&amp;quot; rowCount=&amp;quot;4&amp;quot; editable=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;             &amp;lt;mx:ArrayCollection id=&amp;quot;questions&amp;quot;&amp;gt;&lt;br /&gt;           &amp;lt;mx:Object&amp;gt;&lt;br /&gt;              &amp;lt;mx:Sequence&amp;gt;1&amp;lt;/mx:Sequence&amp;gt;&lt;br /&gt;              &amp;lt;mx:Question&amp;gt;Who is the queen of England?&amp;lt;/mx:Question&amp;gt;&lt;br /&gt;           &amp;lt;/mx:Object&amp;gt;&lt;br /&gt;           &lt;br /&gt;               &amp;lt;mx:Object&amp;gt;&lt;br /&gt;              &amp;lt;mx:Sequence&amp;gt;3&amp;lt;/mx:Sequence&amp;gt;&lt;br /&gt;              &amp;lt;mx:Question&amp;gt;Who is the king of pop?&amp;lt;/mx:Question&amp;gt;&lt;br /&gt;           &amp;lt;/mx:Object&amp;gt;&lt;br /&gt;           &lt;br /&gt;           &amp;lt;mx:Object&amp;gt;&lt;br /&gt;              &amp;lt;mx:Sequence&amp;gt;2&amp;lt;/mx:Sequence&amp;gt;&lt;br /&gt;              &amp;lt;mx:Question&amp;gt;Who is the king of Spain?&amp;lt;/mx:Question&amp;gt;&lt;br /&gt;           &amp;lt;/mx:Object&amp;gt;&lt;br /&gt; &lt;br /&gt;         &amp;lt;/mx:ArrayCollection&amp;gt;&lt;br /&gt; &lt;br /&gt;             &amp;lt;mx:columns&amp;gt;&lt;br /&gt;                 &amp;lt;mx:DataGridColumn id=&amp;quot;sequenceColumn&amp;quot; dataField=&amp;quot;Sequence&amp;quot; headerText=&amp;quot;Sequence&amp;quot; editable=&amp;quot;true&amp;quot; editorDataField=&amp;quot;value&amp;quot; sortable=&amp;quot;false&amp;quot; &amp;gt;&lt;br /&gt;               &amp;lt;mx:itemEditor &amp;gt;&lt;br /&gt;                   &amp;lt;mx:Component&amp;gt;&lt;br /&gt;                       &amp;lt;mx:ComboBox  editable=&amp;quot;false&amp;quot; dataProvider=&amp;quot;{outerDocument.sequenceNumbers}&amp;quot;  &amp;gt;&lt;br /&gt;                        &lt;br /&gt;                       &amp;lt;/mx:ComboBox&amp;gt;&lt;br /&gt;                   &amp;lt;/mx:Component&amp;gt;&lt;br /&gt;               &amp;lt;/mx:itemEditor&amp;gt;&lt;br /&gt;           &amp;lt;/mx:DataGridColumn&amp;gt;&lt;br /&gt;                 &amp;lt;mx:DataGridColumn dataField=&amp;quot;Question&amp;quot; headerText=&amp;quot;Question&amp;quot; editable=&amp;quot;false&amp;quot; sortable=&amp;quot;false&amp;quot;/&amp;gt;&lt;br /&gt;             &amp;lt;/mx:columns&amp;gt;&lt;br /&gt;         &amp;lt;/mx:DataGrid&amp;gt;&lt;br /&gt;&amp;lt;/mx:Application&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;a href="http://files.spltech.co.uk.s3.amazonaws.com/FlexExamples/FlexExample8.html"&gt;Click here to see the Combo box in a DataGrid example in action&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5712470018526280356-3743894862879223491?l=simplyolaf.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://simplyolaf.blogspot.com/feeds/3743894862879223491/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5712470018526280356&amp;postID=3743894862879223491' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5712470018526280356/posts/default/3743894862879223491'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5712470018526280356/posts/default/3743894862879223491'/><link rel='alternate' type='text/html' href='http://simplyolaf.blogspot.com/2009/07/adobe-flex-add-combo-box-to-datagrid.html' title='Adobe Flex: Add a combo box to a DataGrid that re-orders its elements'/><author><name>Armindo Cachada</name><uri>http://www.blogger.com/profile/17668696197506133653</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5712470018526280356.post-5519108988875721186</id><published>2009-07-09T05:21:00.000-07:00</published><updated>2009-07-09T07:00:48.432-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='adobe flex'/><category scheme='http://www.blogger.com/atom/ns#' term='Timer'/><category scheme='http://www.blogger.com/atom/ns#' term='TimerEvent'/><category scheme='http://www.blogger.com/atom/ns#' term='flex3'/><title type='text'>Adobe Flex: Creating a countdown clock with Timer</title><content type='html'>Are you trying to find a quick and easy way of creating a countdown clock in Adobe Flex. Don't look any further. I'll go straight to the point:&lt;br /&gt;&lt;pre&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;&amp;lt;mx:Application xmlns:mx=&amp;quot;http://www.adobe.com/2006/mxml&amp;quot; layout=&amp;quot;absolute&amp;quot; creationComplete=&amp;quot;creationComplete()&amp;quot;&amp;gt;&lt;br /&gt; &amp;lt;mx:Script&amp;gt;&lt;br /&gt; &amp;lt;![CDATA[&lt;br /&gt;  import mx.controls.Alert;&lt;br /&gt;  [Bindable]&lt;br /&gt;  private var n_seconds_left:int=30;&lt;br /&gt;  private var timer:Timer;&lt;br /&gt;   &lt;br /&gt;  /**&lt;br /&gt;   * Initialises the timer&lt;br /&gt;   */&lt;br /&gt;  private function creationComplete():void {&lt;br /&gt;  this.timer= new Timer(1000,n_seconds_left);&lt;br /&gt;                      timer.addEventListener(TimerEvent.TIMER,decrementSeconds);   &lt;br /&gt;  timer.start();&lt;br /&gt;  }&lt;br /&gt;   &lt;br /&gt;  /**&lt;br /&gt;   * Decrements the number of seconds left if it still is&lt;br /&gt;   * bigger than 0. Otherwise stop the timer.&lt;br /&gt;   * &lt;br /&gt;   */&lt;br /&gt;  private function decrementSeconds(event:TimerEvent):void {&lt;br /&gt;   n_seconds_left--;&lt;br /&gt;  }&lt;br /&gt;   &lt;br /&gt;  ]]&amp;gt;&lt;br /&gt; &amp;lt;/mx:Script&amp;gt;&lt;br /&gt; &amp;lt;mx:Label text=&amp;quot;Final Countdown: {n_seconds_left}&amp;quot; fontSize=&amp;quot;18&amp;quot;/&amp;gt;&lt;br /&gt;&amp;lt;/mx:Application&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The constructor for the Timer class in Adobe Flex takes two arguments:&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;&lt;b&gt;delay&lt;/b&gt;- Time interval in milliseconds for generating a TimerEvent. In our example, we set that value as 1000 milliseconds=1 second as you would expect for a clock.&lt;br /&gt;&lt;li&gt;&lt;b&gt;count&lt;/b&gt; - number of times that a TimerEvent will be generated before a TimerEvent.TIME_COMPLETE is generated. In our example it was 30. This means that our countdown clock only runs for 30 seconds. If you don't specify this value the Timer will run forever and the TimerEvent.TIME_COMPLETE will never be dispatched&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;If we don't specify the second argument when creating a Timer we still can achieve the same results:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;&amp;lt;mx:Application xmlns:mx=&amp;quot;http://www.adobe.com/2006/mxml&amp;quot; layout=&amp;quot;absolute&amp;quot; creationComplete=&amp;quot;creationComplete()&amp;quot;&amp;gt;&lt;br /&gt; &amp;lt;mx:Script&amp;gt;&lt;br /&gt;  &amp;lt;![CDATA[&lt;br /&gt;  import mx.controls.Alert;&lt;br /&gt;  [Bindable]&lt;br /&gt;  private var n_seconds_left:int=30;&lt;br /&gt;  private var timer:Timer;&lt;br /&gt;   &lt;br /&gt;  /**&lt;br /&gt;   * Initialises the timer&lt;br /&gt;   */&lt;br /&gt;  private function creationComplete():void {&lt;br /&gt;   this.timer= new Timer(1000);&lt;br /&gt;   timer.addEventListener(TimerEvent.TIMER, decrementSeconds); &lt;br /&gt;   timer.start();&lt;br /&gt;  }&lt;br /&gt;   &lt;br /&gt;  /**&lt;br /&gt;   * Decrements the number of seconds left if it still is&lt;br /&gt;   * bigger than 0. Otherwise stop the timer.&lt;br /&gt;   * &lt;br /&gt;   */&lt;br /&gt;  private function decrementSeconds(event:TimerEvent):void {&lt;br /&gt;     if (this.n_seconds_left&amp;gt;0) {&lt;br /&gt;   n_seconds_left--;&lt;br /&gt;     }&lt;br /&gt;     else {&lt;br /&gt;        timer.stop();&lt;br /&gt;      }&lt;br /&gt;  }&lt;br /&gt;   &lt;br /&gt;  ]]&amp;gt;&lt;br /&gt; &amp;lt;/mx:Script&amp;gt;&lt;br /&gt; &amp;lt;mx:Label text=&amp;quot;Final Countdown: {n_seconds_left}&amp;quot; fontSize=&amp;quot;18&amp;quot;/&amp;gt;&lt;br /&gt;&amp;lt;/mx:Application&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The biggest difference to the previous code is that we use Timer.stop() to interrupt the timer to prevent another TimerEvent from being called so that our countdown clock doesn't go below 0.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://files.spltech.co.uk.s3.amazonaws.com/FlexExample7/FlexExample7.html"&gt;Click here to see our countdown clock in action&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5712470018526280356-5519108988875721186?l=simplyolaf.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://simplyolaf.blogspot.com/feeds/5519108988875721186/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5712470018526280356&amp;postID=5519108988875721186' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5712470018526280356/posts/default/5519108988875721186'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5712470018526280356/posts/default/5519108988875721186'/><link rel='alternate' type='text/html' href='http://simplyolaf.blogspot.com/2009/07/adobe-flex-creating-countdown-clock.html' title='Adobe Flex: Creating a countdown clock with Timer'/><author><name>Armindo Cachada</name><uri>http://www.blogger.com/profile/17668696197506133653</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5712470018526280356.post-4838458301782894720</id><published>2009-07-05T02:31:00.000-07:00</published><updated>2009-07-06T23:13:35.554-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='struts 2'/><category scheme='http://www.blogger.com/atom/ns#' term='flex 3'/><category scheme='http://www.blogger.com/atom/ns#' term='struts2+flex'/><category scheme='http://www.blogger.com/atom/ns#' term='adobe flex'/><category scheme='http://www.blogger.com/atom/ns#' term='struts+flex'/><category scheme='http://www.blogger.com/atom/ns#' term='HttpService'/><title type='text'>Adobe Flex with Struts 2 using HttpService</title><content type='html'>Using HttpService is the easiest way in which you can integrate Adobe Flex and Struts 2. As an example I will show you how you can create a registration form in Adobe Flex which calls a struts 2 action to create new users. Note that this example is very simple and for demonstration purposes. I am not adding any validation in flex and not even creating the users in a database. All I show you is how you can pass data between flex and struts.&lt;br /&gt;&lt;br /&gt;First let me show you the steps you need to perform in Adobe Flex:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Step 1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Create the registration form in mxml:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;mx:Form label=&amp;quot;Registration Form&amp;quot;&amp;gt;&lt;br /&gt; &amp;lt;mx:FormHeading label=&amp;quot;Registration Form&amp;quot;&amp;gt;&lt;br /&gt; &amp;lt;/mx:FormHeading&amp;gt;&lt;br /&gt; &amp;lt;mx:FormItem label=&amp;quot;First Name&amp;quot;&amp;gt;&lt;br /&gt;  &amp;lt;mx:TextInput id=&amp;quot;firstName&amp;quot;&amp;gt;&lt;br /&gt;  &amp;lt;/mx:TextInput&amp;gt;&lt;br /&gt; &amp;lt;/mx:FormItem&amp;gt;&lt;br /&gt; &amp;lt;mx:FormItem label=&amp;quot;Last Name&amp;quot;&amp;gt;&lt;br /&gt;  &amp;lt;mx:TextInput id=&amp;quot;lastName&amp;quot;&amp;gt;&lt;br /&gt;  &amp;lt;/mx:TextInput&amp;gt;&lt;br /&gt; &amp;lt;/mx:FormItem&amp;gt;&lt;br /&gt; &amp;lt;mx:FormItem label=&amp;quot;Email&amp;quot;&amp;gt;&lt;br /&gt;   &amp;lt;mx:TextInput id=&amp;quot;email&amp;quot;&amp;gt;&lt;br /&gt;  &amp;lt;/mx:TextInput&amp;gt;&lt;br /&gt; &amp;lt;/mx:FormItem&amp;gt;&lt;br /&gt; &amp;lt;mx:FormItem label=&amp;quot;Username&amp;quot;&amp;gt;&lt;br /&gt;  &amp;lt;mx:TextInput id=&amp;quot;username&amp;quot;&amp;gt;&lt;br /&gt;  &amp;lt;/mx:TextInput&amp;gt;&lt;br /&gt; &amp;lt;/mx:FormItem&amp;gt;&lt;br /&gt; &amp;lt;mx:FormItem label=&amp;quot;Password&amp;quot;&amp;gt;&lt;br /&gt;  &amp;lt;mx:TextInput id=&amp;quot;password&amp;quot; displayAsPassword=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;  &amp;lt;/mx:TextInput&amp;gt;&lt;br /&gt; &amp;lt;/mx:FormItem&amp;gt;&lt;br /&gt; &amp;lt;mx:FormItem&amp;gt;&lt;br /&gt;  &amp;lt;mx:Button label=&amp;quot;Register&amp;quot; click=&amp;quot;registerUser()&amp;quot;/&amp;gt;&lt;br /&gt; &amp;lt;/mx:FormItem&amp;gt;&lt;br /&gt;&amp;lt;/mx:Form&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Step 2&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Create the HttpService object:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;mx:HTTPService id=&amp;quot;registerService&amp;quot; showBusyCursor=&amp;quot;true&amp;quot; useProxy=&amp;quot;false&amp;quot; url=&amp;quot;register.action&amp;quot; resultFormat=&amp;quot;e4x&amp;quot; method=&amp;quot;POST&amp;quot; result=&amp;quot;registerConfirmation(event)&amp;quot; fault=&amp;quot;registerFailed(event)&amp;quot;/&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;register.action&lt;/b&gt; is the Struts 2 action that registers the user&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;b&gt;registerConfirmation(event)&lt;/b&gt; is the function that is called if the http service call is successful. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;b&gt;registerFailed(event)&lt;/b&gt; is the function that is called if an error occurs. For example if the server is down. The event object gives you access to any xml/html that might be returned upon the call of the action.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;b&gt;resultFormat&lt;/b&gt; specifies in which format you want to view the results. It can be &lt;b&gt;text&lt;/b&gt;, &lt;b&gt;xml&lt;/b&gt; or an &lt;b&gt;object&lt;/b&gt;. There are 5 possible values for this field:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;object - An XML object is returned and is parsed as a tree of ActionScript objects&lt;/li&gt;&lt;br /&gt;&lt;li&gt;xml - Returns literal XML in an XMLNode object&lt;/li&gt;&lt;br /&gt;&lt;li&gt;e4x - Returns literal XML that can be accessed using ECMAScript for XML(E4X) expressions.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;flashvars - The result is text in &lt;b&gt;flashvars&lt;/b&gt; format, value pairs separated by ampersands. Flex returns this result in an actionscript object &lt;/li&gt;&lt;br /&gt;&lt;li&gt;array - The result is XML that is returned in an Array even if there is only one top level node.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Step 3&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Write the actionscript call to submit the form:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public function registerUser():void {&lt;br /&gt;      var params:Object = { 'user.firstName': firstName.text,'user.lastName': lastName.text, 'user.email':email.text, 'user.password':password.text }; &lt;br /&gt;      this.registerService.send(params);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Step 4&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Create registerConfirmation(). This method checks whether the registration was successful. We can know that by inspecting the XML that is returned.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;private function registerConfirmation(event:ResultEvent):void {&lt;br /&gt;        var xml:XML=XML(event.result); &lt;br /&gt; if (xml != null &amp;&amp; xml.item == true) {&lt;br /&gt;  mx.controls.Alert.show(&amp;quot;Registration Successful!&amp;quot;);&lt;br /&gt; }&lt;br /&gt; else {&lt;br /&gt;  mx.controls.Alert.show(&amp;quot;The registration was not successful.&amp;quot;);&lt;br /&gt; }&lt;br /&gt; }}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Step 5&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;If we can't call the action on the server because of some networking issue we also should give some feedback to the user.&lt;br /&gt;&lt;pre&gt;   &lt;br /&gt;/**&lt;br /&gt; * Display a message to the user explaining what went wrong&lt;br /&gt; */&lt;br /&gt;private function registerFailed(event:FaultEvent):void {&lt;br /&gt; mx.controls.Alert.show(event.fault.message);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now let's create our Struts 2 Action:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Step 1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Create RegisterAction.java&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;package uk.co.spltech.web.actions;&lt;br /&gt;&lt;br /&gt;import uk.co.spltech.beans.User;&lt;br /&gt;&lt;br /&gt;import com.opensymphony.xwork2.ActionSupport;&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt; * Creates a new user&lt;br /&gt; * &lt;br /&gt; * @author Armindo Cachada&lt;br /&gt; *&lt;br /&gt; */&lt;br /&gt;public class RegisterAction extends ActionSupport {&lt;br /&gt;&lt;br /&gt; private User user;&lt;br /&gt; &lt;br /&gt; private Boolean success;&lt;br /&gt; &lt;br /&gt; public Boolean getSuccess() {&lt;br /&gt;  return success;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public void setSuccess(Boolean success) {&lt;br /&gt;  this.success = success;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public User getUser() {&lt;br /&gt;  return user;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public void setUser(User user) {&lt;br /&gt;  this.user = user;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; /**&lt;br /&gt;  * Registers a user&lt;br /&gt;  * &lt;br /&gt;  * @return&lt;br /&gt;  */&lt;br /&gt; public String register() {&lt;br /&gt;  System.out.println(&amp;quot;Checking user&amp;quot;);&lt;br /&gt;  if ( this.getUser()!= null) {&lt;br /&gt;   User u = this.getUser();&lt;br /&gt;   if (u.getEmail()!= null &amp;&amp; !u.getEmail().equals(&amp;quot;&amp;quot;) &amp;&amp; u.getPassword()!= null &lt;br /&gt;     &amp;&amp; !u.getPassword().equals(&amp;quot;&amp;quot;) ) {&lt;br /&gt;    System.out.println(&amp;quot;Successfully registered user with email=&amp;quot; + u.getEmail());&lt;br /&gt;    this.success=true;&lt;br /&gt;   }&lt;br /&gt;   else {&lt;br /&gt;    this.success=false;&lt;br /&gt;    System.out.println(&amp;quot;Error registering user&amp;quot;);&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt;  else {&lt;br /&gt;   this.success=false;&lt;br /&gt;   System.out.println(&amp;quot;Error registering user&amp;quot;);&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  return SUCCESS;&lt;br /&gt;&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Step 2&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Add action name='register' to struts.xml&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;package name=&amp;quot;user&amp;quot; extends=&amp;quot;struts-default&amp;quot;&amp;gt;&lt;br /&gt;        &amp;lt;action name=&amp;quot;register&amp;quot; method=&amp;quot;register&amp;quot; class=&amp;quot;uk.co.spltech.web.actions.RegisterAction&amp;quot;&amp;gt;&lt;br /&gt;           &amp;lt;result type=&amp;quot;xslt&amp;quot;&amp;gt;   &amp;lt;param name=&amp;quot;exposedValue&amp;quot;&amp;gt;{success}&amp;lt;/param&amp;gt;&amp;lt;/result&amp;gt;&lt;br /&gt;        &amp;lt;/action&amp;gt;&lt;br /&gt;&amp;lt;/package&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://files.spltech.co.uk.s3.amazonaws.com/example5.zip"&gt;Source for "Adobe Flex with Struts 2 using HttpService" Example&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;To compile this example you will need to copy the following libraries to the lib folder:&lt;br /&gt;&lt;br /&gt;commons-fileupload-1.2.1.jar&lt;br /&gt;commons-io-1.3.2.jar&lt;br /&gt;commons-logging.jar&lt;br /&gt;freemarker-2.3.13.jar&lt;br /&gt;ognl-2.6.11.jar&lt;br /&gt;struts2-core-2.1.6.jar&lt;br /&gt;xwork-2.1.2.jar&lt;br /&gt;struts2-convention-plugin-2.1.6.jar&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5712470018526280356-4838458301782894720?l=simplyolaf.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://simplyolaf.blogspot.com/feeds/4838458301782894720/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5712470018526280356&amp;postID=4838458301782894720' title='14 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5712470018526280356/posts/default/4838458301782894720'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5712470018526280356/posts/default/4838458301782894720'/><link rel='alternate' type='text/html' href='http://simplyolaf.blogspot.com/2009/07/adobe-flex-with-struts-2-using.html' title='Adobe Flex with Struts 2 using HttpService'/><author><name>Armindo Cachada</name><uri>http://www.blogger.com/profile/17668696197506133653</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>14</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5712470018526280356.post-3973088572213226153</id><published>2009-07-04T23:55:00.000-07:00</published><updated>2009-07-19T14:23:00.138-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Web Services'/><category scheme='http://www.blogger.com/atom/ns#' term='adobe flex'/><category scheme='http://www.blogger.com/atom/ns#' term='HttpService'/><category scheme='http://www.blogger.com/atom/ns#' term='AMF'/><category scheme='http://www.blogger.com/atom/ns#' term='BlazeDS'/><title type='text'>Integrating Adobe Flex with Struts 2</title><content type='html'>I have noticed a lot of people on the internet are searching for information on how to integrate Struts 2 with Adobe Flex. It is not as complicated as most think and there's more than one way of doing it.&lt;br /&gt;&lt;h4&gt;Ways in which you can integrate Adobe Flex and Struts:&lt;/h4&gt;&lt;br /&gt;1. Use &lt;b&gt;HttpService&lt;/b&gt; in Adobe Flex to call actions in Struts. In Struts, instead of returning a jsp file change the return type of your action to XSLT. In this way the contents of your action are automatically converted to XML. You can use the XML result in Adobe Flex to determine the result of the action that you invoked using &lt;b&gt;HttpService&lt;/b&gt;.&lt;br /&gt;This technique is by far the easiest of the three. &lt;br /&gt;The main advantages are:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;It is quite simple to use compared to the other techniques&lt;/li&gt;&lt;br /&gt; &lt;li&gt;You get complete control on the information that you transfer between Adobe Flex and Struts&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;There are disadvantages though:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;The more information you transfer between Flex and Struts the more code you have to write for parsing/converting/... data&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;You can easily use HttpService to &lt;b&gt;register&lt;/b&gt; a user using a struts action or to &lt;b&gt;authenticate&lt;/b&gt; a user. Or you can use HttpService to retrieve information from the database through struts. In my next post I will give you an example on how to implement a registration system using HttpService.&lt;br /&gt;&lt;br /&gt;2. Use Soap &lt;b&gt;Web Services&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Use Soap &lt;b&gt;WebServices&lt;/b&gt; to connect to the Struts 2 backend. If you use an EJB 3 compliant application server you can easily create a web service by adding the @WebService annotation to an EJB 3 bean interface. &lt;br /&gt;If you don't have an EJB 3 compliant application server we recommend you to use &lt;a href="http://ws.apache.org/axis2/"&gt;Apache Axis 2&lt;/a&gt; or &lt;a href="http://enunciate.codehaus.org/"&gt;Enunciate&lt;/a&gt;. The advantage of Enunciate is that you can publish your service not only for use with SOAP, it also creates endpoints for REST, AMF and JSON.  We will exemplify this approach in a later post.&lt;br /&gt;&lt;br /&gt;The advantages of using Web Services are:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Automatic class generation: With a few mouse clicks and the WSDL that describes your web service, Flex generates all the classes needed to access your web service. &lt;br /&gt;This is done via the ported version of Apache Axis.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;The conversion of data from/to XML is done automatically for you. You only deal with objects and method calls.&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt; &lt;br /&gt;The major &lt;b&gt;disadvantage&lt;/b&gt; of using web services are &lt;b&gt;circular references&lt;/b&gt;. An example of a circular reference is one where the child node of an object references its parent.&lt;br /&gt;&lt;br /&gt;A ----&gt; B&lt;br /&gt;B ----&gt; A&lt;br /&gt;&lt;br /&gt;You need to deal with this by using annotations or by manually deleting the circular reference. Otherwise you will get a nasty marshaling/unmarshaling exception when calling the web service.&lt;br /&gt;&lt;br /&gt;3. Using &lt;b&gt;BlazeDS&lt;/b&gt;, from Flex it is possible to invoke methods on java objects deployed in an application server. This is done using AMF a message protocol developed by Adobe. This is a similar method to using SOAP. The only difference is that all the information is transferred in binary format. Performance wise this is probably the best option available to integrate Java/J2EE and Adobe Flex. Read my post on &lt;a href="http://simplyolaf.blogspot.com/2009/07/integrate-adobe-flex-and-jboss-using.html"&gt;Integrate Adobe Flex and JBOSS using BlazeDS&lt;/a&gt; for more information.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5712470018526280356-3973088572213226153?l=simplyolaf.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://simplyolaf.blogspot.com/feeds/3973088572213226153/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5712470018526280356&amp;postID=3973088572213226153' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5712470018526280356/posts/default/3973088572213226153'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5712470018526280356/posts/default/3973088572213226153'/><link rel='alternate' type='text/html' href='http://simplyolaf.blogspot.com/2009/07/integrating-adobe-flex-with-struts-2.html' title='Integrating Adobe Flex with Struts 2'/><author><name>Armindo Cachada</name><uri>http://www.blogger.com/profile/17668696197506133653</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5712470018526280356.post-5430692541516008879</id><published>2009-07-02T01:52:00.000-07:00</published><updated>2009-07-02T02:08:18.492-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ArrayCollection'/><category scheme='http://www.blogger.com/atom/ns#' term='flex 3'/><category scheme='http://www.blogger.com/atom/ns#' term='SortField'/><title type='text'>Flex 3: Sorting an ArrayCollection using SortField</title><content type='html'>You can use ArrayCollection and SortField to sort a list of items based on one or more fields:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;this.names= new ArrayCollection();&lt;br /&gt;names.addItem({first:&amp;quot;John&amp;quot;,last:&amp;quot;Travolta&amp;quot;});&lt;br /&gt;names.addItem({first:&amp;quot;Miguel&amp;quot;,last:&amp;quot;Nunes&amp;quot;}); &lt;br /&gt;    names.addItem({first:&amp;quot;Christina&amp;quot;,last:&amp;quot;Aguilera&amp;quot;});   &lt;br /&gt;names.addItem({first:&amp;quot;Michael&amp;quot;,last:&amp;quot;Jackson&amp;quot;});&lt;br /&gt;var sort:Sort= new Sort();&lt;br /&gt;sort.fields=[new SortField(&amp;quot;last&amp;quot;,true,true), new SortField(&amp;quot;first&amp;quot;,true,true)];&lt;br /&gt;names.sort=sort;&lt;br /&gt;names.refresh();&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;You can try the adobe flex example &lt;a href="http://files.spltech.co.uk.s3.amazonaws.com/FlexExample4/FlexExample4.html"&gt;here&lt;/a&gt;. View source is enabled.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5712470018526280356-5430692541516008879?l=simplyolaf.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://simplyolaf.blogspot.com/feeds/5430692541516008879/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5712470018526280356&amp;postID=5430692541516008879' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5712470018526280356/posts/default/5430692541516008879'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5712470018526280356/posts/default/5430692541516008879'/><link rel='alternate' type='text/html' href='http://simplyolaf.blogspot.com/2009/07/flex-3-sorting-arraycollection-using.html' title='Flex 3: Sorting an ArrayCollection using SortField'/><author><name>Armindo Cachada</name><uri>http://www.blogger.com/profile/17668696197506133653</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5712470018526280356.post-4032394641140156932</id><published>2009-07-01T22:52:00.000-07:00</published><updated>2009-07-01T23:43:52.586-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='struts 2.1'/><category scheme='http://www.blogger.com/atom/ns#' term='struts 2'/><category scheme='http://www.blogger.com/atom/ns#' term='file upload'/><category scheme='http://www.blogger.com/atom/ns#' term='flex 3'/><category scheme='http://www.blogger.com/atom/ns#' term='FileReference'/><category scheme='http://www.blogger.com/atom/ns#' term='adobe flex'/><title type='text'>Uploading a file with Flex 3 and Struts 2</title><content type='html'>In my previous post I taught you how to upload a file using Struts 2. In the example I gave you, both the presentation layer and the code that received the file were done in Struts 2.&lt;br /&gt;But what if you want to upload a file via Adobe Flex? How can you do it?&lt;br /&gt;&lt;br /&gt;The FileReference flex class allows you to upload files from a client to a server. In our case a server running Struts 2. FileReference shows a dialog box that allows the user to select which file to upload.&lt;br /&gt;Enough of theory. Below is an example of the code that you can use to upload a file to a server running struts 2:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Step 1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;First you need to create the dialog box that will allow the user to select a file to upload by clicking the button "Browse".&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;mx:VBox width=&amp;quot;100%&amp;quot; left=&amp;quot;10&amp;quot; top=&amp;quot;10&amp;quot; &amp;gt;&lt;br /&gt;   &amp;lt;mx:HBox&amp;gt;&lt;br /&gt;       &amp;lt;mx:Label text=&amp;quot;Image to upload:&amp;quot;/&amp;gt; &amp;lt;mx:TextInput disabledColor=&amp;quot;black&amp;quot; enabled=&amp;quot;false&amp;quot; id=&amp;quot;fileName&amp;quot; width=&amp;quot;200&amp;quot;  /&amp;gt;&lt;br /&gt;              &amp;lt;mx:Button width=&amp;quot;80&amp;quot; label=&amp;quot;Browse&amp;quot; click=&amp;quot;browseFiles()&amp;quot; /&amp;gt;&lt;br /&gt;   &amp;lt;/mx:HBox&amp;gt;&lt;br /&gt;          &amp;lt;mx:Button id=&amp;quot;uploadButton&amp;quot; label=&amp;quot;Upload&amp;quot; enabled=&amp;quot;false&amp;quot; click=&amp;quot;upload()&amp;quot;/&amp;gt;&lt;br /&gt;          &amp;lt;mx:ProgressBar labelPlacement=&amp;quot;center&amp;quot;  source=&amp;quot;{fileRef}&amp;quot; label=&amp;quot;%3%%&amp;quot; minimum=&amp;quot;0&amp;quot; maximum=&amp;quot;100&amp;quot; color=&amp;quot;blue&amp;quot; height=&amp;quot;13&amp;quot; width=&amp;quot;100&amp;quot; id=&amp;quot;progressBar&amp;quot; visible=&amp;quot;false&amp;quot; includeInLayout=&amp;quot;false&amp;quot; /&amp;gt;&lt;br /&gt;    &lt;br /&gt;        &amp;lt;/mx:VBox&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Step 2&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Create an object of type FileReference and add event listeners to track progress of the upload:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt; fileRef = new FileReference();&lt;br /&gt; fileRef.addEventListener(Event.COMPLETE, completeEvent);&lt;br /&gt; fileRef.addEventListener(Event.SELECT, selectEvent);&lt;br /&gt; fileRef.addEventListener(IOErrorEvent.IO_ERROR, showError);&lt;br /&gt; fileRef.addEventListener(ProgressEvent.PROGRESS, progressEvent);&lt;br /&gt; fileRef.addEventListener(SecurityErrorEvent.SECURITY_ERROR, showError);  &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Step 3&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Write the actionscript code that opens a dialog that calls the native "Open File Dialog" in the user's operating system.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;private function browseFiles():void {&lt;br /&gt;      var validFiles:Array= new Array(new FileFilter(&amp;quot;Images (*.jpg,*.png,*.gif,*.jpeg)&amp;quot;, &amp;quot;*.jpg;*.png;*.gif;*.jpeg&amp;quot;));&lt;br /&gt;      this.fileRef.browse(validFiles);&lt;br /&gt;   }&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Step 4&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Write the actionscript code that uploads the file to the server.&lt;br /&gt;In our previous example the struts 2 action for the upload is "/fileUpload".&lt;br /&gt;Therefore we use the following url to upload the file: ${baseUrl}/fileUpload&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;/**&lt;br /&gt;   * Uploads a file to the server &lt;br /&gt;   * &lt;br /&gt;   */ &lt;br /&gt;   private function upload():void {&lt;br /&gt;     mx.controls.Alert.show(&amp;quot;Starting upload.&amp;quot;);&lt;br /&gt;     var sendVars:URLVariables;&lt;br /&gt;     var request:URLRequest;&lt;br /&gt;     sendVars = new URLVariables();&lt;br /&gt;     request = new URLRequest();&lt;br /&gt;     request.data = sendVars;&lt;br /&gt;     request.url =baseUrl + &amp;quot;/fileUpload&amp;quot;;&lt;br /&gt;     request.method = URLRequestMethod.POST;&lt;br /&gt;     fileRef.upload(request,&amp;quot;file&amp;quot;,false); &lt;br /&gt;   }  &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;You can find sample code to upload a file &lt;a href="http://files.spltech.co.uk.s3.amazonaws.com/FlexExample3/FlexExample3.html"&gt;here&lt;/a&gt;. Note however that&lt;br /&gt;the example only works with a server to receive the file.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5712470018526280356-4032394641140156932?l=simplyolaf.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://simplyolaf.blogspot.com/feeds/4032394641140156932/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5712470018526280356&amp;postID=4032394641140156932' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5712470018526280356/posts/default/4032394641140156932'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5712470018526280356/posts/default/4032394641140156932'/><link rel='alternate' type='text/html' href='http://simplyolaf.blogspot.com/2009/07/uploading-file-with-flex-3-and-struts-2.html' title='Uploading a file with Flex 3 and Struts 2'/><author><name>Armindo Cachada</name><uri>http://www.blogger.com/profile/17668696197506133653</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5712470018526280356.post-6799291264879561092</id><published>2009-07-01T20:14:00.000-07:00</published><updated>2009-07-19T03:58:59.120-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='struts 2.1'/><category scheme='http://www.blogger.com/atom/ns#' term='struts 2'/><category scheme='http://www.blogger.com/atom/ns#' term='file upload'/><category scheme='http://www.blogger.com/atom/ns#' term='FileUploadInterceptor'/><title type='text'>Uploading a file with Struts 2</title><content type='html'>Uploading a file with Struts 2 is really simple with the help of the &lt;b&gt;FileUploadInterceptor&lt;/b&gt;. The steps required to upload a file using Struts 2 are:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Step 1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Create the Struts 2 Action class. In our example we have called it FileUploadAction.java&lt;br /&gt;&lt;br /&gt;An example of an action to upload a file:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;package uk.co.spltech.web.actions;&lt;br /&gt;&lt;br /&gt;import com.opensymphony.xwork2.Action;&lt;br /&gt;import java.io.File;&lt;br /&gt;import java.io.FileInputStream;&lt;br /&gt;import java.io.IOException;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt; * Uploads a file using Struts 2&lt;br /&gt; * &lt;br /&gt; * @author Armindo Cachada&lt;br /&gt; */&lt;br /&gt;public class FileUploadAction extends ActionSupport {&lt;br /&gt;     private static final long serialVersionUID = 12323232L;&lt;br /&gt;     private File file;&lt;br /&gt;     private String fileFileName;&lt;br /&gt;     private String fileContentType;&lt;br /&gt;    &lt;br /&gt;    &lt;br /&gt; public String execute() {&lt;br /&gt;&lt;br /&gt;  return Action.SUCCESS;&lt;br /&gt; }&lt;br /&gt;   &lt;br /&gt; public File getFile() {&lt;br /&gt;        return this.file;&lt;br /&gt;     }&lt;br /&gt; &lt;br /&gt;  public void setFile(File file) {&lt;br /&gt;         this.file = file;&lt;br /&gt;      }&lt;br /&gt;&lt;br /&gt;  public void setUpload(File file) {&lt;br /&gt;      this.file = file;&lt;br /&gt;   }&lt;br /&gt; /**&lt;br /&gt;       * This method is called by the action.&lt;br /&gt;       * Here you can do whatever you want with the uploaded file&lt;br /&gt;       */&lt;br /&gt; public String upload() throws IOException  {&lt;br /&gt;        File uploadedFile =this.getFile();&lt;br /&gt;        // you can do whatever you want with the file&lt;br /&gt;        return Action.SUCCESS;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; public String getFileFileName() {&lt;br /&gt;  return fileFileName;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public void setFileFileName(String fileFileName) {&lt;br /&gt;  this.fileFileName = fileFileName;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public String getFileContentType() {&lt;br /&gt;  return fileContentType;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public void setFileContentType(String fileContentType) {&lt;br /&gt;  this.fileContentType = fileContentType;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public String getFileUrl() {&lt;br /&gt;  return fileUrl;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public void setFileUrl(String fileUrl) {&lt;br /&gt;  this.fileUrl = fileUrl;&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Step 2&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Create the action in struts.xml&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;action name=&amp;quot;fileUpload&amp;quot; class=&amp;quot;uk.co.spltech.web.actions.FileUploadAction&amp;quot; method=&amp;quot;upload&amp;quot;&amp;gt;&lt;br /&gt; &amp;lt;result&amp;gt;/success.jsp &amp;lt;/result&amp;gt;&lt;br /&gt; &amp;lt;result type=&amp;quot;error&amp;quot;&amp;gt;/upload.jsp&amp;lt;/result&amp;gt;   &lt;br /&gt;&amp;lt;/action&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Step 3&lt;br /&gt;&lt;br /&gt;Create the jsp. For example:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Please select the file you want to upload:&lt;br /&gt;&lt;br /&gt; &amp;lt;s:form action=&amp;quot;fileUpload&amp;quot; method=&amp;quot;post&amp;quot; enctype=&amp;quot;multipart/form-data&amp;quot; theme=&amp;quot;simple&amp;quot;&amp;gt;  &lt;br /&gt;  &amp;lt;s:actionerror cssClass=&amp;quot;errorMessage&amp;quot;/&amp;gt;&lt;br /&gt;  &amp;lt;s:fielderror cssClass=&amp;quot;error&amp;quot;/&amp;gt;&lt;br /&gt;      &amp;lt;s:file name=&amp;quot;upload&amp;quot; label=&amp;quot;File&amp;quot;/&amp;gt;&lt;br /&gt;     &amp;lt;s:submit/&amp;gt;   &lt;br /&gt; &amp;lt;/s:form&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Step 3&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The default maximum file size that struts 2 allows you to upload is only 2 megabytes. You can increase this size by specifying in struts.properties the struts.multipart.maxSize. This value is in bytes.&lt;br /&gt;For example:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;struts.multipart.maxSize=20480&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Finally you can download the code for this example &lt;a href="http://files.spltech.co.uk.s3.amazonaws.com/example4.zip"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Note that I didn't include the required struts2 library files with the example.&lt;br /&gt;The files you need are:&lt;br /&gt;&lt;br /&gt;commons-fileupload-1.2.1.jar&lt;br /&gt;commons-io-1.3.2.jar&lt;br /&gt;commons-logging.jar&lt;br /&gt;freemarker-2.3.13.jar&lt;br /&gt;ognl-2.6.11.jar&lt;br /&gt;struts2-core-2.1.6.jar&lt;br /&gt;xwork-2.1.2.jar&lt;br /&gt;struts2-convention-plugin-2.1.6.jar&lt;br /&gt;&lt;br /&gt;Click here to learn &lt;a href="http://simplyolaf.blogspot.com/2009/07/uploading-file-with-flex-3-and-struts-2.html"&gt;how to upload a file with Adobe Flex&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5712470018526280356-6799291264879561092?l=simplyolaf.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://simplyolaf.blogspot.com/feeds/6799291264879561092/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5712470018526280356&amp;postID=6799291264879561092' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5712470018526280356/posts/default/6799291264879561092'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5712470018526280356/posts/default/6799291264879561092'/><link rel='alternate' type='text/html' href='http://simplyolaf.blogspot.com/2009/07/uploading-file-with-struts-2.html' title='Uploading a file with Struts 2'/><author><name>Armindo Cachada</name><uri>http://www.blogger.com/profile/17668696197506133653</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5712470018526280356.post-7943758062567924837</id><published>2009-06-29T20:40:00.000-07:00</published><updated>2009-06-29T20:55:52.798-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='UTF-8'/><category scheme='http://www.blogger.com/atom/ns#' term='url'/><category scheme='http://www.blogger.com/atom/ns#' term='encoding'/><category scheme='http://www.blogger.com/atom/ns#' term='jboss 4.2.3'/><category scheme='http://www.blogger.com/atom/ns#' term='tomcat'/><category scheme='http://www.blogger.com/atom/ns#' term='jboss'/><title type='text'>Configuring JBOSS to support UTF-8 characters in the URL</title><content type='html'>The problem I have experienced this week. When I have chinese characters as part of the URL, the characters show up as garbage in the page. I mean request.getParameter("chineseCharacter") returns garbage characters. This problem happened in JBOSS 4.2.3 GA with Apache 2.0(mod_jk).&lt;br /&gt;&lt;br /&gt;Fortunately the solution is simple:&lt;br /&gt;&lt;br /&gt;Edit  JBOSS_HOME/server/${SERVER_NAME}/deploy/jboss-web.deployer/server.xml&lt;br /&gt;&lt;br /&gt;Add URIEnconding="UTF-8" to the HTTP connector and AJP connector:&lt;br /&gt;    &lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;Connector port=&amp;quot;8080&amp;quot; address=&amp;quot;${jboss.bind.address}&amp;quot;&lt;br /&gt;         maxThreads=&amp;quot;250&amp;quot; maxHttpHeaderSize=&amp;quot;8192&amp;quot;&lt;br /&gt;         emptySessionPath=&amp;quot;true&amp;quot; protocol=&amp;quot;HTTP/1.1&amp;quot;&lt;br /&gt;         enableLookups=&amp;quot;false&amp;quot; redirectPort=&amp;quot;8443&amp;quot; acceptCount=&amp;quot;100&amp;quot;&lt;br /&gt;         connectionTimeout=&amp;quot;20000&amp;quot; disableUploadTimeout=&amp;quot;true&amp;quot; URIEncoding=&amp;quot;UTF-8&amp;quot;/&amp;gt;&lt;br /&gt;&lt;br /&gt;   &amp;lt;!-- Define an AJP 1.3 Connector on port 8009 --&amp;gt;&lt;br /&gt;    &amp;lt;Connector port=&amp;quot;8009&amp;quot; address=&amp;quot;${jboss.bind.address}&amp;quot; protocol=&amp;quot;AJP/1.3&amp;quot;&lt;br /&gt;         emptySessionPath=&amp;quot;true&amp;quot; enableLookups=&amp;quot;false&amp;quot; redirectPort=&amp;quot;8443&amp;quot; URIEncoding=&amp;quot;UTF-8&amp;quot;/&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now restart your server and you should have no more problems with having non-latin characters in the URL.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5712470018526280356-7943758062567924837?l=simplyolaf.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://simplyolaf.blogspot.com/feeds/7943758062567924837/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5712470018526280356&amp;postID=7943758062567924837' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5712470018526280356/posts/default/7943758062567924837'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5712470018526280356/posts/default/7943758062567924837'/><link rel='alternate' type='text/html' href='http://simplyolaf.blogspot.com/2009/06/configuring-jboss-uri-encoding-for-utf.html' title='Configuring JBOSS to support UTF-8 characters in the URL'/><author><name>Armindo Cachada</name><uri>http://www.blogger.com/profile/17668696197506133653</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5712470018526280356.post-1768517622260823566</id><published>2009-06-25T00:42:00.000-07:00</published><updated>2009-06-25T02:15:45.019-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='event'/><category scheme='http://www.blogger.com/atom/ns#' term='event listener'/><category scheme='http://www.blogger.com/atom/ns#' term='flex 3'/><category scheme='http://www.blogger.com/atom/ns#' term='adobe flex'/><category scheme='http://www.blogger.com/atom/ns#' term='actionscript'/><title type='text'>Adding an event listener function with arguments using Actionscript</title><content type='html'>This might come handy whenever you can't use directly mxml and you need to add an event listener function that needs one or more arguments.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;&amp;lt;mx:Application xmlns:mx=&amp;quot;http://www.adobe.com/2006/mxml&amp;quot; layout=&amp;quot;absolute&amp;quot; creationComplete=&amp;quot;myInitialize()&amp;quot;&amp;gt;&lt;br /&gt; &amp;lt;mx:Script&amp;gt;&lt;br /&gt;  &amp;lt;![CDATA[&lt;br /&gt;   import mx.controls.Alert;&lt;br /&gt;      &lt;br /&gt;      private function myFunction(arg:String):void {&lt;br /&gt;       mx.controls.Alert.show(&amp;quot;Received call with argument=&amp;quot; + arg);&lt;br /&gt;      }&lt;br /&gt;  &lt;br /&gt;   private function myInitialize():void {&lt;br /&gt;    myButton.addEventListener(MouseEvent.CLICK, function(event:MouseEvent):void{&lt;br /&gt;     var someArg:String=&amp;quot;an_argument&amp;quot;;&lt;br /&gt;     myFunction(someArg);&lt;br /&gt;    });&lt;br /&gt;   }&lt;br /&gt;  ]]&amp;gt;&lt;br /&gt; &amp;lt;/mx:Script&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; &amp;lt;mx:Button id=&amp;quot;myButton&amp;quot; label=&amp;quot;Click me!&amp;quot;/&amp;gt;&lt;br /&gt;&amp;lt;/mx:Application&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;See this code in action &lt;a href="http://www.spltech.co.uk/files/flexexample2/FlexExample2.html"&gt;here&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5712470018526280356-1768517622260823566?l=simplyolaf.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://simplyolaf.blogspot.com/feeds/1768517622260823566/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5712470018526280356&amp;postID=1768517622260823566' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5712470018526280356/posts/default/1768517622260823566'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5712470018526280356/posts/default/1768517622260823566'/><link rel='alternate' type='text/html' href='http://simplyolaf.blogspot.com/2009/06/adding-event-listener-function-with.html' title='Adding an event listener function with arguments using Actionscript'/><author><name>Armindo Cachada</name><uri>http://www.blogger.com/profile/17668696197506133653</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5712470018526280356.post-5846476442939181973</id><published>2009-06-24T22:00:00.000-07:00</published><updated>2009-07-03T00:18:08.677-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='flex'/><category scheme='http://www.blogger.com/atom/ns#' term='flex 3'/><category scheme='http://www.blogger.com/atom/ns#' term='component lifecycle'/><category scheme='http://www.blogger.com/atom/ns#' term='creation policy'/><title type='text'>Adobe Flex 3 UI Components Lifecycle</title><content type='html'>In adobe flex 3 there are certain events that are called when a component is created.&lt;br /&gt;These events are raised in the following order:&lt;br /&gt;&lt;br /&gt;1) preInitialize: This event is raised when the component has just been created but none of the child components exist. &lt;br /&gt;&lt;br /&gt;2) initialize: This event is raised after the component and all its children have been created but before any dimensions have been calculated.&lt;br /&gt;&lt;br /&gt;3) creationComplete: This even is dispatched after all the component and its children have been created and after all the layout calculations have been performed.&lt;br /&gt;&lt;br /&gt;4) applicationComplete: Dispatched after all the components of an application have been successfully created&lt;br /&gt;&lt;br /&gt;Events 1) to 3) are dispatched in the order mentioned above for all visible components.&lt;br /&gt;Note however that for components that are not visible on the screen by default, none of these events will be raised. This is because depending on the creation policy the hidden components might not exist yet.&lt;br /&gt;For example in a &lt;b&gt;TabNavigator&lt;/b&gt; only the components that are inside the default tab are created because they are visible. If you do change to another non-visible tab then Flex creates the components one by one. In that case the events mentioned above are raised. &lt;br /&gt;&lt;br /&gt;We have created a simple example to demonstrate this. The &lt;b&gt;DataGrid&lt;/b&gt; shows you a list of the events that have been raised during the lifecycle of the main application window. If you change to the second tab you will see additional entries in the list due to the creation of a &lt;b&gt;Label&lt;/b&gt; UI component. &lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;&amp;lt;mx:Application xmlns:mx=&amp;quot;http://www.adobe.com/2006/mxml&amp;quot; layout=&amp;quot;absolute&amp;quot; preinitialize=&amp;quot;preInitialise()&amp;quot; initialize=&amp;quot;initialise()&amp;quot; applicationComplete=&amp;quot;applicationComplete()&amp;quot; creationComplete=&amp;quot;creationComplete()&amp;quot; viewSourceURL=&amp;quot;srcview/index.html&amp;quot;&amp;gt;&lt;br /&gt; &amp;lt;mx:Script&amp;gt;&lt;br /&gt;  &amp;lt;![CDATA[&lt;br /&gt;   import mx.collections.ArrayCollection;&lt;br /&gt;&lt;br /&gt;   [Bindable]&lt;br /&gt;   private var eventsCalled:ArrayCollection=new ArrayCollection();&lt;br /&gt;&lt;br /&gt;   public function preInitialise():void {&lt;br /&gt;    eventsCalled.addItem({label:&amp;quot;preInitialise called&amp;quot;,event:&amp;quot;preInitialise&amp;quot;});    &lt;br /&gt;   }&lt;br /&gt; &lt;br /&gt;   public function initialise():void {&lt;br /&gt;    eventsCalled.addItem({label:&amp;quot;initialise called&amp;quot;,event:&amp;quot;initialise&amp;quot;});    &lt;br /&gt;   }&lt;br /&gt;   &lt;br /&gt;   public function creationComplete():void {&lt;br /&gt;    eventsCalled.addItem({label:&amp;quot;creation complete called&amp;quot;,event:&amp;quot;creationComplete&amp;quot;});    &lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;   public function applicationComplete():void {&lt;br /&gt;    eventsCalled.addItem(&amp;quot;applicationComplete called&amp;quot;); &lt;br /&gt;   }&lt;br /&gt;      &lt;br /&gt;  ]]&amp;gt;&lt;br /&gt; &amp;lt;/mx:Script&amp;gt;&lt;br /&gt;&amp;lt;mx:TabNavigator width=&amp;quot;400&amp;quot; height=&amp;quot;400&amp;quot;&amp;gt;&lt;br /&gt;  &amp;lt;mx:Canvas label=&amp;quot;tab1&amp;quot;&amp;gt;&lt;br /&gt;   &amp;lt;mx:DataGrid id=&amp;quot;datagrid&amp;quot; dataProvider=&amp;quot;{eventsCalled}&amp;quot; top=&amp;quot;10&amp;quot; left=&amp;quot;10&amp;quot; width=&amp;quot;300&amp;quot; /&amp;gt;&lt;br /&gt;  &amp;lt;/mx:Canvas&amp;gt;&lt;br /&gt;  &amp;lt;mx:Canvas label=&amp;quot;tab2&amp;quot;&amp;gt;&lt;br /&gt;   &amp;lt;mx:Label text=&amp;quot;This label is created only when it is displayed&amp;quot; creationComplete=&amp;quot;creationComplete();&amp;quot; preinitialize=&amp;quot;preInitialise();&amp;quot;  initialize=&amp;quot;initialise();&amp;quot; /&amp;gt;&lt;br /&gt;  &amp;lt;/mx:Canvas&amp;gt;&lt;br /&gt;  &lt;br /&gt; &amp;lt;/mx:TabNavigator&amp;gt;&lt;br /&gt;&amp;lt;/mx:Application&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;To see this example in action click: &lt;a href="http://www.spltech.co.uk/files/flexexample1/FlexExample1.html"&gt;here&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;You can change this behavior by setting the &lt;b&gt;creationPolicy&lt;/b&gt; attribute, for example in the application mxml node. This attribute is only valid for &lt;b&gt;containers&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;There are 4 possible values for this attribute:&lt;br /&gt;&lt;br /&gt;1) &lt;b&gt;creationPolicy="auto"&lt;/b&gt; - the container delays creating some or all of its descendants until they are needed. This is known as &lt;b&gt;deferred instantiation&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;2) &lt;b&gt;creationPolicy="all"&lt;/b&gt; - the container immediately creates all its descendants even if they are not selected.&lt;br /&gt;&lt;br /&gt;3) &lt;b&gt;creationPolicy="queued"&lt;/b&gt; - all components inside a container are added to a creation queue. The application waits until all children of a container are created before moving to the next container.&lt;br /&gt;&lt;br /&gt;4. &lt;b&gt;creationPolicy="none"&lt;/b&gt; - all components inside a container are never created. Whoever decides to go with this strategy needs to manually create all items inside a container.&lt;br /&gt;&lt;br /&gt;For example to change the behavior seen above we could set the creationPolicy="all":&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;&amp;lt;mx:Application xmlns:mx=&amp;quot;http://www.adobe.com/2006/mxml&amp;quot; layout=&amp;quot;absolute&amp;quot; creationPolicy=&amp;quot;all&amp;quot; preinitialize=&amp;quot;preInitialise()&amp;quot; initialize=&amp;quot;initialise()&amp;quot; applicationComplete=&amp;quot;applicationComplete()&amp;quot; creationComplete=&amp;quot;creationComplete()&amp;quot; viewSourceURL=&amp;quot;srcview/index.html&amp;quot;&amp;gt;&lt;br /&gt;...&lt;br /&gt;&amp;lt;/mx:Application&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5712470018526280356-5846476442939181973?l=simplyolaf.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://simplyolaf.blogspot.com/feeds/5846476442939181973/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5712470018526280356&amp;postID=5846476442939181973' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5712470018526280356/posts/default/5846476442939181973'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5712470018526280356/posts/default/5846476442939181973'/><link rel='alternate' type='text/html' href='http://simplyolaf.blogspot.com/2009/06/adobe-flex-3-components-lifecycle.html' title='Adobe Flex 3 UI Components Lifecycle'/><author><name>Armindo Cachada</name><uri>http://www.blogger.com/profile/17668696197506133653</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5712470018526280356.post-7014299883944811259</id><published>2009-06-21T23:26:00.000-07:00</published><updated>2009-06-21T23:33:58.952-07:00</updated><title type='text'>SEO Urls/Hierarchical Actions with struts 2.1</title><content type='html'>I have added a working struts 2.1 project that gives you a working example on how to create SEO optimised urls for struts 2.1. You can find the previous post &lt;a href="http://simplyolaf.blogspot.com/2009/06/creating-hierarchical-actions-in-struts.html"&gt;here&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5712470018526280356-7014299883944811259?l=simplyolaf.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://simplyolaf.blogspot.com/feeds/7014299883944811259/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5712470018526280356&amp;postID=7014299883944811259' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5712470018526280356/posts/default/7014299883944811259'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5712470018526280356/posts/default/7014299883944811259'/><link rel='alternate' type='text/html' href='http://simplyolaf.blogspot.com/2009/06/seo-urlshierarchical-actions-with.html' title='SEO Urls/Hierarchical Actions with struts 2.1'/><author><name>Armindo Cachada</name><uri>http://www.blogger.com/profile/17668696197506133653</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5712470018526280356.post-6061598543234251692</id><published>2009-06-15T01:27:00.000-07:00</published><updated>2009-06-15T02:01:40.612-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='js'/><category scheme='http://www.blogger.com/atom/ns#' term='javascript'/><category scheme='http://www.blogger.com/atom/ns#' term='minify'/><category scheme='http://www.blogger.com/atom/ns#' term='yahoo'/><category scheme='http://www.blogger.com/atom/ns#' term='ant'/><category scheme='http://www.blogger.com/atom/ns#' term='yui compressor'/><category scheme='http://www.blogger.com/atom/ns#' term='css'/><title type='text'>Minifying CSS and JS with Yahoo YUI Compressor</title><content type='html'>In my previous blog post I explained &lt;a href="http://simplyolaf.blogspot.com/2009/06/minimizing-number-of-http-requests-by.html"&gt;how to use Ant to concatenate javascript and css files&lt;/a&gt; in a way to minimize the number of http requests. &lt;br /&gt;Another recommendation by yahoofor building &lt;b&gt;high performance websites&lt;/b&gt; is to minify JS and CSS files. The reasoning is that the smaller the size of the javascript/css, the less time it takes for them to be interpreted. &lt;br /&gt;&lt;br /&gt;Yahoo provides a great utility - &lt;a href="developer.yahoo.com/yui/compressor"&gt;yahoo yui compressor&lt;/a&gt; that minifies both javascript and css. &lt;br /&gt;&lt;br /&gt;We can therefore improve our build script and add the following task:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;!-- this compresses all the css and js in the static folder --&amp;gt;&lt;br /&gt;        &amp;lt;target name=&amp;quot;js.minify&amp;quot;&amp;gt;&lt;br /&gt;                &amp;lt;property&lt;br /&gt;                    name=&amp;quot;yui-compressor.jar&amp;quot;&lt;br /&gt;                    location=&amp;quot;lib/yuicompressor-2.4.2.jar&amp;quot; /&amp;gt;&lt;br /&gt;                &amp;lt;property&lt;br /&gt;                    name=&amp;quot;yui-compressor-ant-task.jar&amp;quot;&lt;br /&gt;                    location=&amp;quot;lib/yui-compressor-ant-task-0.3.jar&amp;quot; /&amp;gt;&lt;br /&gt;&lt;br /&gt;                &amp;lt;path id=&amp;quot;task.classpath&amp;quot;&amp;gt;&lt;br /&gt;                  &amp;lt;pathelement location=&amp;quot;${yui-compressor.jar}&amp;quot; /&amp;gt;&lt;br /&gt;                  &amp;lt;pathelement location=&amp;quot;${yui-compressor-ant-task.jar}&amp;quot; /&amp;gt;&lt;br /&gt;                &amp;lt;/path&amp;gt;&lt;br /&gt;&lt;br /&gt;                &amp;lt;taskdef&lt;br /&gt;                    name=&amp;quot;yui-compressor&amp;quot;&lt;br /&gt;                    classname=&amp;quot;net.noha.tools.ant.yuicompressor.tasks.YuiCompressorTask&amp;quot;&amp;gt;&lt;br /&gt;&lt;br /&gt;                  &amp;lt;classpath refid=&amp;quot;task.classpath&amp;quot;/&amp;gt;&lt;br /&gt;                &amp;lt;/taskdef&amp;gt;&lt;br /&gt;&lt;br /&gt;           &amp;lt;yui-compressor warn=&amp;quot;false&amp;quot; charset=&amp;quot;UTF-8&amp;quot; jsSuffix=&amp;quot;-min.js&amp;quot; cssSuffix=&amp;quot;-min.css&amp;quot; fromdir=&amp;quot;${build.dir}/static&amp;quot; todir=&amp;quot;${build.dir}/static&amp;quot;&amp;gt;&lt;br /&gt;           &amp;lt;include name=&amp;quot;**/*.js&amp;quot; /&amp;gt;&lt;br /&gt;           &amp;lt;include name=&amp;quot;**/*.css&amp;quot; /&amp;gt;&lt;br /&gt;       &amp;lt;/yui-compressor&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;                  &amp;lt;move todir=&amp;quot;${build.dir}/static&amp;quot; includeemptydirs=&amp;quot;false&amp;quot;&amp;gt;&lt;br /&gt;                    &amp;lt;fileset dir=&amp;quot;${build.dir}/static&amp;quot;&amp;gt;&lt;br /&gt;                                &amp;lt;include name=&amp;quot;**/*-min.css&amp;quot;/&amp;gt;&lt;br /&gt;                    &amp;lt;/fileset&amp;gt;&lt;br /&gt;                    &amp;lt;mapper type=&amp;quot;glob&amp;quot; from=&amp;quot;*-min.css&amp;quot; to=&amp;quot;*.css&amp;quot;/&amp;gt;&lt;br /&gt;                  &amp;lt;/move&amp;gt;&lt;br /&gt;                  &amp;lt;move todir=&amp;quot;${build.dir}/static&amp;quot; includeemptydirs=&amp;quot;false&amp;quot;&amp;gt;&lt;br /&gt;                    &amp;lt;fileset dir=&amp;quot;${build.dir}/static&amp;quot;&amp;gt;&lt;br /&gt;                                &amp;lt;include name=&amp;quot;**/*-min.js&amp;quot;/&amp;gt;&lt;br /&gt;                    &amp;lt;/fileset&amp;gt;&lt;br /&gt;                    &amp;lt;mapper type=&amp;quot;glob&amp;quot; from=&amp;quot;*-min.js&amp;quot; to=&amp;quot;*.js&amp;quot;/&amp;gt;&lt;br /&gt;                  &amp;lt;/move&amp;gt;&lt;br /&gt;&lt;br /&gt;        &amp;lt;/target&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;First we copy all the javascript and css files to the &lt;b&gt;build/static&lt;/b&gt; folder and then we use &lt;b&gt;yahoo compressor&lt;/b&gt; to minify all the files in this directory. &lt;br /&gt;&lt;br /&gt;Click &lt;a href="http://www.spltech.co.uk/files/example2.zip"&gt;here&lt;/a&gt; to download an example.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5712470018526280356-6061598543234251692?l=simplyolaf.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://simplyolaf.blogspot.com/feeds/6061598543234251692/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5712470018526280356&amp;postID=6061598543234251692' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5712470018526280356/posts/default/6061598543234251692'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5712470018526280356/posts/default/6061598543234251692'/><link rel='alternate' type='text/html' href='http://simplyolaf.blogspot.com/2009/06/minifying-css-and-js-with-yahoo.html' title='Minifying CSS and JS with Yahoo YUI Compressor'/><author><name>Armindo Cachada</name><uri>http://www.blogger.com/profile/17668696197506133653</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5712470018526280356.post-3282059482833186741</id><published>2009-06-14T19:31:00.000-07:00</published><updated>2009-06-15T01:59:46.907-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='yslow'/><category scheme='http://www.blogger.com/atom/ns#' term='ant'/><category scheme='http://www.blogger.com/atom/ns#' term='number of http requests'/><category scheme='http://www.blogger.com/atom/ns#' term='concatenate'/><title type='text'>Minimizing number of http requests by concatenating all the CSS and Javascript files</title><content type='html'>If you have installed &lt;b&gt;yslow&lt;/b&gt; in your browser you will know all about yahoo's &lt;b&gt;high performance rules&lt;/b&gt; for a website. One of the most important rules is to minimize the number of http requests. There are several ways of doing that. I will cover one of them in this post - minimizing the number of http requests by concatenating all the &lt;b&gt;javascript&lt;/b&gt; files and &lt;b&gt;css&lt;/b&gt; files into two big files. &lt;br /&gt;&lt;br /&gt;&lt;b&gt;Apache Ant&lt;/b&gt; makes the task of concatenating files together extremely easy by using concat.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;concat destfile="${build.dir}/concatenated.js"&amp;gt;&lt;br /&gt;        &amp;lt;filelist dir="${src.dir}/js"&lt;br /&gt;           files="one.js, two.js"/&amp;gt;&lt;br /&gt;&amp;lt;/concat&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This is a simple solution but I chose not to use it for the following reasons:&lt;br /&gt;&lt;br /&gt;1. I don't always want every single javascript/css to be included for all pages.&lt;br /&gt;You could create multiple concatenated files with different combinations but that would be too messy.&lt;br /&gt;&lt;br /&gt;2. We are creating a dependency between the jsps and the ant build script. Do you really want to do that?&lt;br /&gt;&lt;br /&gt;3. Javascript, css can be notoriously difficult to debug, so for development purposes&lt;br /&gt;it is useful not to do any concatenation.&lt;br /&gt;&lt;br /&gt;Ant has a neat feature that allows to do string replacement on any file by using a filterset.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&amp;lt;copy file="${build.dir}/version.txt" toFile="${dist.dir}/version.txt"&amp;gt;&lt;br /&gt; &amp;lt;filterset&amp;gt;&lt;br /&gt;   &amp;lt;filter token="DATE" value="whatever"/&amp;gt;&lt;br /&gt; &amp;lt;/filterset&amp;gt;&lt;br /&gt;&amp;lt;/copy&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;You can specify the string that you want to be replaced at build time by surrounding it with ampersands. So in the template jsps instead of including javascripts/css in the normal way, I did the following:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;@IncludeCSS css/file1.css css/file2.css ...@&lt;br /&gt;...&lt;br /&gt;@IncludeJS js/jquery.js js/thickbox.js js/vmSlider.js js/blockUI.js@&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Then I created the following ant task:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;ExtendedFileTransform concatenate="true"  propertiesfile="${build.dir}/static.mapping.properties" &amp;gt;&lt;br /&gt;  &amp;lt;jspfileset refid="jspFileset"&amp;gt;&lt;br /&gt;  &amp;lt;/jspfileset&amp;gt;&lt;br /&gt;  &amp;lt;staticfileset dir="${static_content.dir}"&amp;gt;&lt;br /&gt; &amp;lt;include name="**/*.js" /&amp;gt;&lt;br /&gt; &amp;lt;include name="**/*.css" /&amp;gt;&lt;br /&gt; &amp;lt;include name="**/*.png" /&amp;gt;&lt;br /&gt; &amp;lt;include name="**/*.jpg" /&amp;gt;&lt;br /&gt; &amp;lt;include name="**/*.jpeg" /&amp;gt;&lt;br /&gt; &amp;lt;include name="**/*.gif" /&amp;gt;&lt;br /&gt; &amp;lt;include name="**/*.PNG" /&amp;gt;&lt;br /&gt; &amp;lt;include name="**/*.JPG" /&amp;gt;&lt;br /&gt; &amp;lt;include name="**/*.GIF" /&amp;gt;&lt;br /&gt;  &amp;lt;/staticfileset&amp;gt;&lt;br /&gt;&amp;lt;/ExtendedFileTransform&amp;gt;&lt;br /&gt;&lt;/pre&gt;ExtendedFileTransform is a custom task I created, based on Julien Lecombte's &lt;a href="http://www.julienlecomte.net/blog/?s=FileTransform&amp;amp;submit=Go"&gt;File Transform&lt;/a&gt;.&lt;br /&gt;This custom task inspects all the jsps and searches for javascript(IncludeJS) and css includes(IncludeCSS). If concatenated="true" we concatenate the files specified within the IncludeXXX directory and we replace it with a valid html javascript/css include to the generated files. If concatenated="false", i.e. for development, there is no concatenation and the IncludeXXX directory is replaced with an include for each javascript/css file.&lt;br /&gt;&lt;br /&gt;The full ant target that you could use for production looks like this:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;target name=&amp;quot;-copy.static.files-prod&amp;quot;&amp;gt;&lt;br /&gt;        &amp;lt;taskdef name=&amp;quot;ExtendedFileTransform&amp;quot; classname=&amp;quot;uk.co.simpletech.ant.ExtendedFileTransform&amp;quot; classpath=&amp;quot;${build.dir}/classes&amp;quot; /&amp;gt;&lt;br /&gt;&lt;br /&gt;        &amp;lt;mkdir dir=&amp;quot;${build.dir}/staticpre&amp;quot; /&amp;gt;&lt;br /&gt;&lt;br /&gt;        &amp;lt;!-- we copy all jsp files to a temporary location --&amp;gt;&lt;br /&gt;        &amp;lt;copy todir=&amp;quot;${build.dir}/jsppre&amp;quot;&amp;gt;&lt;br /&gt;            &amp;lt;fileset dir=&amp;quot;jsp&amp;quot; includes=&amp;quot;**/*&amp;quot; /&amp;gt;&lt;br /&gt;        &amp;lt;/copy&amp;gt;&lt;br /&gt;&lt;br /&gt;        &amp;lt;fileset dir=&amp;quot;${build.dir}/jsppre&amp;quot; id=&amp;quot;jspFileset&amp;quot;&amp;gt;&lt;br /&gt;            &amp;lt;include name=&amp;quot;**/*.jsp&amp;quot; /&amp;gt;&lt;br /&gt;        &amp;lt;/fileset&amp;gt;&lt;br /&gt;        &amp;lt;!-- we concatenate the files together --&amp;gt;&lt;br /&gt;&lt;br /&gt;        &amp;lt;ExtendedFileTransform concatenate=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;        &amp;lt;jspfileset refid=&amp;quot;jspFileset&amp;quot;&amp;gt;&lt;br /&gt;            &amp;lt;/jspfileset&amp;gt;&lt;br /&gt;            &amp;lt;staticfileset dir=&amp;quot;${build.dir}/static&amp;quot;&amp;gt;&lt;br /&gt;                &amp;lt;include name=&amp;quot;**/*.js&amp;quot; /&amp;gt;&lt;br /&gt;                &amp;lt;include name=&amp;quot;**/*.css&amp;quot; /&amp;gt;&lt;br /&gt;            &amp;lt;/staticfileset&amp;gt;&lt;br /&gt;        &amp;lt;/ExtendedFileTransform&amp;gt;&lt;br /&gt;&lt;br /&gt;       &lt;br /&gt;&lt;br /&gt;        &amp;lt;delete dir=&amp;quot;${build.dir}/jsppre&amp;quot; /&amp;gt;=&lt;br /&gt;    &amp;lt;/target&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Here is an &lt;a href="http://www.spltech.co.uk/files/example1.zip"&gt;example project&lt;/a&gt; where you can see the css/js concatenation in action.&lt;br /&gt;&lt;p/&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5712470018526280356-3282059482833186741?l=simplyolaf.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://simplyolaf.blogspot.com/feeds/3282059482833186741/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5712470018526280356&amp;postID=3282059482833186741' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5712470018526280356/posts/default/3282059482833186741'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5712470018526280356/posts/default/3282059482833186741'/><link rel='alternate' type='text/html' href='http://simplyolaf.blogspot.com/2009/06/minimizing-number-of-http-requests-by.html' title='Minimizing number of http requests by concatenating all the CSS and Javascript files'/><author><name>Armindo Cachada</name><uri>http://www.blogger.com/profile/17668696197506133653</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5712470018526280356.post-2099396641265154605</id><published>2009-06-14T19:18:00.000-07:00</published><updated>2009-06-14T19:23:34.946-07:00</updated><title type='text'>Case insensitive search in hibernate</title><content type='html'>It is very simple to do case insensitive search in hibernate.&lt;br /&gt;Here is an example HQL query:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Query q = this.entityManager.createQuery("SELECT * FROM User u where lower(u.firstName)=:firstName");&lt;br /&gt;q.setParameter("firstName", firstName.toLowerCase());&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;In this case lower() will convert the firstName property to lower case allowing you to do case insensitive search.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5712470018526280356-2099396641265154605?l=simplyolaf.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://simplyolaf.blogspot.com/feeds/2099396641265154605/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5712470018526280356&amp;postID=2099396641265154605' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5712470018526280356/posts/default/2099396641265154605'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5712470018526280356/posts/default/2099396641265154605'/><link rel='alternate' type='text/html' href='http://simplyolaf.blogspot.com/2009/06/case-insensitive-search-in-hibernate.html' title='Case insensitive search in hibernate'/><author><name>Armindo Cachada</name><uri>http://www.blogger.com/profile/17668696197506133653</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5712470018526280356.post-6642797037281251919</id><published>2009-06-13T22:53:00.000-07:00</published><updated>2009-06-23T01:53:10.867-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='struts 2.1'/><category scheme='http://www.blogger.com/atom/ns#' term='hierarchical action'/><category scheme='http://www.blogger.com/atom/ns#' term='struts 2'/><category scheme='http://www.blogger.com/atom/ns#' term='seo'/><title type='text'>Creating hierarchical actions in struts 2.1</title><content type='html'>Struts 2.1 doesn't directly support hierarchical actions. Nonetheless I still was able to implement them at &lt;a href="http://www.visualmandarin.com/"&gt;visualmandarin&lt;/a&gt;.&lt;br /&gt;Notice how the podcasts and exercises urls are all organized into folders and even the lesson title is present in the url: &lt;a href="http://www.visualmandarin.com/lessons/beginner/podcasts/can-i-have-a-menu-please"&gt;Lesson - Can I have a menu please?&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;If you are interested in SEO optimized urls for your website this kind of feature is a MUST. But how to do it struts 2.1? In short the steps you need to follow are:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Step 1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;If you are running on struts 2, migrate to struts 2.1&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Step 2&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Make sure you are using the convention plugin&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Step 3&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Ensure that all your actions have an explicit namespace. If you don't you might find that those actions are being called when they shouldn't.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Step 4&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Create a wildcard action in the namespace that you want to be hierarchical. In my case I have created one in namespace /lessons:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;action name="*" namespace="/lessons" method="execute" class="lessonsLocator"&amp;gt;&lt;br /&gt;&amp;lt;result name="lister"&amp;gt;&amp;lt;/result&amp;gt;&lt;br /&gt;&amp;lt;result name="ResourceNotFoundException" type="chain"&amp;gt;404&amp;lt;/result&amp;gt;&lt;br /&gt;&amp;lt;/action&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Your lessons locator action should inspect the uri to determine which resource to display. In my case I was dealing with lessons but you could be dealing with categories and products or anything else. It shouldn't make any difference.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Step 5&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Extend org.struts2.impl.StrutsActionProxy and override the following prepare() method:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;@Override&lt;br /&gt;  protected void prepare() {&lt;br /&gt;      String profileKey = "create DefaultActionProxy: ";&lt;br /&gt;      try {&lt;br /&gt;          UtilTimerStack.push(profileKey);&lt;br /&gt;          // we backtrack the namespace until we find an action that matches&lt;br /&gt;          this.findActionByBacktracking();&lt;br /&gt;        &lt;br /&gt;          if (config == null &amp;amp;&amp;amp; unknownHandler != null) {&lt;br /&gt;              config = unknownHandler.handleUnknownAction(namespace, actionName);&lt;br /&gt;          }&lt;br /&gt;          if (config == null) {&lt;br /&gt;              String message;&lt;br /&gt;&lt;br /&gt;              if ((namespace != null) &amp;amp;&amp;amp; (namespace.trim().length() &amp;gt; 0)) {&lt;br /&gt;                  message = LocalizedTextUtil.findDefaultText(XWorkMessages.MISSING_PACKAGE_ACTION_EXCEPTION, Locale.getDefault(), new String[]{&lt;br /&gt;                      namespace, actionName&lt;br /&gt;                  });&lt;br /&gt;              } else {&lt;br /&gt;                  message = LocalizedTextUtil.findDefaultText(XWorkMessages.MISSING_ACTION_EXCEPTION, Locale.getDefault(), new String[]{&lt;br /&gt;                      actionName&lt;br /&gt;                  });&lt;br /&gt;              }&lt;br /&gt;              throw new ConfigurationException(message);&lt;br /&gt;          }&lt;br /&gt;&lt;br /&gt;          resolveMethod();&lt;br /&gt;        &lt;br /&gt;          if (!config.isAllowedMethod(method)) {&lt;br /&gt;              throw new ConfigurationException("Invalid method: "+method+" for action "+actionName);&lt;br /&gt;          }&lt;br /&gt;&lt;br /&gt;          invocation.init(this);&lt;br /&gt;&lt;br /&gt;      } finally {&lt;br /&gt;          UtilTimerStack.pop(profileKey);&lt;br /&gt;      }&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;  /**&lt;br /&gt;   * Returns a list of all possible namespaces. The one with biggest length&lt;br /&gt;   * is top of the list up to /xxx... bottom of a list. Note that we don't backtrack until&lt;br /&gt;   * the empty namespace&lt;br /&gt;   *&lt;br /&gt;   * @param namespace&lt;br /&gt;   * @return&lt;br /&gt;   */&lt;br /&gt;  private String [] getAllPossibleNamespaces(String namespace) {&lt;br /&gt;   List&amp;lt;String&amp;gt; namespaces = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;   // e.g. /lessons/hsk/.../1 -&amp;gt;&lt;br /&gt;   String [] tokens = namespace.split("/");&lt;br /&gt;   tokens=removeEmptyStrings(tokens);&lt;br /&gt;   if (tokens != null &amp;amp;&amp;amp; tokens.length &amp;gt;= 0) {&lt;br /&gt;    for (int i=0; i&amp;lt; tokens.length; i ++) {&lt;br /&gt;     String gnamespace="";&lt;br /&gt;     for (int j=0;j&amp;lt;tokens.length- i;j++) {&lt;br /&gt;      gnamespace += "/" + tokens[j] ;&lt;br /&gt;     }&lt;br /&gt;     namespaces.add(gnamespace);&lt;br /&gt;    }&lt;br /&gt;   }&lt;br /&gt;   return namespaces.toArray(new String[0]);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  private String [] removeEmptyStrings(String [] tokens) {&lt;br /&gt;   List&amp;lt;String&amp;gt; result = new ArrayList();&lt;br /&gt;   for (String token: tokens) {&lt;br /&gt;    if (token == null || token.equals("")) {&lt;br /&gt;   &lt;br /&gt;    }&lt;br /&gt;    else {&lt;br /&gt;     result.add(token);&lt;br /&gt;    }&lt;br /&gt;   }&lt;br /&gt;   return result.toArray(new String[0]);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  /**&lt;br /&gt;    * Searches for the given action in one or more namespaces&lt;br /&gt;    *&lt;br /&gt;    */&lt;br /&gt;  private void findActionByBacktracking() {&lt;br /&gt;   if (namespace != null &amp;amp;&amp;amp; !namespace.equals("") &amp;amp;&amp;amp; !namespace.equals("/")) {&lt;br /&gt;    String [] namespaces =this.getAllPossibleNamespaces(namespace);&lt;br /&gt;  &lt;br /&gt;    for (String namespace: namespaces) {&lt;br /&gt;   &lt;br /&gt;        config = configuration.getRuntimeConfiguration().getActionConfig(namespace, actionName);&lt;br /&gt;&lt;br /&gt;        if (config != null ) break;&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt;   }&lt;br /&gt;   else {&lt;br /&gt;       config = configuration.getRuntimeConfiguration().getActionConfig(namespace, actionName);    &lt;br /&gt;   }&lt;br /&gt; &lt;br /&gt;  }&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Step 6&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Extend org.apache.struts2.impl.StrutsActionProxyFactory.&lt;br /&gt;&lt;br /&gt;My implementation as an example:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public class HierarchicalActionProxyFactory extends DefaultActionProxyFactory {&lt;br /&gt;  @Override&lt;br /&gt;  public ActionProxy createActionProxy(ActionInvocation inv, String namespace, String actionName, String methodName, boolean executeResult, boolean cleanupContext) {&lt;br /&gt;    &lt;br /&gt;      HierarchicalActionProxy proxy = new HierarchicalActionProxy(inv, namespace, actionName, methodName, executeResult, cleanupContext);&lt;br /&gt;      container.inject(proxy);&lt;br /&gt;      proxy.prepare();&lt;br /&gt;      return proxy;&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;Step 7&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Finally the last step: override the &lt;b&gt;property struts.actionProxyFactory&lt;/b&gt;&lt;br /&gt;in struts.properties and point to your implementation of the proxy factory.&lt;br /&gt;&lt;br /&gt;My implementation was:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;struts.actionProxyFactory=com.visualmandarin.web.config.HierarchicalActionProxyFactory&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;If you have followed these steps correctly you should be able to have the same kind of urls that I have in visualmandarin.com website. If there's something that you don't understand don't hesitate to ask!&lt;br /&gt;&lt;br /&gt;You can find a working example &lt;a href="http://www.spltech.co.uk/files/example3.zip"&gt;here&lt;/a&gt;. This war file was tested in jboss 4.2.3 but should work in any compliant application server.&lt;br /&gt;&lt;br /&gt;What you need to get this example working:&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;Add the struts 2 library files to the lib directory&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Add the convention plugin jar file to the &lt;b&gt;lib&lt;/b&gt; directory&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Specify the correct path to your application server&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;Once you build the war file and deploy it, you can access the example at http://localhost/example3 or http://localhost:8080/example3&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5712470018526280356-6642797037281251919?l=simplyolaf.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://simplyolaf.blogspot.com/feeds/6642797037281251919/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5712470018526280356&amp;postID=6642797037281251919' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5712470018526280356/posts/default/6642797037281251919'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5712470018526280356/posts/default/6642797037281251919'/><link rel='alternate' type='text/html' href='http://simplyolaf.blogspot.com/2009/06/creating-hierarchical-actions-in-struts.html' title='Creating hierarchical actions in struts 2.1'/><author><name>Armindo Cachada</name><uri>http://www.blogger.com/profile/17668696197506133653</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry></feed>
