23.12.2012 Views

ZK Developer's Guide

ZK Developer's Guide

ZK Developer's Guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

[ 143 ]<br />

Chapter 6<br />

Now we start creating a macro component, and use that component in the page. The<br />

interesting thing about the macro component itself is the usage of annotation-based<br />

data binding in the macro component.<br />

The first step is to create the macro ZUL file.<br />

<br />

<br />

<br />

<br />

<br />

<br />

import com.packtpub.zk.media.model.*;<br />

User user = self.getDynamicProperty(„user");<br />

<br />

<br />

To use data binding based on annotation, we have to declare the org.zkoss.<br />

zkplus.databind.AnnotateDataBinderInit initialization class. In our example,<br />

the component we created is of type org.zkoss.zk.ui.HtmlMacroComponent.<br />

To initialize the user for the databinding, we have to access the property with the<br />

getDynamicProperty method.<br />

In the ZUL page, we have to define the new component as:<br />

<br />

Now we can use this component as follows:<br />

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!