Using JSF and Flex Components Together
So far I have shown you how to use charting components that ship with Fiji. Obviously you might want to use other, existing Flex components or maybe even build your own. To use any other Flex components, we use the universal wrapper or <fiji:swf> component.
We will use one of the charts provided by amCharts.com.
Note: We can use their charts for free. The only limitation is that a small URL will appear pointing to their Web site. I don't think it's such a limitation for such nice charts.
The SWF file for the chart as well as chart data are included in the template under web/ampie directory. You can also download them from here:
SWF file – ampie.swf <link>
Settings file – ampie_settings.xml <link>
Data file – ampie_data.xml <link>
The page looks like this:
<fiji:swf src="/ampie/ampie.swf" bgcolor="#FFFFFF" width="420" height="300">
<f:param name="path" value="/ampie" />
<f:param
name="settings_file"
value="#{facesContext.externalContext.requestContextPath}/ampie/ampie_settings.xml" />
<f:param
name="data_file"
value="#{facesContext.externalContext.requestContextPath}/ampie/ampie_data.xml" />
<f:param name="preloader_color" value="#999999" />
</fiji:swf>
Using the src attribute of <fiji:swf>, we point to a Flash component. The Flash component can also be loaded as a resource by using src=“resource:///file.swf”. This particular Flash component (ampie.swf) requires some data. The data is being passed using the standard JSF attribute, <f:param>. When a Flash object is rendered on a page, it has a special flashVars attribute that provides arguments to the Flash module. In our case, the <f:param> tags with their information are rendered as flashVar arguments to the Flash component. This is how the charts gets its data.
Running the page will produce the following:

In case you need to update the data for the chart, one possible way is to rerender the Flash component using the standard RichFaces approach.
- Login or register to post comments
- 55116 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