Programmers Guide > JOT Beans
JOT Beans
JOT Bean Properties:
JOT Template tokens
obtain dynamic content from the properties of Java objects, including
J2EE and POJO classes (plain old java objects).
The framework includes JotBean
base classes that applications can extend (see
Extending JOT Beans).
Non JotBeans are transparently enveloped with the
getInstance() JotBean wrapper method.
Examples:
In the following example, the JOT.Foo token refers to the foo
property using the method getFoo(). Token JOT.Foo(bar)
invokes getFoo() with argument bar.
JOT Template: JOT.Foo and JOT.Foo(bar)
JOT Bean: public String getFoo()
JOT Bean: public String getFoo(String arg)
In the next example, property fooBarA uses two parameters.
JOT Template: JOT.FooBarA(literal1, literal2)
JOT Bean: public String getFooBarA(String arg1, String arg2)
Property fooBarB in the next example uses the
dynamic value of property fooBarC as a parameter.
JOT Template: JOT.FoobarB(bar1, JOT.FoobarC(bar2), bar3)
JOT Bean: public String getFoobarB(String b1, Object b2, String b3)
JOT Bean: public String getFoobarC(String b)
List parameters using the "[]" operator are Object array arguments.
JOT Template: JOT.Vacations([JOT.Christmas, JOT.Ramadan, JOT.NewYears])
JOT Bean: public String getVacations(Object[] dates)
Assigning Values to Properties:
A JOT Template uses assignment tokens to set property values with
the '=' operator. The next example invokes the setFoobarD()
setter method with two arguments.
JOT Template: JOT.FoobarD=(literal1, JOT.FoobarC(bar2))
JOT Bean: public String setFoobarD(String arg1, Object arg2)
If there is no matching setter method then the assignment token
creates a property with the given value. The next example sets the
Title property on the ShoppingCart object.
JOT Template: JOT.ShoppingCart.Title=(Shopping Cart for JOT.CustomerName)
JotServletBeans:
JOT Beans that implement the
JotServletBean interface (including JOT Web Components) have access
to JSP Page scope attributes, Request parameters, and Request, Session,
and Application attributes as automatic properties.
Indirect Properties:
JOT Template tokens can reference indirect properties. The following
example accesses dynamic content from the bar property of the
batz property of the foo object.
JOT.foo.batz.bar(a, b)
The next example returns the CustomerID attribute
property of the built-in session object.
JOT.Session.Attribute(CustomerID)
Since Session attributes are automatic properties,
the previous example could also be written as:
JOT.CustomerID
Implementing JOT Bean Properties:
A JotBean property is typically a getter method that returns
a String for the rendering engine. Property values can also be JotBean
components or any other type of object. In the following example, the
numeric Price property is implemented with a getPrice()
method:
JOT Template: JOT.Price
public Double getPrice()
{
return getProduct().getPrice();
}
Properties can be declared on a JOT Template and created
and initialized automatically by the framework
(see Declaring JOT Beans).
If a property is not created that way, and is itself a
JotBean, it must be prepared and registered with the current
JotServiceContext, as in this example that renders the
Price property of an Inventory JotBean:
JOT Template: JOT.Product.Price
public Inventory getProduct()
{
// prepare and register new Inventory component
return (Inventory)configureJotBean(new Inventory(selectedProductID));
}
A property can also be added to a JotBean dynamically. The following
example uses
putJotBeanProperty() to create and initialize a property named
"ContactInformation".
JOT Template: JOT.ContactInformation.HomePhone
public void prepareJotBean()
throws JotException
{
putJotBeanProperty("ContactInformation", new ContactInformation());
}
|