| |||||||||||||||
| |||||||||||||||
Writing Templates - Switch Tags Switch tags, a new BeanMaker feature, let you define some conditional functionality in your templates. A switch definition defines a switch domain, i.e. a collection of key-value pairs. Each switch domain can have an optional default value which will be used in place of an unknown key. Switches are mostly usefull when you want to generate different code based on property types. Switch Domain definition
Switch tag - (Using the domain definitions) An switch tag is the means of retrieving the values defined in a switch domain definition as described above.
It's syntax is shown below: $switchdef('NUMBERS')$ one=1 two=2 three=3 $default$=UNKNOWN_NUMBER $switchdef$ $switch('NUMBERS','one')$ $switch('NUMBERS','two')$ $switch('NUMBERS','fourteen')$ ...produces this output: 1 2 UNKNOWN_NUMBER Examples 2. Real-world Situation int an_integer String a_string boolean a_boolean CustomObject a_customobject ...and using the following BeanMaker template... $switchdef('OBJECT')$ int = new Integer($property$) boolean = new Boolean($property$) long = new Long($property$) $default$ = $property$ $switchdef$ List list = new ArrayList(); $doproperty$ list.add($switch('OBJECT','$propertytype$')$); $loop$ ...we can produce this output: List list = new ArrayList(); list.add(new Integer(an_integer)); list.add(a_string); list.add(new Boolean(a_boolean)); list.add(a_customobject); |
|||||||||||||||
Copyright ©2000-2006 CyLog Software www.cylog.org | |||||||||||||||