Version 28

    Getting Started with the JBoss Ajax4jsf CDK

     

    Configuring the Environment

     

    Install and configure the Maven how it is shown at Ajax4jsf. Maven Repository Configuration

     

    Project Structure

     

    The environment is now set up to use the CDK. Let's use it to make a dummy component for a quick test of the CDK to make sure everything is in place. To do this, we will create a project, a component library within this project, and then a component within this component library. Finally, we'll build the component library.

     

    Set Up the Project

     

    • Create a new directory

    • Create a file named pom.xml in the directory with the following content:

     

    <?xml version="1.0" encoding="UTF-8"?>
    <project 
          xmlns="http://maven.apache.org/POM/4.0.0" 
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
       <modelVersion>4.0.0</modelVersion>
       <groupId>org.mycompany</groupId>
       <artifactId>mylib-parent</artifactId>
       <url>http://mycompany.org</url>
       <version>1.0-SNAPSHOT</version>
       <packaging>pom</packaging>
       <dependencies>
          <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
             <version>3.8.1</version>
             <scope>test</scope>
          </dependency>
          <dependency>
             <groupId>javax.servlet</groupId>
             <artifactId>servlet-api</artifactId>
             <version>2.4</version>
             <scope>provided</scope>
          </dependency>
          <dependency>
             <groupId>javax.servlet</groupId>
             <artifactId>jsp-api</artifactId>
             <version>2.0</version>
             <scope>provided</scope>
          </dependency>
          <dependency>
         <groupId>org.richfaces.ui</groupId>
         <artifactId>richfaces-ui</artifactId>
         <version>3.1.0</version>
          </dependency>
       </dependencies>
    </project>

     

    Here is what some of these elements are used for:

     

    groupId

    Prefix for the Java package structure of your library

    url

    Name space for your library to be used in the TLD file

    version

    Version of your library

     

    Set Up the Component Library

     

    • In the project directory you just created, launch the following command (all in one line):

     

    mvn archetype:create -DarchetypeGroupId=org.richfaces.cdk -DarchetypeArtifactId=maven-archetype-jsf-component  -DarchetypeVersion=3.1.2.GA -DartifactId=mylib

     

    A new directory with the name mylib will be created. It does not have any components in it yet, but it has this predefined structure:

     

    src/main/config

    Contains the metadata for the components

    src/main/java

    Contains Java code (both pre-generated and created by you)

    src/main/resources

    Used to store resource files, such as pictures, JavaScript, and CSS files

    src/main/templates

    Will contain the JSP-like templates that define the component layout

     

    Set Up the Component

     

    • Go to the mylib directory

    • Launch the following command:

     

    mvn cdk:create -Dname=panel

     

    This command creates a skeleton for a new component called panel. Three artifacts will be created:

     

    • An XML configuration file for the metadata

    • A UI class

    • A JSP-like template

     

    Build the Component Library

     

    • Staying in the mylib directory, launch the following command:

     

    mvn install

     

    This command generates and compiles the library and then creates a result JAR file. A directory named target will be created along with a src directory. If you get a file named target/mylib-1.0-SNAPSHOT.jar as a result of mvn install, everything is set up OK. From here, you can start to create real components.

     

    More About...