In this chapter we will create a Mail POJO and build a UI for it.
Now create a NUI template to show the properties of mail object.
First, create a new file named Mail.nui.xml in /nuitemplates/samples directory. Then type following code:
<?xml version = "1.0"?>
<showmail>
<template ignoreText="false">
<table>
<n:loop for="{'sender' , 'receiver' , 'createDate' , 'subject' , 'content'}" id="'propertyName'">
<tr>
<td><p:title bean="mail" property="propertyName"/>: </td>
<td><p:value bean="mail" property="propertyName"/></td>
</tr>
</n:loop>
</table>
</template>
</showmail>
This template iterate each property of Mail(using n:loop and a ognl list),
and output it's title and value.
<%@ taglib prefix="nui" uri="/nui" %>Then prepare a context map:
<%
Mail mail = new Mail () ;
// set properties' value
mail.setSender ("webwork@mail.nui.org") ;
mail.setReceiver ("struts@mail.nui.org") ;
mail.setCreateDate (new Date ()) ;
mail.setSubject ("About NUI, a property oriented template engine.") ;
mail.setContent ("message body.") ;
HashMap context = new HashMap () ;
context.put ("mail" , mail) ;
%>
<nui:template name="samples-showmail" context="<%= context %>"/>
| sender: | webwork@mail.nui.org |
| receiver: | struts@mail.nui.org |
| createDate: | 2006/04/14 |
| subject: | About NUI, a property oriented template engine. |
| content: | message body. |