|
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
{
super.prepareJotBean();
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 a JotBean declared on an enclosing
JOT Template (see
Declaring JOT Beans) or the property value of a JotBean
(see Implementing JOT Bean Properties),
as in the following example (the ContentSource and JotServletTemplateBean
objects could be static objects in this case):
public Renderable getRowComponent()
throws JotException
{
// JOT Template is Stringified HTML fragment
ContentSource cs = new StringContentSource(
"<td>JOT.ProductName</td><td>JOT.ProductPrice</td>");
return (Renderable)serviceContext.prepareJotBean(
new JotServletTemplateBean(cs));
}
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>
|