|
Programmers Guide > Declaring JOT Beans
Declaring JOT Beans
A basic JOT Token references a property of the
JotServletTemplateBean that loaded the template and invoked
the rendering engine. In this example fooProperty is a property
of the JotServletTemplateBean being rendered:
JOT.FooProperty
In the next example barProperty is a property of AnotherBean:
JOT.AnotherBean.BarProperty
Implicitly Named JotBeans:
When a token for an object such as AnotherBean in the above example
is encountered, the object instance is determined by one of the following
implicit rules:
- The instance is the value of a JotBean property. For example
the object is returned by getAnotherBean(), or
AnotherBean is an automatic property (from a Request, Session,
or Application attribute), or the property was created and prepared with
putJotBeanProperty() as in this example:
putJotBeanProperty("AnotherBean", new MyJotPropertyBean());
An instance is constructed and prepared with a class named by a
JotBeanClass
initialization parameter (web.xml) as in this example:
<init-param>
<param-name>AnotherBean.JotBeanClass</param-name>
<param-value>com.examples.MyJotPropertyBean</param-value>
</init-param>
An instance is constructed and prepared of class AnotherBean
(with the same package name as the JotServletTemplateBean that loaded
the template).
Explicitly Named JotBeans:
The assignment operation can be used to name a new object or to create
an alias name for an existing object.
The Object token constructs a named object as a JotBean
Property in the scope of the template being rendered and any
nested templates. If the object is a JotBean it is prepared and
registered with the current JotServiceContext. In the following example,
Futz names an instance of class com.examples.MyJotPropertyBean.
JOT.Futz=(JOT.Object(com.examples.MyJotPropertyBean))
JOT.Futz.FooValue <!-- invoke getFooValue() on a MyJotPropertyBean object -->
The value of the argument to the JOT.Object token
is either a class name or there is an initialization parameter named
JotBeanName.JotBeanClass that names a class (see rule 2 above).
The argument value can also be a JOT Token that returns a dynamic
property value. The resolved class name can imply the package name
as in rule 3 above. More examples:
JOT.Futz=(JOT.Object(SomeInitializationParameter)) <!-- Construct Futz -->
JOT.Batz=(JOT.Object(JOT.SomeClassName)) <!-- Construct Batz -->
In the next example, BarAlias is the name given to a JotBean
property with the value returned by getAnotherBean() using the
dynamic argument returned by getAnotherBeanArg().
JOT.BarAlias=(JOT.AnotherBean(JOT.AnotherBeanArg))
JOT.BarAlias.BarProperty
One use of explicitly named JotBeans is for a JOT Template to reference
more than one object of the same type. This example displays the balances
of two bank accounts after a transfer:
JOT.FromAccount=(JOT.Account(JOT.FromAccountNumber))
JOT.ToAccount=(JOT.Account(JOT.ToAccountNumber))
<td>JOT.FromAccount.balance</td><td>JOT.ToAccount.balance</td>
|