<?xml version="1.0"?> | |
<!-- | |
Copyright 2002,2004 The Apache Software Foundation. | |
Licensed under the Apache License, Version 2.0 (the "License"); | |
you may not use this file except in compliance with the License. | |
You may obtain a copy of the License at | |
http://www.apache.org/licenses/LICENSE-2.0 | |
Unless required by applicable law or agreed to in writing, software | |
distributed under the License is distributed on an "AS IS" BASIS, | |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
See the License for the specific language governing permissions and | |
limitations under the License. | |
--> | |
<!-- creates a Bean --> | |
<j:jelly | |
xmlns:j="jelly:core" | |
xmlns:define="jelly:define" | |
xmlns:log="jelly:log" | |
xmlns:my="myDummyTagLib"> | |
<testcase> | |
<log:info>Lets define a new tag library</log:info> | |
<define:taglib uri="myDummyTagLib"> | |
<!-- | |
|| map the given bean to a jelly tag | |
|| we'll specify some required attributes and some default values | |
--> | |
<define:bean name="customer" className="org.apache.commons.jelly.core.Customer"> | |
<define:attribute name="name" required="true"/> | |
<define:attribute name="location" defaultValue="UK"/> | |
</define:bean> | |
</define:taglib> | |
<log:info>Now lets invoke the new Jelly bean tag</log:info> | |
<my:customer var="c1" name="James"/> | |
<log:info>Created a customer with name ${c1.name} and location ${c1.location}</log:info> | |
<my:customer var="c2" name="Bob" location="US"/> | |
<log:info>Created a customer with name ${c2.name} and location ${c2.location}</log:info> | |
<j:catch var="exception"> | |
<my:customer location="UK"/> | |
</j:catch> | |
<log:info>Caught exception ${exception} with reason: ${exception.reason}</log:info> | |
<j:if test="${exception == null}"> | |
<log:error>Failed! I should have an exception since I didn't specify a 'name' attribute</log:error> | |
</j:if> | |
</testcase> | |
</j:jelly> | |