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:

  1. 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 parameter or a Request, Session, or Application attribute), or the property was created and prepared with addJotBeanProperty() as in this example:
        addJotBeanProperty("AnotherBean", new MyJotPropertyBean());
    
  2. 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>
    
  3. 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 JotBean assignment 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 JotServletServiceContext. In the following example, Futz names an instance of class com.examples.MyJotPropertyBean.

    JOT.JotBean=(Futz, com.examples.MyJotPropertyBean)
    JOT.Futz.FooValue <!-- invoke getFooValue() on a MyJotPropertyBean object --> 

The value of the second argument to the JotBean assignment token is either a class name or there is an initialization parameter named JotBeanName.JotBeanClass that names a class (see rule 2 above). The second argument 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.JotBean=(Futz, SomeInitializationParameter) <!-- Construct Futz --> 
    JOT.JotBean=(Batz, 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>
© 2007 JOT Object Technologies