Preparing PrimeFaces

PrimeFaces is a suite of components built on top of JSF 2.x, giving you lots of first-class widgets to use on a Rich Internet Application (RIA) solution, such as charts and mind maps. Its only requirement is to choose between Oracle Mojarra and Apache MyFaces, both JSF 2.0 implementations, and to reference the chosen one. The current implementation version at the time of writing is 3.5.

Tip

Oracle WebLogic Server 12c comes with a JSF 2.0 implementation (Oracle Mojarra) enabled at its classpath, so we don't need to download anything but PrimeFaces.

Downloading the binaries

To use PrimeFaces, we must download it from http://www.primefaces.org/downloads.html. You can choose between Binary, Source, and Bundle packages.

Tip

To follow the book, getting the binaries is enough, but if you plan to use PrimeFaces for real work, the Bundle option would be a good idea, since it includes the binaries, source code, API Javadocs, and taglib documentation.

The official documentation is a PDF available at http://www.primefaces.org/documentation.html with details on every component of the framework. And the most valuable source of information is the ShowCase page, with samples and working code for every component, available at http://www.primefaces.org/showcase/ui/.

PrimeFaces can be configured with JQuery's ThemeRoller (http://jqueryui.com/themeroller/), and there are lots of predefined themes available at http://primefaces.org/themes.html. You can also access the showcase mentioned previously and see how the themes feel like by selecting different names from the top left drop-down box.

Theme packages can be downloaded from http://repository.primefaces.org/org/primefaces/themes/. Grab the themes that appeal to you by clicking on the folder with the same name, then clicking again on the highest version number and selecting the file with extension .jar.

Note

Download at least one theme; we're going to use it in the next section to compose a shared library—ui-lightness is the authors' choice.

Creating a shared library

Shared libraries are a handy way to make different types of resources available between applications deployed on the same domain, avoiding the need to add them inside each application package or to change the classpath (and the unavoidable restart to make the new libraries available).

There is another way to share libraries called optional packages, where you can deploy a single plain JAR file as a library, and reference it from your application. The main difference between the two concepts is that a shared library can be a Java EE module (have a few EJBs, for instance), and an optional package is a standard Java library that can be shared by many applications without having to put the library inside the deployment package or adding it to the server's classpath.

Tip

As we're going to use PrimeFaces and at least one theme package, the more sensible way to go is to construct a shared library.

For a full list of available modules, the differences between shared libraries and optional packages, and detailed specs on how to build and reference them, refer to http://docs.oracle.com/middleware/1212/wls/WLPRG/libraries.htm.

Note

We're going to use /opt/packt/etc as the base folder to keep files that do not directly relate to installation procedures or the development workspace.

The following steps show how to create the shared library:

  1. Create a folder to hold the contents of the library and a few subdirectories:
    cd /opt/packt/etc
    mkdir ./primeSL
    cd primeSL
    mkdir ./META-INF
    mkdir ./WEB-INF
    mkdir ./WEB-INF/lib
    
  2. Copy the JAR files downloaded in the previous section—primefaces-3.5.jar, ui-lightness-1.0.10.jar and any other themes you chose—to the lib folder.
  3. Create a file named MANIFEST.MF inside META-INF with the following content:
    Manifest-Version: 1.0
    Extension-Name: primefaces
    Specification-Version: 3.5
    Implementation-Version: 3.5
  4. Compress the contents of /opt/packt/etc/primeSL into a file named primefacesSL.war:
    cd /opt/packt/etc/primeSL
    zip -r primeSL.war */*
    

    Note

    Make sure that folders META-INF and WEB-INF are at the highest level of the WAR file.

  5. The shared library is ready to be deployed.

Now that we have the assembled package, here's some insight about the MANIFEST.MF file we just created:

  • The extension-name attribute is the name that we're going to use to reference the shared library at our projects
  • The specification-version attribute is used to indicate which version this library exposes
  • Finally, entry implementation-version is related to package versioning, so the developer can pin to a specific build version, if necessary

Tip

Usually, this last entry is not declared, you only need to stick to a spec version. If a new release of PrimeFaces, let's say version 3.5.1, is made available, and we only declared specification-version, there's no need to update MANIFEST.MF.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.106.33