2. A simple RIFE application

The center of every RIFE application is the repository. It keeps the different parts of the application together, such as configuration data, site users, data sources, etc. These parts are called participants.

The repository is available from anywhere in the application and offers a convenient way to initialize and access application-wide resources.

In the simple Hello World example, the repository file is located in ~/tutorial/jetty-{version}/webapps/01_helloworld/WEB-INF/classes/rep/participants.xml. From now on, we will skip the leading directories in the text, so, for example, this file will be referred to as rep/participants.xml.

Example 2.1. The participants file for Hello World

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE rep SYSTEM "/dtd/rep.dtd">

  <participant param="sites/helloworld.xml">ParticipantSite</participant>

Since this is a very simple example, we only have one participant, which is the site itself. As specified with the param attribute, the site file is found in sites/helloworld.xml. A real life application would most likely contain more participants.

A site is made up of elements, which are the smallest logical building blocks in the application. Elements are linked together to form a flow through the web site.

You can think of this as electronic components that need to be wired together before they become useful. An electronic component has no use by itself, but when it's combined with others, the most amazing products can be created.

It's also possible to use the same components but with different contact points wired together or in a different order. This will cause the functionality to dramatically change without the necessity to pull components apart or build new ones.

More even, when your product evolves you might need to include new components in between existing wires. It's not a big task to just remove the existing wire and put the new component in between. The rest of your product continues to function without you being bothered about it.

A RIFE element corresponds to the electronic component and the flow corresponds to the wiring. You can take any element from any application and just include it in the flow of another application (rewiring).

Each element can have input and output variables. These can be connected and data will be passed around when the links between them are followed.

If we take a look at the site structure defined in sites/helloworld.xml, we can see that it contains only one element called HELLOWORLD and that it's mapped to the URL /home.

Example 2.2. Site file for Hello World

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE site SYSTEM "/dtd/site.dtd">

  <element id="HELLOWORLD" implementation="tutorial.helloworld.HelloWorld" url="home"/>

Since our first example only has one element, there are no inputs or outputs, and no links. Therefore, the entire element has been declared in-line. When you want to create reusable elements, you'll probably want to declare them in their own XML file. We'll talk about those features in more detail in the next example.

The important thing to notice here is the implementation attribute of the element tag. The implementation of the element can be either a Java class file or a Java source file, which is then compiled on the fly if needed, or a supported Java scripting language, like Jython.

Our implementation of the element is a Java class, that just outputs a greeting. It is implemented in HelloWorld.java

Example 2.3. The Java element of Hello World

import com.uwyn.rife.engine.Element;

public class HelloWorld extends Element
  public void processElement()
    Template template = getHtmlTemplate("tutorial.helloworld");
    template.setValue("hello", "Hello world.");

Element implementations must extend the com.uwyn.rife.engine.Element class and implement the processElement() method. As you can see, this element will use a template and output "Hello world.". We will talk more about templates alter in the tutorial.