Using JSF and Flex Components Together
Exadel Fiji extends JavaServer Faces (JSF) by allowing the use of Flex components within a JSF page. Fiji stands for “Flex and JSF Integration.” When using Fiji components, developers use Flex with the same component-based approach to building user interfaces that they are familiar with from JSF. This means that Flex components are bound to standard JSF managed beans.
Fiji is a framework that provides the following:
- A library of ready-to-use Flex charting components for JSF
- A universal wrapper that allows the use of any Flex component within a JSF page
- Most importantly, with Fiji, you can bind Flex components to the same JSF-managed beans properties or methods (or Seam components or Spring beans) used by the rest of your JSF application.
The current version ships with the following ready-to-use charts:
- Column chart
- Stacked column chart
- Bar chart
- Stacked bar chart
- Line chart
For example, here is a screen shot of a Flex component inside a JSF page

You can see all Fiji components in action at http://livedemo.exadel.com/fiji-demo
Now that I have given you a short introduction to Fiji, you are probably wondering what problem Fiji is trying to solve. Let's see.
Why Fiji?
Let's start with the basics. JavaServer Faces (JSF) is a standard (Java EE) framework for building Web user interfaces out of components. Today, we are interested in building Rich Internet Applications, so RichFaces was created takes JSF a step further by allowing the easier building of AJAX-based applications in JSF. (In case you don't know, RichFaces offers a large number of ready-to-use AJAX components.)
While JSF has been constantly growing, one area where it's still lacking is in displaying rich and interactive charts, graphs, and other similar visuals. Even with AJAX, any serious charting is extremely difficult, not to mention the testing that would be required for different browsers. It really comes down to two things. First, the technologies used behind JSF such as HTML, JavaScript, and CSS are not meant for displaying rich and interactive visual data (possible, but very difficult). Second, people have much higher expectations from a browser. The browser alone was never meant to display such visual data. It was primarily meant to display text and static images. So, in the end, it's not really JSF’s fault, we are simply asking the underlying technologies (HTML, JavaScript, CSS, the browser) to do too much.
Of course, there is hope. We can use a Flash player to display rich and interactive charts.
Adobe Flash
With Flex, complex rich applications can be compiled and then run inside a Flash player. A Flash player is a virtual machine that installs as a plug-in into any browser. Because the application (built with Flex) is running inside a virtual machine, it provides a far more superior environment for rich and interactive charts and graphs than the browser alone (which just interprets HTML, JavaScript, etc.).
The obvious next question is: So, why not use Flex and JSF components together right now? While it's possible to use Flex and JSF components inside the same page, the two technologies are not aware of each other. This means that JSF components are bound to JSF managed beans (or Seam components or Spring beans) while Flex is bound to completely different objects. This kind of integration is equivalent to inserting an image into a JSF page – in other words, not much integration.
Back to Fiji
This is a good place to revisit Fiji. Fiji is the perfect fit for helping with the above problem. Not only does Fiji provide ready-to-use chart components and a universal wrapper to use any Flex component, but, with Fiji, you can bind Flex components to standard JSF managed beans. As a JSF developer, you just use the standard and the familiar JSF component-centric approach, while now also being able to use Flex components.
So, where does it make sense to use Fiji. One scenario is if you have an existing JSF application and you would like to insert richer content based on Flash while still using your existing model (JSF managed beans, Seam components or Spring beans). This content can be charts, graphs or any other rich content.
Another situation where Fiji would make sense is where you have an existing JSF application, but want to use a Flash-based user interface (instead of HTML/JavaScript). By using Fiji, you can still use the existing model part of your application.
However, to be honest, it wouldn't make sense to use Fiji if you have an existing Flash-only application and are using a service like GraniteDS, BlazeDS, or Exadel Flamingo.
Now, I think we are ready for examples.
- Login or register to post comments
- 55426 reads
- Printer-friendly version
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)











Comments
themathmagician replied on Mon, 2009/02/02 - 8:19pm
I have tried to follow the tutorial, and make Fiji work with Seam and Flex.
I have tried several approaches:
1) Followed the tutorial here:
Result - server crash from the helloworld on page 3 :-(
2) I tried to follow the tutorials advice that fiji is just a rich faces project - just copied the 2 files fiji-api.jar and fiji-ui.jar into the lib
folder of my HelloWorld Seam project, and added the following facelet:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:rich="http://richfaces.org/rich"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:fiji="http://exadel.com/fiji">
<rich:panel>
<f:facet name="header">
Fiji
</f:facet>
Ready for Fiji...
<fiji:swf src="hello.swf" width="400" height="400"
bgcolor="#EFEFEF"
application="HelloWorld"/>
</rich:panel>
</ui:composition>
The hello.swf file liest in the same folder as the facelet file.
This didn't crash the server. But the result is not what I wanted - no
Flash component.
Any ideas what I do wrong?
Best,
Agata
maxkatz replied on Tue, 2009/02/03 - 12:53pm
maxkatz replied on Tue, 2009/02/03 - 12:54pm
jgreene replied on Tue, 2009/03/03 - 12:47pm
Max -
You give little guidance on how to update an amChart wrapped inside a fiji:swf component. Looking at the amCharts docs, it looks like the data wants to be either csv or xml format. If I want to use an am line chart wrapped in the fiji:swf component, I need to know how to bind the chart data to a bean instead of xml or csv data. Can this be done? If not, I think this is important and should be stated.
maxkatz replied on Mon, 2009/03/09 - 12:39pm
in response to: jgreene