Java Development News:

The JSF Flex Project

By Ji Hoon Kim

01 Sep 2008 | TheServerSide.com

The goal of JavaServer Faces Flex is to provide users capability in creating Flex components as normal JavaServer Faces components. So users would create the components as normal JSF components and the project will create the necessary SWC, SWF, and other components, and link the values of the components back to the managed beans using JSON+JavaScript and ActionScript. By doing so, developers who are unfamiliar with Adobe Flex can be completely abstracted from its technology and focus in linking the application's data to legacy information. This article will provide a quick overview of the project, a brief introduction of the technical info regarding its design, and how to build the SNAPSHOT artifacts by downloading the source code to the local machine. Please note that the project is in its infancy state, so it is probable that it will undergo transformation in the future.

JSF Flex example

JSF Flex Lifecyle

The project itself will piggy back on JSF's lifecycle with one main difference being that there will exists an interlude step called buildComponentInterlude between buildComponentBegin and buildComponentChildren.

encodeBegin: buildComponentBegin buildComponentInterlude

encodeChildren: buildComponentChildren

encodeEnd: buildComponentEnd

The following image shows a brief overview of some of the steps taken during the various application modes [debugMode, simplySWF, and productionEnv].

Brief overview of JSF Flex Lifecycle

One thing to note is that buildComponentEnd II process occurs only once per application, since the existence of system resources are checked prior to creating them. Also each application is allowed various modes fit for different purposes.

  • debugMode : preMxml, Mxml, and SWF files would be created in each run as well as JSON objects.
  • simplySWF : Mxml which has been modified by the user exists, so create only SWF files and JSON objects [users can use this to modify the mxml file and create a swf file].
  • productionEnv : SWF file already exists, so nothing to do here but create JSON objects [this is the default value to ensure that users do not run the components in either of the two other modes in an environment that is higher than dev]. One thing to note is that all directories of Webcontent/swf/* should be copied to their corresponding directory within the Workspace during the move to higher environment, since the system uses servContext.getRealPath(new String()) as the root directory of preMxml, Mxml, and swf directory and Tomcat for example flushes it out to their cache directory under metadata.

JSF Flex Framework

In order to separate the core framework with its implementations, JSF Flex has componentized much of its code into several maven projects that will be linked during build time and its implementations created during runtime. This will allow users to choose their preferred implementation during build time by providing a specific profile id or providing none for the default implementations.

During build time, decision will made of which _RunnerFactory implementation the project should instantiate during runtime [default being DefaultRunnerFactoryImpl] and this implementation will dictate which implementation of _CommonTaskRunner, _FileManipulatorTaskRunner, and _FlexTaskRunner the system should instantiate during runtime. Furthermore, the decision of which implementation of _AnnotationDocletParser to instantiate during run time for specific JRE version will be made during the build time. More details regarding the above process is shown below, which provides a brief overview of each maven project.

JSF Flex Maven Projects
  • jsf-flex-build-plugIn -- A plug-in project that utilizes qdox open source project to inspect the java file’s documentations in order to generate replaceMapping XML for jsf-flex-framework/component14 project.
  • jsf-flex/core -- Contains code pertinent to JSF components. Since the project uses myfaces plug-in, tld, faces_config.xml, tagClass, and etcetera are created during build time.
  • jsf-flex/examples -- A WAR project containing sample jsf pages for the project.
  • jsf-flex-shared -- A project containing shared resource for jsf-flex and jsf-flex-framework sub-projects. Its main reason of existence is to avoid cyclic dependency between the two projects by providing shared interfaces.
  • jsf-flex-framework/core -- Contains the core code that is used by jsf-flex-framework/component14 and jsf-flex-framework/component15 projects.
  • jsf-flex-framework/runnerImpl/ commonTaskRunnerImpl -- Contains projects that implement the _CommonTaskRunner interface used by jsf-flex-framework/core [i.e. sdkStandardCommonTaskRunnerImpl project]
  • jsf-flex-framework/runnerImpl/ fileManipulatorTaskRunnerImpl -- Contains projects that extends the _FileManipulatorTaskRunner abstract class used by jsf-flex-framework/core [i.e. velocityFileManipulatorTaskRunnerImpl project]
  • jsf-flex-framework/runnerImpl/ flexTaskRunnerImpl -- Contains projects that implement the _FlexTaskRunner interface used by jsf-flex-framework/core [i.e. antFlexTaskRunnerImpl project]
  • jsf-flex-framework/component14 [JRE < 5] -- For component14, during the build time documentation for java files will be inspected by the JSF Flex plug-in and will generate replaceMapping XML files that will be parsed to check which fields to inspect and how to fetch these fields from the JSF component [by attribute map or by method invocation]. Contains an implementation of _AnnotationDocletParser interface used by jsf-flex-framework/core for fetching the fields from the JSF component [AnnotationDocletParser14Impl].
  • jsf-flex-framework/component15 [JRE >= 5] -- Since these components are suppose to be used for JRE >= 5, the attributes will be fetched during runtime through Java annotation and will not require JSF Flex plug-in during build time. Contains an implementation of _AnnotationDocletParser interface used by jsf-flex-framework/core for fetching the fields from the JSF component [AnnotationDocletParser15Impl].

JSF Flex Building SNAPSHOT artifacts

Here I’ll present a brief overview of building snapshot artifacts of JSF Flex.

Checking out/Extracting the resources from the repository

Check out/extract the resources from http://jsf-flex.googlecode.com/svn/trunk/ to a folder within the local system [i.e. C:jsfFlexProject] by using the SVN tool.

Importing the project into Eclipse IDE
  1. In the folder where the resources were checked out to, run the following command to enable importing of the projects into an Eclipse IDE [project requires maven for building] :

mvn -D wtpversion=<WTP Version of local Eclipse> eclipse:eclipse

  1. Then run mvn install within the resource directory [i.e. C:jsfFlexProject]. This should be enough to import the projects into Eclipse IDE.
  2. Create a new workspace and navigate to File => Import => Existing Projects into Workspace.
  3. Select the folder where the resources were checked out to [i.e. C:jsfFlexProject].
  4. Finally add the "M2_REPO" Classpath variable within the workspace:
    1. Navigate to Window => Preferences => Java => Build Path => Classpath Variables
    2. M2_REPO as variable and value as the maven2 repository [for me it was "C:/Documents and Settings/Administrator/.m2/repository"]

Projects to import

Conclusion

With the Web 2.0 technology flourishing within the web world, JSF Flex allows bridging of these two technologies which excel in their own area, Flex in creating a Rich Internet Application and Java in maintaining a robust code on the server side.

Specifically the project will provide:

  1. Easy creation of Flex applications while preserving the ease of databinding to legacy systems through JSF.
  2. An alternative to purchasing FlexBuilder when creating simple Flex applications.
  3. Complete abstraction of Flex technology.

Resources

Further details and the source code: http://code.google.com/p/jsf-flex/

Project member’s main discussion list: http://groups.google.com/group/jsf-flex/

About the Author

Ji Hoon Kim is a Software Engineer within IBM.

Related Content

Related Resources