ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

Introducing [fleXive] - A Complementary Approach to Java EE 5 Web Development
Pages: 1, 2, 3, 4

Getting Started with [fleXive]

The prerequisites to get started with [fleXive] are minimal: you need a Java 5 SDK (Java 6 if you want to use JSR-223 scripting), Apache Ant 1.7 or higher, a MySQL 5.x database, and a Java EE 5 Application Server (currently JBoss 4.2.2 GA and Glassfish v2 are fully supported with some experimental support for Geronimo 2.1)

Detailed information about setting up MySQL and configuring your application server of choice can be found in the installation chapter of the reference documentation.

After downloading and unzipping the [fleXive] binary distribution -- we recommend using the current development build until the final release is available -- you will find the following directory layout:

|-- build.xml
|-- database.properties
|-- applications/
|-- extlib/
|-- lib/
|-- templates/

The applications folder contains all [fleXive] applications that should be included in the enterprise archive (EAR) file. The standard distribution includes the backend administration application in this directory. To remove an application from the EAR, simply remove it from this directory and rebuild the EAR file.

Third-party library files required for compiling and running [fleXive]-based applications are stored in the extlib folder, while all [fleXive] libraries are contained in the lib folder.

The next step is to adapt the database.properties file to your needs (host, port, username, and password) and create the database schema by executing the following line at the command prompt:

ant db.create db.config.create

You will be prompted to enter a name for your division database (simply hit enter to keep flexive).

To create a new project, you need to call the ant target project.create. Doing so will create a project folder (the name of the project will be asked when invoking the ant task) in the same directory where the [fleXive] distribution is stored, i.e., the current parent directory. For the example in the next section we created a project named products.

To learn more about available Ant targets and creating [fleXive] application skeletons, please have a look at the getting started section of the reference documentation.

Let's Write Code

To demonstrate some of [fleXive]'s core features, we create a small application that manages products and their manufacturers. The data input will be done in the generic backend application, the custom front-end application will be written in JSF.

Start off by creating a new application with

ant project.create

Use "products" for the name. Change to the newly created directory:

cd ../products

The directory structure of the application is as follows:

    |-- lib
    |-- resources
    |   |-- META-INF
    |   |-- messages
    |   |-- scripts
    |   |   |-- library
    |   |   |-- runonce
    |   |   `-- startup
    |   `-- templates
    |-- src
    |   `-- java
    |       |-- ejb
    |       |-- shared
    |       `-- war
    `-- web
        `-- index.xhtml

The [fleXive] build system automatically recognizes resources and code dropped in these directories: for example, if you add classes to src/java/ejb, an EJB jar will be generated and added to your application. If you place localized messages in resources/messages, these will be available through [fleXive] message beans, and so on.

Now we're set for development, but first we have to think about the data model:

  • Products have a name, a multilingual description, a price, a manufacturer, and possibly some product images. A product exists in different color variants, each with a unique article number.
  • A manufacturer has a name, a multilingual description, a company logo, and a home country.

There are several ways to create our types in [fleXive]:

  • using the backend web-based GUI
  • using the Java APIs of [fleXive]
  • using a Groovy builder

For the sake of simplicity, we choose Groovy to create our data types. The first argument to the GroovyTypeBuilder is the type name. The body includes all properties to be created for the type. The following listing shows the creation of the manufacturer data model, including test data generation:

import ...
// get countries select list
final FxSelectList countries =

// create product manufacturer type
new GroovyTypeBuilder().manufacturer(description:
    new FxString("Manufacturer")) {
    name        (assignment: "ROOT/CAPTION",
                 description: new FxString(FxLanguage.ENGLISH,
    description (dataType: FxDataType.HTML,
                 multilang: true,
                 description: new FxString(FxLanguage.ENGLISH,
    logo        (dataType: FxDataType.Binary,
                 description: new FxString(FxLanguage.ENGLISH,
                                "Company Logo"))
    basedIn     (dataType: FxDataType.SelectOne,
                 referencedList: countries,
                 description: new FxString(FxLanguage.ENGLISH,
                                "Based in"))

// create test data
GroovyContentBuilder builder =
    new GroovyContentBuilder("manufacturer")
builder {
    name("Police Inc.")
    basedIn(new FxSelectOne(false,
    description(new FxHTML(FxLanguage.ENGLISH,
        "A global distributor of police-related accessoires.")
        "Ein weltweiter Distributor von Polizei-Accessoires."))

builder = new GroovyContentBuilder("manufacturer")
builder {
    basedIn(new FxSelectOne(false,
    description(new FxHTML(FxLanguage.ENGLISH,
        "Love is Amor's business.")
        "Liebe ist Amor's Gesch\u00E4ft."))

builder = new GroovyContentBuilder("manufacturer")
builder {
    name("Atlantic Enterprises")
    basedIn(new FxSelectOne(false,
    description(new FxHTML(FxLanguage.ENGLISH,
        "Atlantic deals with poker hardware.")
   "Atlantic ist ein Hersteller von Gl\u00FCcksspiel-Hardware."))

The script code can be executed in [fleXive]'s scripting console, located in the backend application at Administration / Scripts / Groovy console. You can see the resulting data structure in the backend's Structure tab.

Pages: 1, 2, 3, 4

Next Pagearrow