Rendering Infrastructure

Echo services are responsible for producing browser-understandable output. The Service interface contains two methods: getId() and service(). The getId() method is responsible for returning a unique alphanumeric string as an identifier (it may also contain underscores). The service() method, which takes a Connection as a parameter, is responsible for rendering the output to the provided Connection.

HTML Rendering

Many Echo services will render their output in the form of HTML code. ComponentPeer objects also render HTML code to generate browser-ready representations of server side Component objects. Echo provides an HTML-generation infrastructure in order to facilitate the needs of these objects. The fundamental difference between Services and ComponentPeers in this regard is that Services are responsible for rendering entire HTML documents, while ComponentPeers are only responsible for rendering a sepcific part of the document. Services will invoke the render() methods of ComponentPeers such that they provide their portion of the HTML document that the Service is rendering.

When an HTML document is rendered, it is first represented in memory as a hierarchy of nextapp.echoservlet.html.Element objects. This hierarchy is assembled via calls to Element's add() method. Attributes may be set on each element using the addAttribute() method. When the hierarchy has been fully assembled, the render() method is invoked on the root element. The render() method takes a as one of its parameters. All rendering is done by sending output to this PrintWriter. This architecture dispenses with the need to do heavy-duty string concatenation on rendering. It also provides for capabilities where a ComponentPeer may render code in multiple parts of an HTML document.

The nextapp.echoservlet.html Package

The nextapp.echoservlet.html package contains classes used in producing HTML documents. The Element class is contained in this package, and is the most fundamental building block when creating HTML documents. Elements are assembled into hierarchies which can be rendered into HTML documents. The html package also provides provides classes for creating "style" and "script" HTML elements, whose content has significant formatting restrictions.

The HtmlDocument Class

The HtmlDocument class is not a part of the html package; it is instead located in the core nextapp.echoservlet package. While the classes of the html package are used for generic HTML code generation, the HtmlDocument class is specifically intended to provide a backbone for creating HTML documents rendered by Echo Services. The HtmlDocument provides convenient methods of creating both content-containg and frameset HTML documents.

The ClientObjects Class

The ClientObjects class is used throughout Echo to generate URIs and JavaScript object names. It is a very simple class which contains only static methods, and as such, may not be instantiated. As an example of its use, a component peer might invoke the ClientObjects.getServiceUri() method when rendering an <img> element to determine the Echo URI of the service which will provide the image data.

Non-HTML Rendering

Many Echo services output data which is not in HTML. Echo services are capable of rendering other text formats and even binary data. These capabilities of Echo services will be used to render content such as JavaScript include files, images, multimedia content, and downloadable files.