This document is designed to get you up and
running with Barracuda fast. It tries to address the most commonly asked
questions raised by users.
Q: What is Barracuda?
A: Barracuda is an Open-Source Presentation Framework designed to make
it easier to build web apps. There are 4 ways we are focusing on doing this:
- by creating a Server-Side Component Model that makes it easy to manipulate DOM
structures using proven MVC patterns
like you'd find in Swing
- by providing a Form Mapping & Validation package to automatically map forms to
objects and validate them
- by supporting Model 2 Flow
Control handling with a sophisticated Server-Side Event Model
- by making it really easy to deal with Localization issues
Once these initial pieces are in place, phase 2 will focus on:
- creating a Javascript Component Library to make it easier to do client side validation
- developing an "Application Wizard" utility that will make it easy to build
applications using the Event Model framework
Q: What is the Component Model?
A: Ok, so what is a component model, and why do I need one? Good
questions; we'll try to explain.
Any webapp component model generally allows you to do two basic things: first, you can
assemble complex components out of simpler ones; second, when you render the root
component all its children will be rendered as well.
The Barracuda component model goes further and provides strongly typed MVC interfaces
like you'd find in Swing. This means that instead of extending the component every time
you want to use it, you simply implement the component's Model interface. The component
takes data from the model and places it into the view.
Unlike Swing (which only defines the Model interfaces), Barracuda components also
define View interfaces. In most cases a view will correspond to some element in a DOM
structure (sometimes called "binding" a component to a DOM node). This allows
the component to take the data from the model and insert it into the DOM structure for
you. This means developers no longer have to manipulate DOM structures by using the DOM
interfaces (tedious). Instead, you manipulate components and the components take care of
all the dirty work.
Here's how it all fits together. In the past, developers could compile HTML pages into
DOM objects by using XMLC 2.2+. This made it possible to
dynamically insert data into a web page using convenience methods provided by XMLC
generated classes. While this worked well for simple data fields, it was still too
cumbersome for populating complex structures like lists and tables, because developers had
to manipulate the *ML using low-level DOM interfaces.
The Barracuda component model gives you the ability to bind a component to a node in
any DOM structure. When the component needs to render itself, it queries the model and
automatically inserts the data into the DOM structure for you. This makes it very easy to
populate complex structures (lists, tables) in any DOM structure.
In addition, certain Barracude components (BAction, BLink, BSelect, BInput, and
BToggleButton) are capable of generating events on the client side. These components
allow you to add server side listeners directly to the components (just like you would in
Swing). When the action occurs on the client, your event handler code on the server is
notified. This is the only real tie between the component model and the event model
portions of Barracuda.
One of the easiest ways to get started with components is by using the BTemplate
component. This component populates the DOM by looking for tagged values in the template
and queries the model based on key name, rather than model position. This means all a
developer has to do is provide data for various keys; all the designer has to do is refer
to the data by key name -- the component will substitute accordingly. This makes it very
easy to restructure the *ML document without requiring the developer to make changes to
the component or the model.
For details on how to use the Component Model, refer to the Component Model - 30,000 Ft Overview, the Component Model Tutorial and the Barracuda Config Tutorial.
Q: What is the Forms Mapping &
Validation package?
A: The Forms Mapping & Validation package is designed to make it
easier to work with HTML forms by allowing you to specify which elements a form should
contain and how they should be mapped and validated.
When you receive an HttpServletRequest, you simply say "given the form
specifications I have defined, map/validate this request". Once the form has been
mapped, you can easily access elements in the form as first class Java object (ie. String,
Boolean, etc). If an element in the form is not valid, you'll be notified of the
error. The form mapping and validation framework does most of the dirty work for you.
For details on how to use the Forms Mapping & Validation package, refer to the Forms Model - 30,000 Ft Overview and the Forms Model Tutorial.
Q: What is the Event Model?
A: The Barracuda Event Model is designed to make it easier to build
and administer complex web applications by using events in conjuction with a Model 2 dispatching paradigm.
With simple applications, it is often sufficient to implement screens as simple Servlets;
as application complexity grows, however, events become a valuable mechanism for managing
your web application.
From the simplest perspective, the Event Model simply intercepts HTTP Requests,
converts them to actual event objects, and then dispatches them to all interested
listeners in the system. There are two kinds of events in the system: Control Events and
View Events.
Control Events indicate you want to do something--perhaps get a certain screen or
update a form. View events, on the other hand, are actually responsible for ensuring that
the correct screen gets sent back to the client. In the Model 2 paradigm, you generally
handle control events and then redirect to the appropriate view. This is very easy in the
Barracuda Event Model because one event (spawned by the HTTP Request) can actually
generate many additional events.
This one-to-many relationship makes it possible to intercept events before they
actually get handled to make sure that the action is permissable. For instance, if I
define an event called TransferFunds.event, I probably want to be sure that you have
logged into the system before actually allowing the event handlers to process the event.
With the Barracuda event model, this process is very easy: I can install security or
logging mechanisms over various portions of the event hierarchy without ever touching the
actual event handler code for given events. This keeps the system loosely coupled and
highly cohesive (where event handlers each do one thing and do it well).
Of course this flexibility requires some additional effort on the part of the
developer: you must carefully define the event hierarchy up front and specify which
screens are capable of handling events. The process is straightforward, however, and well
documented. For enterprise caliber system, the reward is well worth it.
For details on how to use the Event Model, refer to the Event Model - 30,000 Ft Overview and the Event Model Tutorial.
Q: What about Localization?
A: The Barracuda Presentation Framework offers a number of features to
make localization easy by leveraging the value of XMLC. Barracuda provides a
custom Ant taskdef, which extends the Xmlc taskdef, that automatically localizes XMLC
templates.
For instance, let's say you have an XMLC template called Foo.html which typically gets
compile to FooHTML.class. The Barracuda Localization taskdef looks for the presence of
.properties files that contain localized text for a given template. For instance, if we
had a Foo.properties (which identifies the text to be localized) and a Foo_es.properties
(which contains the localized text in Spanish) the localization taskdef will automatically
create a FooHTML_es.class as well. This means that you can quickly localize static text in
your app simply by creating .properties file for each locale we wish to support. The
templates themselves remain untouched.
Once we have all this different localized templates, the next question is how do we
access them? Barracuda provides a DefaultDOMLoader that will load templates based on
template name plus target locale. Let's reconsider the example above. If I ask the
DOMLoader to get me the FooHTML template for the Spanish locale, it will return an
instance of FooHTML_es.class. If I request the template for the German locale, it will
return an instance of FooHTML.class, since FooHTML_de.class does not exist. The whole
system works very similarly to Java's ResourceBundle utility, and makes it very easy to
support multiple locales with very little additional coding.
Barracuda also makes it easy to determine a client's target locale and automatically
persist that information across multiple requests. For a more detailed understanding of
the localization features in Barracuda, look at the Barracuda
Config Tutorial and the HelloWorld 4 Example.
Q: What are Barracuda's dependencies?
A: One of the questions people often ask is "What other
frameworks does Barracuda depend on?". The answer is "very few".
Barracuda is designed to run in any Java Servlet 2.2+ container. The component model
requires the DOM Level 2 interfaces defined by
W3C.org (these classes are included in Xerces).
We build applications using the WAR format, since this is a highly portable standard.
Please note that while many of the included examples require XMLC 2.2+, the framework itself is built around the DOM
interfaces (you could actually use any DOM generated document, although we feel XMLC is
one of the best methods to create these ;-)
We use Apache Ant 1.5.1+ to compile
the system, along with a custom XMLC taskdef. The testing framework is based on JUnit 3.8+. Logging is provided by Log4J 1.2.8+. All of the necessary jar
files are bundled with Barracuda. (other than Xerces2 which already supplied with Ant and Tomat)
We should also note that all of the Barracuda subsystems are designed to be as loosely
coupled as possible. You can use the Forms Mapping package all by itself, if you like.
Same thing with the Component Model and the Event Model. Furthermore, Barracuda relies
heavily on interfaces, so it's entirely possible to plugin in your own implementations if
you really wish to do so.
Q: How do I actually use it?
A: Using Barracuda is simple -- simply place barracuda.jar in your classpath. If you are building
applications using the Servlet WAR format, this is most easily accomplished by adding the
jar to your /WEB-INF/lib directory, or by placing it in your JDK's
/ext directory. If you are using an IDE, you'll need to add the jar file to your
project classpath as well so that the compiler can find the Barracuda classes.
If you have downloaded the whole Barracuda Project (either from cvs or from binary
zips), you can easily run the whole thing locally--just unpack the files and then add the
project as a WAR within your local appserver. Because the Barracuda project structure
conforms to the WAR specification, it will easily run in any Servlet 2.2+ compliant
container. You can access all the Barracuda documentation, plus it comes with its own
version of Ant, so you can easily build the project from source.
Q: What's the best place to start?
A: The best place to start with Barracuda is probably with the
Component Model. To use this, you will need to use XMLC 2.2+ or some other mechanism to load *ML documents as DOMs. The simplest component to
use is the BTemplate component (see the Component Model
Tutorial).
After this, it'll be well worth your time to look at the Forms Mapping and Validation
Package (see the Forms Model Tutorial), since most web
apps end up dealing with forms.
Finally, once you are comfortable with the component model and are preparing to build
larger multi-screened applications, we'd highly recommend taking the time to learn the
Event Model (see the Event Model Tutorial); it will
make it significantly easier to build and maintain complex web apps, while giving you the
full benefits of Model 2 event dispatching and a robust event handling mechanism.
To see all of these pieces working together in fully localized splendor, see the Barracuda Config Tutorial.
Q: Is it compatible with JBuilder and other IDEs?
A: Yep! All you need to do is add barracuda.jar to
the IDE's classpath. That's it! If you use Ant to compile your source you will need to
make sure that ant_barracuda.jar is on the system classpath.
Q: How much work is still remaining?
A: Please refer to the official Todo List for
the latest details on what's remaining.
Q: How can I get involved?
A: Hey! Glad you asked! There's plenty to be done, and if you're
looking for an opportunity to contribute, we've got lots of opportunities (ranging from
easy to complex). Contact Christian or the Barracuda Mailing List for details... |