Hello World 1a - this is a very
simple example that demonstrates how to use a BTemplate component without even coding a
model. Instead, we use a properties file.
Spotting the Differences
First of all, notice that we're using the exact same template as we did in HelloWorld 1.
So, let's start by comparing the HelloWorld1a
servlet with the previous example. A quick glance will reveal that the only real
difference lies in how we are instantiating the Model. Rather than using an inner class,
we are instead instantiating a DefaultPropertiesModel.
This model takes a reference to a properties file name, in this case
org.enhydra.barracuda.tutorials.comp.HelloWorld
When the model receives a request for data, it looks for the key in the properties file
and returns the corresponding value. Pretty simple.
Now, while you probably wouldn't want to do this for data that is dynamic to every
request, it does make it easier to handle localization issues where localized static text
values are stored in a file. The primary purpose of this example is just to show you how
it can be done. |