The usage of DataList taglib

This file contains a sample for DataList taglib. Here we will create a list of items with paging. For paging support we will use Pager taglib from Coldtags suite. How it looks like? In our case we will have a simple array that will be formatted as a list. And we will output just 2 rows per page:

<html>

<!-- Datalist taglib -->
<%@ taglib uri="taglib73.tld" prefix="list" %>

<!-- pager taglib -->
<%@ taglib uri="taglib139.tld" prefix="pg" %>

<!-- our data -->
<%
  String s[]={"apple","orange","pear","cherry"};
%>

<!-- describe paging. Size is 2 records -->
<pg:paging pageSize="2">

<!-- our list -->
<list:DataList source="<%=s%>">

<pg:item invokeAll="false">
  <list:itemTemplate><%=CURRENT_VALUE%></list:itemTemplate>
  <list:alternatingItemTemplate><em><%=CURRENT_VALUE%></em></list:alternatingItemTemplate>
  <list:separatorTemplate><br></list:separatorTemplate>

  <list:headerTemplate><center><b>DataList with paging</b></center></list:headerTemplate>
  <list:footerTemplate><center><b>End of page</b></center></list:footerTemplate>
</pg:item>
</list:DataList>

<!-- index -->
<pg:index title="Pages:">
  <pg:page><%=thisPage%></pg:page>
</pg:index>

</pg:paging>

</html>

and you will get some like this:

DataList with paging

pear
cherry
End of page
Pages: 1  2

 © Coldbeans   Comments?

See also Other tips from Coldbeans.