Search Flex Components Free

Custom Search
Showing posts with label Flex Vs JAVA. Show all posts
Showing posts with label Flex Vs JAVA. Show all posts

July 6, 2009

Calling a JavaScript Function from A Flex Application

Sometimes it might be necessary to call a Javascript function from your Flex application. The technique is quite simple. It involves sending the Javascript function name along with any parameters to the ExternalInterface class. For example, let's assume that a Javascript function called changeMainContent was defined to take a tag name (id) and a url. Normally using Javascript the functions is called this way: changeMainContent(id, url). Let's define a Flex method that invokes this Javascript method:
public function callWrapper(id:String, url:String):void {
var f:String = "changeMainContent";//Javascript function
ExternalInterface.call(f,id, url);
}

Now a call this method when a button is clicked is as follows:

June 22, 2009

Handling Java Exceptions in Flex

Accessing the Throwable object in Flex

RemoteObject component invokes the fault event when an error occurs while remote method invocation. The fault event handler is provided with the FaultEvent object. This FaultEvent object has property named message of type mx.messaging.messages.ErrorMessage. The message property holds the Throwable object from the Java method in the rootCause property. We need to use this rootCauseproperty to retrieve the properties which are set to the Throwable object in Java. All the public properties from the Throwable object are available.

We will see a sample application. In this application I am creating a custom Exception and adding a getter method to that, which will return my custom data. From the Flex application I will access both the error message and the custom data.

MyException.java

public class MyException extends Exception {

public MyException(String message) {

super(message);

}

public String getMyName(){

return “Sujit Reddy G”;

}

}

Method throwing exception

This method will throw the custom exception created above, add this method to a Java class. Invoke the below method using RemoteObject component in Flex.

public void throwCheckedException() throws Exception{

throw new MyException(”This is a checked exception”);

}

Reading values in Flex application

We add the method below as the fault event handler to the RemoteObject component in the Flex application. You can see that we accessed the rootCause object to retrieve the properties of the custom Exception object returned from the Java method.

private function handleException(event:FaultEvent):void{

var errorMessage:ErrorMessage = event.message as ErrorMessage;

Alert.show(errorMessage.rootCause.message);

Alert.show(errorMessage.rootCause.myName);

}

We are adding the above method as fault event handler to the RemoteObject component.

fault=”handleException(event)”/>

Invoking the method in the Java class on button click

You can also use the flex.messaging.MessageException. This class is packaged in the flex-messaging-core.jar. You should throw MessagException instead of MyException or any custom exception created. MessageException provides a property named extendedData, which is a HashMap. You can add any data to this property and access it from the Flex application using ErrorMessage(event.message).extendedData.

Learn flex with java

Adobe - Flex Developer Center - Learn Flex and Java

SpringSource and Adobe are collaborating to make it easy for Java developers to create enterprise-class rich Internet applications (RIAs) using Adobe Flex ...
www.adobe.com/devnet/flex/flex_java.html

Flex and Java - Flex 3 Getting Started - Adobe Learning Resources

 Flex is a great solution for Java developers because it enables them to utilize the power of Java servers while creating expressive and ...
learn.adobe.com/wiki/display/Flex/Flex+and+Java

Manning: Flex on Java

Flex on Java assumes you live in the real world—not the demo. This unique book shows you how to refactor an existing web application using the server-side ...
www.manning.com/allmon/

January 5, 2008

Flex/flash could learn from Java and Maven








I want to get the first element of my "tmps" xml document. Casting the string to a XML document and work on it as a XMLList prevents me from getting the first element in the XMLList as long as the element doesn't contain a child! That simply must be a bug.



I admit it is not the largest bug in the world, but the consequence of a bug like this seems larger than I first thought.

As the xml and ui components both are a part of the platform, the solution seems to be an upgrade of the flashplayer as Adobe fixes the bug. Upgrading the flashplayer is something the enduser as to do.



As I am working on a internal flash/flex application that has to run in a closed environment, where ugrades of the flashplayer are something that is out of the hands of the enduser, an upgrade of the flashplayer may not be a trivial process.



A "watercooler talk" led to a interesting suggestion to how Adobe could structure the platform to lower the impact on the end user.

What if the xml api was some kind of versioned module that your flex application dependend on?

Then you (as a developer) just had to change your internal dependencies as bugfixes and new features was available.

Adobe could have something like a centralized repository existing of original (signed) modules.



The local machine running the flex application could have some local repository for downloaded dependencies. Each dependency could be resolved at runtime and downloaded as needed.

That would lower the time it takes for adobe to release a bugfix, as it doesn't involve a complete new flashplayer release and the issue where endusers doesn't have the privilege to upgrade a plugin is gone as well.



If the idea looks like the java/maven dependency architecture it's not a coincidence :-) Maybe flex /flash could learn from the java world in this case.

<?xml version="1.0"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" initialize="init()">

<mx:Script>

<![CDATA[

import mx.controls.Alert;

import mx.events.*;

import flash.events.*;



private var work:String = "<tmps><tmp att=\"abc\"><dummy/></tmp></tmps>";

private var wontWork:String = "<tmps><tmp att=\"abc\" /></tmps>";



private function init() : void {

result.text = work;

}



private function clickHandler(event:ItemClickEvent):void {

if (event.label == "OK") {

result.text = work;

} else {

result.text = wontWork;

}

}



private function printResult(event:MouseEvent):void {

var list :XMLList = XML(result.text).tmp;

Alert.show(list[0]); // should print first element in the list - the tmp element

}

]]>

</mx:Script>

<mx:Panel title="Flex bug example" height="100%" width="100%">

<mx:ButtonBar itemClick="clickHandler(event);">

<mx:dataProvider>

<mx:Array>

<mx:String>OK</mx:String>

<mx:String>not OK</mx:String>

</mx:Array>

</mx:dataProvider>

</mx:ButtonBar>

<mx:TextArea id="result" editable="false" height="100" width="100%"/>

<mx:Button id="evaluate" label="evaluate result" click="printResult(event)"/>

</mx:Panel>

</mx:Application>

December 17, 2007

Java Application Server PE

If you are trying to use the Flex Data Services Project Template with the Java Application Server PE you might get the following error.

Error: java.security.AccessControlException: access denied (java.lang.RuntimePermission createClassLoader)
Cause: the default settings of the SUN server policy settings does not allow classloaders within webapplications.


Solution: Simply replace the policy file with one that contains the following grant entry:

edit: C:\Sun\AppServer\domains\domain1\config\server.policy

add: This towards the bottom of the policy file.

grant {
// Allow everything for now
permission java.security.AllPermission;
};

Using FDS with Java 5

I found this little tidbit of information tucked away in my documents folder and I figured I might as well share it.

While attending the flex data services course, we were told that both Flex Builder and FDS2 are 100% compatible with Java 5, even though they both ship with the 1.4.xx JRE. Now I'm still looking to wildly expand my Java knowledge, and every book out there is Java 1.5, not to mention certain tools like the Hibernate code generators for Eclipse, optimize their code for Java 5... so I went home that night and decided I was going to make it happen.

First off, I like my Java folder to be close at hand, so I installed the Java 5 jdk first, disabling the automatic installation of the JRE, because the install seemingly won't let me change the install folder of the JRE. Then I installed the JRE seperately. In the end they were located in C:\Java\JDK.. and C:\Java\JRE... respectively.

Then moving on to Flex Data Services (integrated with JRUN edition). In FDS2 I opened the jvm.config file in C:\fds2\jrun4\bin and changed the line java.home=C:/fds2/UninstallerData/jre to java.home=C:/Java/jdk1.5.0_07. I also moved the JRE in uninstallerdata to my desktop to make sure it wasn't being used. I then started FDS2 and it started up fine. (NOTE: originally I pointed it to the JRE, but loading my test .JSP page would fail because it couldn't find com/sun/tools/javac/Main).

Incidentally I also added the JAVA_HOME environment variable to my XP machine and pointed it to the JDK. This takes care of Flex Builder and the Flex SDK as well. (I tested this further in fds and it appears that the jvm.config setting overrides the java_home variable - so if you want to use the java_home for fds2, blank out the value in the jvm.config).

Finally, when you start up the Adobe Flex 2 Command Prompt, it tells you what version of Java it's using. I haven't had any issues at all since upgrading to Java 5. Looks like the instructor was right after all.

Related Flex Tutorials