Programmers Guide > JOT Web Components

JOT Web Components

A JOT Web Component is a Renderable object that renders dynamic content (see JotContentBean). The generic type for a JOT Web Component is a JotServletTemplateBean that renders dynamic content with a JOT Template. Composite views are composed with JOT Web Components that render nested JOT Templates into enclosing JOT Templates to any nesting depth.

The properties of enclosing JotServletTemplateBeans are available to JOT Tokens in nested JOT Templates. For instance, a getStyle() method in an outer JotServletTemplateBean would apply the same HTML style attribute to any nested components with the JOT.Style token, as in this example:

    <table style="JOT.Style">

In the following example the CustomerInfo token renders dynamic content with a customer information JotServletTemplateBean:

    <p>
    <!-- Render view of CustomerInfo component -->
    JOT.CustomerInfo
    <p>

The JOT Template for the CustomerInfo component could be this simple HTML fragment:

    <table>
        <tr><td>Customer Name</td><td>JOT.Name</td></tr>
        <tr><td>Home Phone</td><td>JOT.HomePhome</td></tr>
    </table>

The CustomerInfo JOT Web Component for the example is this JotServletTemplateBean:

    public class CustomerInfo
        extends JotServletTemplateBean
    {
        private Customer customer;

        public void prepareJotBean()
            throws JotException
        {
            String cid = (String)getJotBeanProperty("customerID"); // Form field
            customer = entityManager.find(Customer.class, cid); // persistent object
        }
        public String getName() { return customer.fullName(); }

        public String getHomePhone() { return customer.homeTelephoneNumber(); }
    }

Using JOT Web Components:

A JOT Web Component can be declared by an enclosing JOT Template (see Declaring JOT Beans). Or it can be a Renderable property of a JotBean (see Implementing JOT Bean Properties), such as this ProductRow property for use in a loop:

    public void prepareJotBean()
        throws JotException
    {
        // JOT Template is Stringified HTML fragment
        ContentSource cs = new StringContentSource(
            "<td>JOT.ProductName</td><td>JOT.ProductPrice</td>");
        putJotBeanProperty("ProductRow", new JotServletTemplateBean(cs));
    }

Using the CustomerInfo class above this method returns a JOT Web Component that is rendered with the token JOT.CustomerInfo:

    public Renderable getCustomerInfo()
    {
        return (Renderable)configureJotBean(new CustomerInfo());
    }

The JOT.Views.Component token renders a JOT Web Component with the JOT Views rendering engine, as in these examples:

    <hr>
    <!-- Render the SnooperContent component -->
    JOT.Views.Component(com.jotobjects.tools.servlet.JotSnooperContentBean)
    <p>
    <!-- Render the CustomerInfo component with a specific template -->
    JOT.Views.Component(com.myapp.CustomerInfo, /webpages/CustomerInfoDetail.html)
    <hr>

© 2008 JOT Object Technologies