Ch09

From Documentation

Miscellenous

Any fool can write code that a computer can understand. Good programmers write code that humans can understand. -- Martin Fowler

Thinking in Style

In ZK, we can assign zclass and sclass to specify component's CSS class, or set style attribute directly. There are some places we can declare CSS class:

  • Write in ZUML processing instruction <?style ?> block.
  • Write in Style component.
  • In JSP + ZK architecture, write in JSP(HTML).

In other case, <?style ?> is a good choice, but we can't use it in JSP + ZK architecture. Because ZUL include by <jsp:include> or ZK Include will not generate complete HTML structure. The ZUL we import by jQuery set the redrawCtrl, will not generate too.

No matter you write CSS in JSP or ZUL, there is no difference in usage. Take ToDoZK for example, you could declare all CSS class in index.jsp or split them into ZUL files. The second way can provide some advantage:

  • Easy to maintain, manage CSS class.
  • Can replace the Style content or refer file programmable.

We must notice that Style is also a ZK component, so excessive use will be a server overhead. The ideal solution is write main content in JSP and Style is used to assist.

Addition Advantage of Use Native Namespace

We talk about many performance advantages in before chapter. There is another addition advantage: decrease Label component usage. Try this ZUL code:

<zk>
    <div>You got <label value='3' /> messages.</div>
</zk>

In this code, the Div is ZK component. When watch DOM structure, we can find ZK will automatically transform You got, messages. into Label. If we change to use native namespace div:

<zk xmlns:n="native">
    <n:div>You got <label value='3' /> messages.</n:div>
</zk>

ZK will not do any transform. In this case, we decrease three ZK components: Div and two Label. When we write some static text message, we must notice this point.