Single Page


Page and Rendering

When a component is created (e.g., new Button()), it doesn't belong to any page. Furthermore, there is no view at the client if it doesn't belong to a page. It also means any update to it won't have any effect at the client.

On the other hand, once a component is attached to a page[2] (i.e., belongs to a page), any update to it will cse the view to change accordingly[3].

To maximize the performance, ZK does not update the client immediately. Rather, it accumulated all updates, optimize them, and then send a minimal collection of updates to the client at the final phase of the processing. The final phase is called the Rendering phase.

From application's viewpoint, there are four different phases[4]. However, from component's viewpoint, all other phases are the same, so you might say there are the rendering phase and the non-rendering phases.

The Non-Rendering Phases

In the phases other than Rendering, the application and ZK are allowed to access any methods of the component except the redraw method. It is the component's job to notify ZK if a component needs to be redrawn, or some states of the view have to change.

For example, you have a method that will cause the client to redraw the view, then you can call back the invalidate method.

public MyComp extends org.zkoss.zk.ui.AbstractComponent {
    public void setValue(String value) {    
        _value = value;        
        invalidate();        
    }    
}

The invocation of invalidate notifies that a component has to be redrawn in the Rendering phase. It doesn't redraw it immediately. Rather, ZK accumulates all these updates and processes them later in the Rendering phase.

The Rendering Phase

After all events are processed, ZK starts the rendering phase to redraw components that are invalidated in other phases. In other words, if a component's invalidate method was ever called, ZK will invoke the redraw method in the Rendering phase.

In the Rendering phase, only the redraw method is invoked and the invalidate method cannot be called – it also implies almost all methods other than redraw shall not be called.

Molds

The skeletal implementation of AbstractComponent introduces the concept of molds. A mold is a view of a component. For example, tabbox supports the default and accordion molds to provide different views for the same component.

<tabbox mold="default">
</tabbox>
<tabbox mold="accordion">
</tabbox>

To minimize the development effect, it is recommended to extend from AbstractComponent or one of its deriving classes. With AbstractComponent, you don't implement the redraw method directly. Rather, you can use your favorite Servlet technologies to generate the view, such as DSP[5] and JSP.



[2] To attach a component to a page, the application can call either setPage() with a page, or setParent() with a component belonging to a page.

[3] Whether to update the view is under control of the component when it belongs to a page After all, it is a component spec.

[4] Refer to the Developer's Guide for more information

[5] DSP (Dynamical Server Page) is a template technology developed by Potix. It is similar to JSP, but it can be embedded into a JAR file and no need to be compiled to Java codes first.