Since the advent of BlazeDS we can deploy a Flex application on any JEE Application Server. I personally like to place all the resources like web services endpoints, usernames, etc in Java system properties. Then I can simply get them back by doing a System.getProperty('propertyName"). If you want to know how to set and use Java system properties in JBoss, read one my previous blog entries: Setting Java System Properties in JBoss .
If your Flex application is being served from a JEE application server, it would be nice to be able to read the Java system properties of that server. On alternative is to have a POJO in the back end that reads the Java system properties in the back end, then the Flex client queries that information from the POJO using remoting. This is the option to use if you also need modify Java system properties from the Flex application. If you don't need to modify the Java system properties, there is an easier alternative.
With Flex you have the ability to pass variables to the application at startup via flashVars. A Flex application gets compiled to a Flash (SWF) file. That file usually is served embedded in an HTML page. So, if you want to pass variables to the application you create an index.html page to serve the application that looks like this:
<html>
<body>
<object id='flexApp' height='100%' width='100%'>
<param name='stockCheckEndPoint' value='http://foo/stockEndPoint/>
<param name='ldapServer' value='ldapServerName>'/>
<embed name='flexApp' src='flexApp.swf' pluginspage='http://www.adobe.com/go/getflashplayer'
height='100%' width='100%'/>
</object>
</body>
</html>
This page passed the values of stockServiceEndpoint and ldapServer to the Flex application. To read those values in Action Script Flex provides the following instructions:
stockWebServiceEndpoint = Application.application.parameters.stockCheckEndPoint;
ldapServerName = Application.application.parameters.ldapServer;
Now the values of the flashVars are in couple ActionScript variables ready to be used. This still does not solve the problem of reading Java system properties in a Flex application. The solution involves using the flashVars as described above, but instead of serving the Flex application from a static html page, to serve it from a JSP page that reads the Java system properties.
<html>
<body>
<%
String stockCheckEndPoint = System.getProperty("stockCheckEndPoint");
String ldapServer = System.getProperty("ldapServer");
%>
<object id='flexApp' height='100%' width='100%'>
<param name='stockCheckEndPoint' value='<%= stockCheckEndPoint %>'/>
<param name='ldapServer' value='<%= ldapServer %>'/>
<embed name='flexApp' src='flexApp.swf' pluginspage='http://www.adobe.com/go/getflashplayer'
height='100%' width='100%'/>
</object>
</body>
</html>
As you can see, instead of creating an index.html file to serve the Flex application, I created a JSP file (index.jsp) to server the Flex application. I read the Java system properties and placed it in the variables stockCheckEndPoint and ldapServer. Then I passed the value of these variables as flashVars. Now I can access the values of those variables with ActionScript as mentioned before. Use this formula, so you never have to hard code variables in Flex again.
um, this is my favorite post-blogher post so far. no one knows this...because i was a huge pussy...but, i was there! i did meet karl and yvonne, and they were beyond lovely. aside from that, i can only say i have already vowed to be less of a pussy next year, and, you didn't know uncircumcised penises are easier to jack off? maybe i'm more of an outsider than i thought.
Posted by: buy viagra online | October 15, 2010 at 04:29 AM
I was in Dubai last month. I was having dinnner one night at a place right next to a Tennis stadium that sometimes is used for concerts. By chance that day there was a concert staged by Iranian DJs, and the scene was awesome. Thousands of young Iranians More femals than males) all dressed in hip, revealing clothes. Couples all over each other. Outrages outfits. I could not believe it!
Posted by: order cialis | October 18, 2010 at 02:54 AM
The questions that many people make are usually incomprehensible, this is often a problem for some writers who have no idea of the most appropriate to speak on their blogs. I think this topic is very appropriate, is simple but very effective, I congratulate the idea so brilliant that they had to create this article. thank you very much for sharing the information.
Posted by: Impotence causes | October 28, 2010 at 11:40 AM
So do I. I read java system properties via page passed the values of stockServiceEndpoint..
Posted by: adobe flex developer | November 23, 2010 at 07:36 PM
I wandered lonely as a cloud !
Posted by: retro air jordans | January 04, 2011 at 07:58 PM
Living in a daily change of the old, and my life has no taste, pale years of my youth submerged all the past.
Posted by: Cheap Coach Outlet | January 06, 2011 at 04:27 PM
i agree with your views from here.
Posted by: Nike Air Max | April 20, 2011 at 08:27 PM
I think this topic is very appropriate, is simple but very effective, I congratulate the idea so brilliant that they had to create this article.
Posted by: ClubPenguin | June 30, 2011 at 02:06 AM
I have read this previously on Some blog but i don't remember the name.
Posted by: php scripts | August 28, 2011 at 02:52 PM
so good
Posted by: Dr Dre Solo | October 24, 2011 at 01:22 AM