XBean taglib ver. 1.3


    Custom JSP taglib that lets you iterate over some set (collection) of beans and prepare the output in XML format. And the final idea is to use XSLT stuff for publishing your data. This taglib is similar to the XSQL taglib but instead of the direct connection to database you can use a collection of objects.

For example, lists the collection of beans:
 


<%@ taglib uri="taglib.tld" prefix="get" %>

<%
  java.util.List v = new java.util.ArrayList();
  Person p = new Person();
  p.setName("John");
  p.setAge(25);
  v.add (p);
  ...
%>
 
<get:XBean source="<%=v%>">;
  <get:getProperty>name</get:getProperty>
  <get:getProperty>age</get:getProperty>
</get:XBean>

Here source parameter describes a collection (array, enumeration etc.) of bean. Instead of that we can provide a name for the attribute (in the page, request, session or applcation scope). E.g.:
 


<get:XBean name="persons">;
  <get:getProperty>name</get:getProperty>
  <get:getProperty>age</get:getProperty>
</get:XBean>

Tag iterates over the given collection and outputs (inserts into page) its elements in XML format. Names for the properties describe what methods will be called for getting values. E.g. property name age corresponds to the call getName() etc. By default tag will use all the properties.

So this tag outputs XML text and now you may use for example XSL taglib for an appropriate transformation:
 


<%@ taglib uri="taglib.tld" prefix="get" %>
<%@ taglib uri="taglib1.tld" prefix="xslt" %>

<xslt:applyXSL xslData="sheet.xsl">

 <xslt:setXML>;
  <get:XBean name="persons">;
    <get:getProperty>name</get:getProperty>
    <get:getProperty>age</get:getProperty>
  </get:XBean>
 </xslt:setXML>

</xslt:applyXSL>

XML data will be presented as a collection of rows where the each row is a set of properties:
 


<rows>
  <row>
   <property_name1>property_value1</property_name1>
   <property_name2>property_value2</property_name2>
   ...
  </row>
  ...
  ...
</rows>

so for the above mentioned example (selected properties are name and age) it will be some like this:
 


<rows>
  <row>
   <name>John</name>
   <age>25</age>
  </row>
  <row>
   <name>David</name>
   <age>33</age>
  </row>
...
</rows>

and you may use stylesheet like this for presenting data in HTML table for example:
 


<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="rows">
<table border="1" width="100%">
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<xsl:for-each select="row">
<tr>
<td><xsl:value-of select="Name"/></td>
<td><xsl:value-of select="Age"/></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>

Any null value will be presented as an empty string.

Tags are:

XBean

Body tag iterates over the given collection of beans and presents them in XML format. Parameters are:

1) source Optional parameter. Describes a source collection (array, enumeration, iterator etc.)
2) name Optional parameter. Describes a name for the attribute (in page, request, session or application scope) that will keep your collection.
3) xsl Optional parameter. Describes an URL for XSL stylesheet (if you will use client side XSL formatting)

getProperty

Body tag defines a name for the property. Parameters are:

1) cond Optional parameter. Describes a boolean value tag's behavior depends on. Default value is true (get property)

for downloading:

Library: xbeantag.jar    Description: taglib.tld

 © Coldbeans       Comments?

 See also Coldtags suite - the largest collection of custom JSP tags.

Also in Coldtags: